Basically, I have an image with a flask server.
When I create a new droplet from it, the flask server doesn’t run. It needs to be manually run.
How can I make the bash script to run python server.py as soon as the droplet is ready instead of me having to manually ssh in or run fabric?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
@asb : stop on runlevel [!12345] --> is that mean any runlevel except {1, 2, 3, 4, 5}
The best way to have something run on boot is use an init script. Assuming you are using Ubuntu, you can use Upstart to write it in a simple declarative format. A quick example might look like:
<br>
<br><pre>
<br>description “Daemon for flask project”
<br>
<br>start on (local-filesystems and net-device-up IFACE=eth0)
<br>stop on runlevel [!12345]
<br>
<br># If the process quits unexpectedly trigger a respawn
<br>respawn
<br>
<br>setuid myuser
<br>setgid mygroup
<br>chdir /path/to/dir
<br>
<br>exec uwsgi --master
<br> --processes 4
<br> --die-on-term
<br> --socket /tmp/uwsgi.sock
<br></pre>
<br>
<br>Save the file to “/etc/init/myservice.conf” It will now launch on boot once the filesystem is mounted and the network is active. You can also manage it like other services, using:
<br>
<br><pre>
<br>service myservice start
<br>service myservice restart
<br>service myservice stop
<br></pre>
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.