Making app a deamon - mfedorov/nebulent-rac-ui GitHub Wiki
Demonetization of the app is done via Upstart (which is by default is used in ubuntu for those purposes)
- create upstart script in /etc/init with the following content
description "Rac client starting Node with Upstart and Forever"
# Start up when the system hits any normal runlevel, and
# shuts down when the system goes to shutdown or reboot.
start on filesystem or runlevel [5]
stop on runlevel [06]
# IMPORTANT: You will want to use this with Forever. It
# tells Upstart that forever is going to fork after it
# starts.
expect fork
# This monitors Forever, which seems gratuitous.
# TIP: Comment these out while debugging your script.
respawn
respawn limit 5 30
# Send error messages to the console. Useful for debugging.
console output
# exampleuser is a very low-privileged user. We run as
# this user instead of as root (the default user).
setuid deploy
# The user's home directory
env HOME=/home/deploy
# Now we run Forever, telling it to write its logs to
# /tmp, and to run the script /opt/example/server.js
script
cd $HOME
# this will work only if you've mounted the fs read write
echo "Debug Message" >> /tmp/upstart
exec forever start -c /usr/local/bin/coffee /var/www/rac-client/nebulent-rac-ui/app.coffee
end script
- add a rule in /etc/dbus-1/system.d/Upstart.conf for deploy users to be able to manipulate job (start/stop/restart) without sudo privileges:
<policy group="deploy">
<allow send_destination="com.ubuntu.Upstart"
send_interface="org.freedesktop.DBus.Properties" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Instance" />
</policy>