Search code examples
linuxnode.jsubuntughost-blogsystemd

Run a node app in background in an Ubuntu VM using Systemd


Trying to set a demon process using systemd in Ubuntu 15.04 VM provide by Google Compute Engine, to run an ghost blog platform on background.

So far my service script is the following:

[Service]
ExecStart=/usr/bin/node /home/blog/index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
RestartSec=120s
SyslogIdentifier=blog-service
User=user
Group=user
Environment=NODE_ENV=production PORT=5000
[Install]
WantedBy=multi-user.target

After start the service and check the status I get:

blog.service
   Loaded: loaded (/etc/systemd/system/blog.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) since Fri 2015-08-21 01:04:01 UTC; 42s ago
  Process: 3455 ExecStart=/usr/bin/node /home/blog/index.js (code=exited, status=0/SUCCESS)
 Main PID: 3455 (code=exited, status=0/SUCCESS)

I don't understand why I get (code=exited, status=0/SUCCESS), If I run manually node index.js everything goes ok. How can I get my project running in background properly?


Solution

  • The solution was to add the parameter Type=forking on the service script. Looks like is not possible to run the node web server without say to the system to create a child process.