Node.js script failed to start using systemctl

I need to run my node.js script automatically from my remote machine using systemctl.

I already created a .service file and put it in /etc/systemd/system/ . Here is the .service file:

 [Unit] Description=laporan [Service] ExecStart=/var/www/laporan/nodeserver/server.js Restart=always User=nobody Group=root Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production WorkingDirectory=/var/www/laporan/nodeserver [Install] WantedBy=multi-user.target 

But every time I try to start the service, it returns an error as follows (output from systemctl status laporan ):

 ● laporan.service - laporan Loaded: loaded (/etc/systemd/system/laporan.service; enabled) Active: failed (Result: start-limit) since Mon 2016-09-12 09:15:06 WITA; 11min ago Process: 121690 ExecStart=/var/www/laporan/nodeserver/server.js (code=exited, status=203/EXEC) Main PID: 121690 (code=exited, status=203/EXEC) Sep 12 09:15:05 kominfomdc systemd[1]: Unit laporan.service entered failed state. Sep 12 09:15:06 kominfomdc systemd[1]: laporan.service start request repeated too quickly, refusing to start. Sep 12 09:15:06 kominfomdc systemd[1]: Failed to start laporan. Sep 12 09:15:06 kominfomdc systemd[1]: Unit laporan.service entered failed state. 

What exactly is this error about? Did I miss something?

+7
source share
2 answers

I do not think you are starting a node application. You simply specify the JavaScript file here:

 ExecStart=/var/www/laporan/nodeserver/server.js 

You also need to specify the node executable, something like the following, if node is on the way.

 ExecStart= node /var/www/laporan/nodeserver/server.js 

However, as you noticed, you must enter the full path to the executable:

 ExecStart=/usr/local/bin/node /var/www/laporan/nodeserver/server.js 
+10
source

to give clarity about the error, you specified the wrong path to the executable node . To get the right way, you can use

 $ which node // /usr/bin/node 

in my case it is different, I get / usr / bin / node as the path, so in ExecStart you copy the path to the node from the command line

 ExecStart=/usr/bin/node /var/www/laporan/nodeserver/server.js 
0
source

All Articles