On an amazon linux instance, I have two scripts called start_my_app
and stop_my_app
which start and stop forever (which in turn runs my node.js app). I use these scripts to manually start and stop my node app. So far so good.
My problem: I also want to set it up such that start_my_app
is run whenever the system boots up. I know that I need to add a file inside init.d
and I know how to symlink it to the proper directory within rc.d
, but can't figure out what actually needs to go inside the file that I place in init.d
. I'm thinking it should be just one line, like, start_my_app
, but that hasn't been working for me.
$ update-rc.d myScript.sh defaults NN
where NN is the order in which it should be executed. 99 for example will mean it would be run after 98 and before 100.Another option is to have an @reboot command in your crontab.
Not every version of cron supports this, but if your instance is based on the Amazon Linux AMI then it will work.
For Debian 9 see https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-up. It is helped me. Short version for Debian 9: add commands (as root) to /etc/rc.local
Probably, /path_to_file/filename.sh should be executable (I think so).