0

I am simply trying to start my node application as a service I am pointing to the server.js file and have that set as executable.

I would like to have this node app restarting on server reboot and be able to generally just use it as a service.

/etc/systemd/system/parsoid.service

[Unit]
Description=MediaWiki Parsoid Server

[Service]
ExecStart=/var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
Restart=always
User=nobody
# Note Debian/Ubuntu uses 'nogroup', RHEL/Fedora uses 'nobody'
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/gwart/mediawiki/extensions/VisualEditor/parsoid

[Install]
WantedBy=multi-user.target 

However when checking if the service is running it does not start. The node app starts without problems by doing node /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js.

Errors

root@server:/etc/systemd/system# systemctl status parsoid.service 
● parsoid.service - MediaWiki Parsoid Server
   Loaded: loaded (/etc/systemd/system/parsoid.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Sat 2018-12-15 20:35:57 GMT; 1s ago
  Process: 8565 ExecStart=/var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js (code=exited, status=127)
 Main PID: 8565 (code=exited, status=127)

Dec 15 20:35:56 server.live-servers.net systemd[1]: parsoid.service: Unit entered failed state.
Dec 15 20:35:56 server.live-servers.net systemd[1]: parsoid.service: Failed with result 'exit-code'.
Dec 15 20:35:57 server.live-servers.net systemd[1]: parsoid.service: Service hold-off time over, scheduling restart.
Dec 15 20:35:57 server.live-servers.net systemd[1]: Stopped MediaWiki Parsoid Server.
Dec 15 20:35:57 server.live-servers.net systemd[1]: parsoid.service: Start request repeated too quickly.
Dec 15 20:35:57 server.live-servers.net systemd[1]: Failed to start MediaWiki Parsoid Server.

[Edit]

Dec 15 20:57:33 server88-208-249-95.live-servers.net systemd[1]: [/etc/systemd/system/parsoid.service:5] Executable path is not absolute, ignoring: node /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
Dec 15 20:57:33 server.live-servers.net systemd[1]: parsoid.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
root@server:/etc/systemd/system# /var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js
Error while reading config file: Error: ENOENT: no such file or directory, open '/etc/systemd/system/config.yaml
filbranden
  • 21,113
  • 3
  • 58
  • 84
Jamie Hutber
  • 121
  • 3
  • 7
  • 17
  • 1
    As far as I know, node files won't run by default/"natively". Try running `/var/www/gwart/mediawiki/extensions/VisualEditor/parsoid/bin/server.js` in your terminal. To fix this, run `whereis node` and prepend the binary path to the `ExecStart=` statement. – rudib Dec 15 '18 at 20:45
  • Very good point, give me 5, I think I can use this :)( – Jamie Hutber Dec 15 '18 at 20:51
  • I've updated the question with the latest, but it seems to me. `node ..bin/server.js` will work in the terminal, however service requires an absolute path, which means I have no way of telling it where the base path should be, in regards to getting the config.yml is. I guess I could `ln` it? – Jamie Hutber Dec 15 '18 at 21:02
  • 1
    See my first comment. Run `whereis node` and use the absolute path to the node binary. – rudib Dec 15 '18 at 21:03
  • Ye sorry, I should have mentioned I did do this: `Environment=PATH=/usr/bin/node:/usr/local/bin`. `/usr/bin/node` is the absolute path to node. But I can't do `ExecStart=/usr/bin/node /var/www/gwart.co.uk/mediawiki/extensions/VisualEditor/parsoid/bin/server.js` as it then says I need to use an `absolute` path. – Jamie Hutber Dec 15 '18 at 21:06
  • :| Maybe I can and I got it wrong :D Still, the node server is reporting as running, but it seems to be rather slow (it doesn't return anything at all), but that is another a problem. Thanks very much for your help – Jamie Hutber Dec 15 '18 at 21:08
  • 2
    `ExecStart=/usr/bin/node /path/to/your/file.js` should work fine. `ExecStart=node /path/to/your/file.js` won't work as `node` is not an absolute path. – rudib Dec 15 '18 at 21:13
  • Note that the `production` flag might restrict some access. – rudib Dec 15 '18 at 21:14
  • humm I'm not sure how this question will help others, I think maybe I should change the title and let you add an answer? Otherwise I'll need to google something for `Dec 15 21:07:04 server.live-servers.net node[16320]: {"name":"parsoid","hostname":"server.live-servers.net","pid":16320,"level":40,"message":"first worker died during startup, continue startup","worker_pid":16331,"exit_code":1,"startup_attempt":1,"levelPath":"warn/service-runner/master","msg":"first worker died during startup, continue startup","time":"2018-12-15T21:07:04.563Z","v":0} ` – Jamie Hutber Dec 15 '18 at 21:15
  • [This thread might be related to that problem.](https://www.mediawiki.org/wiki/Topic:Uq1qjam84dx9v48a) So that might be you running an incpmatible version of node. Or it might be a configuration issue. Reagrding the question: We could make it something like "how to run a nodejs app with systemd", but that might be a duplicate then... – rudib Dec 15 '18 at 22:03
  • This is https://unix.stackexchange.com/questions/395131/ and https://unix.stackexchange.com/questions/424909/ and https://unix.stackexchange.com/questions/208835/ again. – JdeBP Dec 16 '18 at 09:24

0 Answers0