How do I specify to install the Daemon
Closed this issue · 2 comments
marcofranssen commented
Hi,
Using links I created a symlink in the init.d directory.
What is the best way to do the install of this daemon
update-rc.d install mypackage defaults
I'm asking this since it should also work when I release an update for this package.
Deleted user commented
Since support was recently added to specify control files (see: #3), you could add the update-rc.d command into your postinst, and then in your postrm file put:
update-rc.d -f mypackage remove
to remove the daemon.
Another option would be to use upstart which lets you specify at what runlevels to run in the init script itself, i.e.:
# /etc/init/myapp.conf
description "My NodeJS App"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 5 60 # try 5 times within 60 seconds, or giveup
script
echo $$ > /var/run/myapp.pid
cd /location/of/app;
exec sudo -u username NODE_ENV=production /usr/bin/node server.js >> /var/log/myapp/myapp.log 2>&1
end script
pre-start script
mkdir -p /var/log/myapp
echo "\n[`date +%Y-%m-%dT%T.%3NZ`] (sys) Starting\n" >> /var/log/myapp/myapp.log
end script
pre-stop script
rm /var/run/myapp.pid
echo "\n[`date +%Y-%m-%dT%T.%3NZ`] (sys) Stopping\n" >> /var/log/myapp/myapp.log
end script
This is the strategy i'm using, but i'll probably switch to init since upstart is being deprecated. I also have my postinst file create a user and group for my package and install NPM dependencies.
marcofranssen commented
That did the trick