phelpsiv phelpsiv - 1 year ago 58
Node.js Question

Systemd service failing on startup

I'm trying to get a nodejs server to run on startup, so I created the following systemd unit file:

Description=TI SensorTag Communicator

ExecStart=/usr/bin/node /home/pi/sensortag-comm/sensortag.js


I'm not sure what I'm doing wrong here. It seems to fail before the nodejs script even starts, as no logging occurs. My script is dependent on mysql 5.5 (I think this is where I'm running into an issue). Any insight, or even a different solution would be appreciated.

Also, it runs fine once I'm logged into the system.


The service is enabled, and is logging through journalctl. I'll update with the results on 7/11/16.

Not sure why it didn't work the first time, but upon checking journalctl the issue was 100% that MySQL hadn't started. I once again changed it to
and it worked perfectly!

Answer Source

If there is no mention of the service at all in the output of journalctl that could indicate that the service was not enabled to start at boot.

Make you run systemctl enable my-unit-name before your next boot test.

Also, since you depend on MySQL being up and running, you should declare that with something like: After=mysql.service. The exact service name may depend on your Linux distribution, which you didn't state.

Adding User=root adds nothing, as system units would be run by root by default anyway.

When you said "it fails", you didn't specify whether it was failing at boot time, or with a test run by systemctl start my-unit-name.

After attempting to start a service, there should be logging if you run journalctl -u

You might also consider adding StandardOutput=journal to your unit file to make sure you capture output from the service you are running as well.