Upstart / init script does not work

I am trying to create a / script service to automatically start and manage my nodejs server, but it does not work at all.

First of all, I used this source as the main link http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/

After testing, I minimized the contents of the actual file to avoid any error resulting in (minimum minimum, but it does not work)

description "server" author "blah" start on started mountall stop on shutdown respawn respawn limit 99 5 script export HOME="/var/www" exec nodejs /var/www/server/server.js >> /var/log/node.log 2>&1 end script 

The file is saved in /etc/init/server.conf

when trying to run a script (as root user or regular user), I get:

 root@iof304 :/etc/init# start server start: Job failed to start 

Then I tried to check my syntax for init-checkconf , the result was:

 $ init-checkconf /etc/init/server.conf File /etc/init/server.conf: syntax ok 

I tried other things like initctl reload-configuration with no result.

What can I do? How can I make this work? It can't be that hard, right?

+7
init upstart
source share
2 answers

Here's what our typical startup script looks like. As you can see, we run our node processes as user nodejs. We also use a pre-launch script to ensure that all log file directories and .tmp directories are created with the correct permissions.

 #!upstart description "grabagadget node.js server" author "Jeffrey Van Alstine" start on started mysql stop on shutdown respawn script export HOME="/home/nodejs" exec start-stop-daemon --start --chuid nodejs --make-pidfile --pidfile /var/run/nodejs/grabagadget.pid --startas /usr/bin/node -- /var/nodejs/grabagadget/app.js --environment production >> /var/log/nodejs/grabagadget.log 2>&1 end script pre-start script mkdir -p /var/log/nodejs chown nodejs:root /var/log/nodejs mkdir -p /var/run/nodejs mkdir -p /var/nodejs/grabagadget/.tmp # Git likes to reset permissions on this file, but it really needs to be writable on server start chown nodejs:root /var/nodejs/grabagadget/views/layout.ejs chown -R nodejs:root /var/nodejs/grabagadget/.tmp # Date format same as (new Date()).toISOString() for consistency sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/nodejs/grabagadget.log end script pre-stop script rm /var/run/nodejs/grabagadget.pid sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/nodejs/grabgadget.log end script 
0
source share

Starting with Ubuntu 15, upstart is no longer used, see systemd.

-3
source share

All Articles