2

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

[Unit]
Description=TI SensorTag Communicator
After=network.target

[Service]
ExecStart=/usr/bin/node /home/pi/sensortag-comm/sensortag.js
User=root

[Install]
WantedBy=multi-user.target

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.

Update

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 After=MySQL.service and it worked perfectly!

ivywit
  • 473
  • 2
  • 8
  • 17

1 Answers1

3

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 my-unit.name.service.

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.

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • Sorry I wasn't clearer, the service is enabled and it is attempting to start on boot. I'm unable to access the machine till Monday, and will update the question with the results of `journalctl -u sensortag.service` then. Just to note, mysql 5.5 uses systemv instead of systemd (the machine is a raspberry pi, and I'm not inclined to setup backports) so trying `After=mysql.service` didn't seem to solve the issue previously, but maybe the issue is elsewhere. Thanks again for the help so far. – ivywit Jul 08 '16 at 23:28