我正在使用 http-server
为一个简单的 Angular 应用程序提供服务。当我从 bash 运行应用程序时,它运行良好。但是当我尝试从 systemd 单元文件运行时,它失败了。
这是我用来运行它的 systemd 单元文件。
[Unit]
Description=web_app
Requires=network.target
After=multi-user.target
[Service]
ExecStart=/usr/bin/http-server -p 80
Type=forking
WorkingDirectory=/home/ubuntu/jenkins/workspace/deepcareweb_dev
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=web_app
User=root
#Group=<alternate group>
#Environment=NODE_ENV=production PORT=1337
[Install]
WantedBy=multi-user.target
我应该怎么做才能从 systemd 单元文件运行 http-server
?
编辑 1:systemctl status
$ sudo systemctl status web_app
● web_app.service - web_app
Loaded: loaded (/etc/systemd/system/web_app.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Sun 2017-03-05 06:17:14 UTC; 10s ago
Process: 1879 ExecStart=/usr/bin/http-server -p 80 (code=exited, status=200/CHDIR)
Main PID: 1354 (code=exited, status=200/CHDIR)
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Control process exited, code=exited status=200
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Failed to start web_app.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Unit entered failed state.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Failed with result 'exit-code'.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Service hold-off time over, scheduling restart.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Stopped web_app.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: web_app.service: Start request repeated too quickly.
Mar 05 06:17:14 ip-172-31-22-251 systemd[1]: Failed to start web_app.
最佳答案
尝试删除“Restart=always”行,因为它会触发“Start request repeated too quickly”错误。删除它后,您应该会看到一条真正的错误消息。
在我的例子中,错误“在步骤 CHDIR 生成/usr/local/bin/http-server 时失败:没有这样的文件或目录”
将“WorkingDirectory”变量更改为“/”并将“ExecStart”更改为“/usr/bin/http-server WORKINGDIRECTORY -p 80”为我解决了这个问题。
关于angularjs - http-server 未在 systemd 中启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42605348/