0

I am trying to set up a systemd service for a simple react application. This application is hosted in /home/myuser/test. Both npm and node are in the PATH and hard linked to /usr/bin. All the files have permissions for the myuser:myuser user and group. If I launch this manually with npm start it launches correctly and serves the app from http://localhost:3000

    Compiled successfully!

You can now view test in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://myipaddress:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

If I try to launch the application through systemd, it fails but does not specify why. I am launching it from same path, with the same user, and have tried all combinations imaginable for ExecStart:

ExecStart=npm start
ExecStart=/usr/bin/npm start
ExecStart=/usr/bin/node /home/myuser/test/node_modules/react-scripts/scripts/start.js

They all produce the same result, namely, it "starts" ok, and soon after it just fails, with no reason for it apparently in journalctl:

 $sudo systemctl status node-client   
 ● node-client.service - Node-React Frontend Server
   Loaded: loaded (/etc/systemd/system/node-client.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-04-08 09:46:10 UTC; 679ms ago
 Main PID: 18165 (node)
   CGroup: /system.slice/node-client.service
           └─18165 /usr/bin/node /home/myuser/test/node_modules/react-scripts/scripts/start.js

Apr 08 09:46:10 hostname systemd[1]: Started Node-React Frontend Server.
Apr 08 09:46:10 hostname systemd[1]: Starting Node-React Frontend Server...

And a few seconds later...

$sudo systemctl status node-client
● node-client.service - Node-React Frontend Server
   Loaded: loaded (/etc/systemd/system/node-client.service; disabled; vendor preset: disabled)
   Active: activating (auto-restart) since Wed 2020-04-08 09:46:00 UTC; 3s ago
  Process: 18142 ExecStart=/usr/bin/node /home/ec2-user/test/node_modules/react-scripts/scripts/start.js (code=exited, status=0/SUCCESS)
 Main PID: 18142 (code=exited, status=0/SUCCESS)

I keep getting the following on journalctl

    -- Logs begin at Tue 2020-03-17 15:04:59 UTC, end at Wed 2020-04-08 09:48:23 UTC. --
Apr 08 09:48:22 hostname systemd[1]: Starting Node-React Frontend Server...
Apr 08 09:48:22 hostname systemd[1]: Started Node-React Frontend Server.
Apr 08 09:48:22 hostname systemd[1]: node-client.service holdoff time over, scheduling restart.
Apr 08 09:48:12 hostname nodeclient[18390]: Starting the development server...
Apr 08 09:48:12 hostname nodeclient[18390]: ℹ 「wds」: 404s will fallback to /
Apr 08 09:48:12 hostname nodeclient[18390]: ℹ 「wds」: Content not from webpack is served from /home/myuser/test/public
Apr 08 09:48:12 hostname nodeclient[18390]: ℹ 「wds」: webpack output is served from
Apr 08 09:48:12 hostname nodeclient[18390]: ℹ 「wds」: Project is running at http://myipaddress/
Apr 08 09:48:10 hostname systemd[1]: Starting Node-React Frontend Server...
Apr 08 09:48:10 hostname systemd[1]: Started Node-React Frontend Server.
Apr 08 09:48:10 hostname systemd[1]: node-client.service holdoff time over, scheduling restart.
Apr 08 09:48:00 hostname nodeclient[18368]: Starting the development server...
Apr 08 09:48:00 hostname nodeclient[18368]: ℹ 「wds」: 404s will fallback to /
Apr 08 09:48:00 hostname nodeclient[18368]: ℹ 「wds」: Content not from webpack is served from /home/myuser/test/public
Apr 08 09:48:00 hostname nodeclient[18368]: ℹ 「wds」: webpack output is served from
Apr 08 09:48:00 hosntame nodeclient[18368]: ℹ 「wds」: Project is running at http://myipaddress/

The systemd service file has changed over time but the error has been the same regardless of the ExecStart and other changes, this is the contents as of now:

[Unit]
Description=Node-React Frontend Server
After=syslog.target network.target

[Service]
ExecStart=/usr/bin/node node_modules/react-scripts/scripts/start.js
Restart=always
RestartSec=10s
TimeoutSec=900
User=myuser
Group=myuser
Environment=PATH=/usr/bin:/usr/local/bin
WorkingDirectory=/home/myuser/test/
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodeclient

[Install]
WantedBy=multi-user.target

The OS is Centos7. All the tests have been done with the same user, no sudo, same commands both manually and through systemd. Manual launch works, systemd doesn't.

Lastly, to mention, I have Express-NodeJS application through systemd and it is launching correctly, with the same systemd configuration. It only fails for React.

Any help would be greatly appreciated!

Thanks

Nissy

7
  • Do you have rsyslog running? If so, you may find messages in its output (StandardError=syslog). – Gerard H. Pille Apr 8 '20 at 11:31
  • You can already get the logs through journalctl, but it doesn't really through any real information. I have also played with the Type=forked, just in case, but doesn't work either. It's strange because launching a service for other node-based applications for backend works ok, just fails for react. – Nissy A.W. Apr 8 '20 at 12:37
  • Can you share enough of your start.js that would allow reproducing the problem? – Gerard H. Pille Apr 8 '20 at 12:56
  • BTW, what do you think are the consequences of "RestartSec=10s" ? – Gerard H. Pille Apr 8 '20 at 13:01
  • My start.js file is the standard react-scripts/scripts/start.js file in a " npx create-react-app my-app" command, as standard as it gets. The RestartSec=10s I used it when trying the Restart=always parameter, it waits 10s before restarting again. Is part of the testing to allow for some breath time while troubleshooting, nothing else. – Nissy A.W. Apr 8 '20 at 13:18
0

Try adding StandardInput=tty-force to your [Service] section

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.