B L
B L

Reputation: 197

Run Python script on startup/reboot of AWS instance

I'm running Flask on an AWS instance. My goal is to be able to have Flask running on its own, without me having to ssh into it and run

python app.py

Is there a way to have this command run every time the AWS instance itself reboots?

Upvotes: 1

Views: 2421

Answers (2)

mellifluous
mellifluous

Reputation: 2975

Try this:

(crontab -l 2>/dev/null; echo '@reboot python /path/to/app.py') | crontab -

Upvotes: 2

Rajat Chandak
Rajat Chandak

Reputation: 131

Yes there is a way to start the python script on reboot.

On linux you will find /etc/init.d directory. You will need to write your own init.d script and put it inside /etc/init.d directory,which will indeed start your python script. Ahh ! wait its not goning to be magic. Dont worry, there is fixed format of init.d script. Script contains some basic tasks like start(),stop(),reload() etc. Just add the code that you want to run on start in start() block.

Some reference link : https://bash.cyberciti.biz/guide//etc/init.d

Upvotes: 7

Related Questions