Systemd can be problematic sometimes. It's easier to write SysV or Upstart initialization scripts every time you can. I will explain some of these questions: [1] , [2] .
Now, what you can do is write the script itself, which:
- change the working directory to your application
- run the run command
For example:
(or npm server.js or whatever your command is instead of npm start )
It may also be useful to set the correct PATH if you need it:
#!/bin/sh PATH="/opt/node/bin:$PATH" export PATH cd /your/application/path npm start
(where /opt/node/bin is your node and npm )
If you save a script like /opt/nodeserver/server.sh , for example, then you should be able to use:
ExecStart=/bin/sh /opt/nodeserver/server.sh
on your systemd script (if there are no more gotchas in systemd that could cause problems here).
rsp Nov 29 '16 at 10:35 2016-11-29 10:35
source share