angularjs - http-server 未在 systemd 中启动

标签 angularjs node.js linux systemd

我正在使用 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/

相关文章:

linux - 苹果机 : IOError: [Errno 13] Permission denied

linux - svn存放项目代码在哪里?

angularjs - 如何使用 Angular JS 将一种日期格式转换为另一种格式?

javascript - ng-repeat 不更新 html

javascript - Node JS Inspect 显示属性具有值,但检查属性返回未定义

node.js - 如何在 NodeJs 中使用 session 变量?

linux - 需要将 AWS NFS 挂载移动到 Azure

javascript - 检测从 angularjs 中的 ngclick 调用了一个函数

jquery - ngImgCrop 无法在 UI Modal 内工作

node.js - 如何在真实服务中运行nuxt.js?