NodeJS React Systemdサービスが機能しません。

NodeJS React Systemdサービスが機能しません。

簡単な反応アプリケーション用のシステムサービスを設定しようとしています。アプリケーションは/home/myuser/testでホストされています。 npmとnodeはどちらもPATHにあり、/usr/binにハードリンクされています。すべてのファイルには、myuser:myuserユーザーとグループの権限があります。手動で起動するとnpm start正しく起動し、次のアプリケーションを提供します。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.

systemdを介してアプリケーションを起動しようとすると、理由を説明せずに失敗します。同じユーザーを使用して、同じパスで開始して想像できるすべてのExecStartの組み合わせを試しました。

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

彼らはすべて同じ結果を生成します。つまり、正常に「起動」してからすぐに失敗します。明らかに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...

数秒後...

$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)

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/

システムサービスファイルは時間の経過とともに変更されましたが、ExecStartやその他の変更に関係なくエラーは同じで、現在は次のようになります。

[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

オペレーティングシステムはCentos7です。すべてのテストは、sudoなしで同じユーザーを使用して手動で、およびsystemdを介して同じコマンドを実行することによって行われました。手動起動は機能しますが、systemdは機能しません。

最後に、systemdを介してExpress-NodeJSアプリケーションがあり、同じsystemd構成を使用して正しく起動されます。 Reactでのみ失敗します。

どんな助けでも大変感謝します!

ありがとう

素晴らしい

ベストアンサー1

セクションStandardInput=tty-forceに追加してみてください[Service]

おすすめ記事