meetamit meetamit - 8 months ago 33
Linux Question

How to run a shell script at startup

On an amazon linux instance, I have two scripts called

which start and stop forever (which in turn run 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
is run whenever the system boots up. I know that I need to add a file inside
and I know how to symlink it to the proper directory within
, but can't figure out what actually needs to go inside the file that I place in
. I'm thinking it should be just one line, like,
, but that hasn't been working for me.


In the file you put in /etc/init.d/ you have to set it executable with:

chmod +x /etc/init.d/start_my_app

Thanks to @meetamit, if this does not run you have to create a symlink to /etc/rc.d/

ln -s /etc/init.d/start_my_app /etc/rc.d/

Please note that on latest Debian, this will not work as your script have to be LSB compliant (provide, at least, the following actions: start, stop, restart, force-reload, and status):

As a note, you should put the absolute path of your script instead of a relative one, it may solves unexpected issues:


And don't forget to add on top of that file: