0

I have a node.js server that I'd like to make a service so it wouldn't shut down after closing SSH-session.

I followed instructions in here, but it didn't go quite as planned because instead of the service starting up it gave me the following error:

   Loaded: loaded (/etc/systemd/system/jasentiedot.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since ti 2018-01-23 10:38:08 EET; 59s ago
  Process: 10525 ExecStart=/home/nodeuser/jasentiedot/server.js (code=exited, status=203/EXEC)
 Main PID: 10525 (code=exited, status=203/EXEC)

Here is the service file at /etc/systemd/system/jasentiedot.service

[Unit]
Description=Servicename

[Service]
ExecStart=/home/nodeuser/jasentiedot/server.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/nodeuser/jasentiedot

[Install]
WantedBy=multi-user.target

The script runs fine when running it manually, so there shouldn't be anything wrong with that.

Is there any better methods to make node.js script persistent in case this doesn't work out? I tried forever, but that didn't work.

nyoatype
  • 41
  • 2
  • 11

1 Answers1

0

You have to specify node xyz.js in Execstart. See this post: Node.js script failed to start with systemctl

nevf
  • 4,596
  • 6
  • 31
  • 32
  • I got one step forward thanks to your answer, but after adding the full path for node it gives me the following error "Failed to start jasentiedot.service: Unit is not loaded properly: Invalid argument." – nyoatype Jan 29 '18 at 08:45
  • It's been a couple of months so you've probably figured it out by now, but you get "Invalid argument" error if you don't pass a fully qualified path to node. – Doughnuts Apr 16 '18 at 03:31