Question

I have a project folder with the app's contents, and to start it manually, I run nohup npm start & and then disown the proc.

I would like to figure out a way to make this a service mynodeapp {start|stop|restart|etc} command instead.

I am also aware that Ubuntu (and Debian in general) is deprecating the SysV init scripts and recommend upstart configs instead in /etc/init/*.conf.

How would I go about writing an upstart config with start-stop-daemon?

Thanks.

Était-ce utile?

La solution

I'll answer this myself with the solution that worked best for me.

After digging around a bit, I just decided to undertake the burden of reading the upstart docs, and came up with the following in /etc/init/myapp.conf:

# Node.js app config

description     "Node.js app upstart config"
author          "George K."

# Starting conditions
start on (local-filesystems and net-device-up IFACE=eth0)

# Stopping conditions
stop on shutdown

# If parent or any child exits, respawn
respawn

# The deed
script
    export HOME="/root"
    export WORKER_COUNT=4

    exec /usr/local/bin/node /path/to/app >> /var/log/app.log 2>&1
end script

Autres conseils

path: /etc/init/myapp.conf make file executable with this command

chmod +x myapp.conf

myapp.conf source:

description "App Server"
author "Author"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

respawn

# if your app use port
env PORT=8080

chdir /home/domain/public_html/chat/
exec node index.js
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top