How to run node.js + supervisor on boot?

After installing and configuring node.js on my development virtual machine running under Ubuntu 11.10, I would like the supervisor to start automatically when loading, invoking and rebooting node.js if necessary.

Below snippet works well when starting my default user in terminal, but how can I get it to work on boot?

cd /var/ && supervisor -w www www/myapp/app.js 

thanks

+4
source share
2 answers

Upstart plus monit works well enough to get everything that works at boot time and to support the node process. Alternatively, you can use npm to install them. There is a question here .

I'm not sure why the supervisor should start at boot (logically, the only time you need it while you are uploading new files), but I would suggest that it can be started at boot by simply creating a new upstart configuration (using the same phrase for foundation):

 #!upstart description "myapp supervisor" author "you" start on startup stop on shutdown script echo $$ > /var/run/supervise_yourprogram.pid // does it need root access? if so... // exec sudo -u username supervisor --restart-on-error myapp.js supervisor --restart-on-error myapp.js end script pre-stop script rm /var/run/supervise_yourprogram.pid end script 

I'm not sure you will need monit for this case, since the supervisor has its own -restart-on-error.

And here is a completely different approach , using a wrapper that you will call instead of your application. js. It looks pretty interesting.

+8
source

This Ubuntu page has instructions for writing a service for Ubuntu.

0
source

Source: https://habr.com/ru/post/1391274/


All Articles