Winson Liao Winson Liao - 21 days ago 8
Linux Question

systemd cannot run service after running commands

I tried to run systemd using the commands

systemctl enable photogrid.service
&
systemctl start photogrid.service
in ubuntu 16

The nodejs app itself can run as expected. The service is to ensure that application will auto-start when application crash or server reboot.

The service apparently did not start. So I key in
systemctl status photogrid.service
to see what happened, the below is what I got from the terminal.

‚óŹ photogrid.service - Photogrid
Loaded: loaded (/lib/systemd/system/photogrid.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2016-11-09 04:35:36 UTC; 7s ago
Process: 27523 ExecStart=/usr/local/bin/node /home/ubuntu/photogrid/app.js (code=exited, status=203/EXEC)
Main PID: 27523 (code=exited, status=203/EXEC)

Nov 09 04:35:36 ip-172-31-34-151 systemd[1]: photogrid.service: Main process exited, code=exited, status=203/EXEC
Nov 09 04:35:36 ip-172-31-34-151 systemd[1]: photogrid.service: Unit entered failed state.
Nov 09 04:35:36 ip-172-31-34-151 systemd[1]: photogrid.service: Failed with result 'exit-code'.


This the script that I wrote for the service under the path /lib/systemd/system/photogrid.service

[Unit]
Description=Photogrid

[Service]
Type=simple
Restart=always
RestartSec=10
Environment=NODE_ENV=production
ExecStart=/usr/local/bin/node /home/ubuntu/photogrid/app.js

[Install]
WantedBy=multi-user.target

Answer

Basically under ExecStart make sure you point to the correct nodejs executable. For my case it was in a different folder and not /usr/local/bin/node, to check where is your node executable. (Assuming you confirm you have downloaded and install it correctly in linux) use command which node to give you path direction.

Comments