Getting a service to start up after reboot is easy with Linux and
In the example below, we have a Unix user called
testuser. The requirement was that
testuser wanted to run a nodejs script uisng
We’ll be editing
crons to include a startup command.
Start editing by replacing the
testuser with your desired runtime user for the Node process. If you choose a different user other than yourself, you will have to run this with sudo.
$ crontab -u testuser -e
If you have never done this before, it will ask you which editor you wish to edit with. I like vim, but will recommend nano for ease of use.
When working with
CRONs, you should always use full paths when executing binaries. Use
which forever to get the full path to
forever. You will notice we have also included the full path to
Once in the editor add the following line:
@reboot /usr/local/bin/forever start -c /usr/local/bin/node /your/path/to/your/app.js
Save the file. You should get some feedback that the cron has been installed.
For further confirmation of the installation of the
cron, execute the following (again replacing “testuser” with your target username) to list the currently installed crons:
$ crontab -u testuser -l