运行 使用 Systemd 的 Ubuntu VM 后台节点应用程序

Run a node app in background in an Ubuntu VM using Systemd

尝试在 Ubuntu 15.04 VM 中使用 systemd 设置恶魔进程,由 Google Compute Engine 提供,运行 后台的幽灵博客平台。

到目前为止,我的服务脚本如下:

[Service]
ExecStart=/usr/bin/node /home/blog/index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
RestartSec=120s
SyslogIdentifier=blog-service
User=user
Group=user
Environment=NODE_ENV=production PORT=5000
[Install]
WantedBy=multi-user.target

启动服务并检查状态后,我得到:

blog.service
   Loaded: loaded (/etc/systemd/system/blog.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) since Fri 2015-08-21 01:04:01 UTC; 42s ago
  Process: 3455 ExecStart=/usr/bin/node /home/blog/index.js (code=exited, status=0/SUCCESS)
 Main PID: 3455 (code=exited, status=0/SUCCESS)

我不明白为什么我得到 (code=exited, status=0/SUCCESS),如果我 运行 手动节点 index.js 一切正常。我怎样才能让我的项目 运行ning 正确地进入后台?

status=0/SUCCESS表示一切正常,检查服务是否运行 ?

解决方案是在服务脚本中添加参数Type=forking。看起来不可能 运行 节点 Web 服务器不告诉系统创建子进程。