I am trying to use a systemd service to run a Node app (specifically, a React app generated with create-react-app. I put a file
/etc/systemd/system/ with (minimally) these contents:
[Unit] Description=React Web Application [Service] ExecStart=/usr/local/bin/npm start --prefix=<path to app> [Install] WantedBy=multi-user.target
After starting the service, my browser shows the nginx
bad gateway error, and
ps aux | grep node shows no corresponding process. The output of
journalctl -u frontend reports successful steps like "Started React Web Application" and eventually "Starting development server…". However,
systemctl status frontend reports that the service is loaded but inactive/dead (edit: or, active/exited).
I tried some adjustments to the
.service file, in particular
KillMode=process. But the problem persists. What is going on? How to fix this?
The app does work fine if I run it directly using
npm start in the shell. Also, another (non-node) web server works fine running through a similar systemd script.
Here is the systemctl status output:
wm-frontend.service - React Web Application Loaded: loaded (/etc/systemd/system/wm-frontend.service; enabled; vendor preset: enabled) Active: active (exited) since Mon 2020-08-10 14:40:59 UTC; 32min ago Process: 4033 ExecStart=/usr/local/bin/npm start --prefix=/home/mw/wm-ax/frontend/blog --scripts-prepend-node-path (code=exited, status=0/SUCCESS) Main PID: 4033 (code=exited, status=0/SUCCESS) Aug 10 14:40:59 localhost systemd: Started React Web Application. Aug 10 14:41:00 localhost npm: > email@example.com start /home/mw/wm-ax/frontend/blog Aug 10 14:41:00 localhost npm: > react-scripts start Aug 10 14:41:04 localhost npm: ℹ ｢wds｣: Project is running at http://0.0.0.0:3000/ Aug 10 14:41:04 localhost npm: ℹ ｢wds｣: webpack output is served from Aug 10 14:41:04 localhost npm: ℹ ｢wds｣: Content not from webpack is served from /home/mw/wm-ax/frontend/blog/public Aug 10 14:41:04 localhost npm: ℹ ｢wds｣: 404s will fallback to / Aug 10 14:41:04 localhost npm: Starting the development server...