“ systemctl start pm2-user-name”给出错误

时间:2019-07-09 10:06:41

标签: node.js ubuntu nginx digital-ocean pm2

我正在设置新服务器,现在尝试安装pm2并按照以下说明进行操作https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04

尝试sudo systemctl start pm2-userName时收到以下错误消息:“由于无法执行单元配置所需的步骤,因此pm2-userName.service的作业失败。”

由于我对此一无所知,因此任何帮助将不胜感激。谢谢!”

到目前为止,我已经按照以下步骤操作: -sudo npm install pm2@latest -g //(安装良好!) -pm2 start hello.js //(工作正常!) -pm2 startup systemd //(我得到一个sudo env PATH ...以进行复制粘贴) -copyPasted sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u carles --hp /home/carles //(一切看起来仍然很好并且可以正常工作(请参见下面的启动脚本) -sudo pm2 save(有效) -s udo systemctl start pm2-carles(失败!因为pm2-carles.service的Job失败,因为该服务未执行其单元配置所要求的步骤。) -systemctl status pm2-carles.service //(已加载但处于活动状态:失败(结果:协议)

启动脚本/// #########################

[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=carles
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/carles/.pm2
PIDFile=/home/carles/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-carles.service
Command list
[ 'systemctl enable pm2-carles' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-carles.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-carles...
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd

JOURNALCTL -XE ############################################ ###

Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
Jul 09 09:36:19 future-card pm2[4752]: [PM2] Resurrecting
Jul 09 09:36:19 future-card pm2[4752]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:19 future-card pm2[4752]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:19 future-card pm2[4752]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:36:19 future-card pm2[4752]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:19 future-card pm2[4752]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 33m    │ 0
Jul 09 09:36:19 future-card pm2[4752]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:19 future-card pm2[4752]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:20 future-card pm2[4783]: [PM2] Resurrecting
Jul 09 09:36:20 future-card pm2[4783]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:20 future-card pm2[4783]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:20 future-card pm2[4783]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:36:20 future-card pm2[4783]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:20 future-card pm2[4783]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 33m    │ 0
Jul 09 09:36:20 future-card pm2[4783]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:20 future-card pm2[4783]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:20 future-card pm2[4815]: [PM2] Resurrecting
Jul 09 09:36:20 future-card pm2[4815]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:20 future-card pm2[4815]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:20 future-card pm2[4815]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:36:20 future-card pm2[4815]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:20 future-card pm2[4815]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 33m    │ 0
Jul 09 09:36:20 future-card pm2[4815]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:20 future-card pm2[4815]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:36:21 future-card pm2[4846]: [PM2] Resurrecting
Jul 09 09:36:21 future-card pm2[4846]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:36:21 future-card pm2[4846]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:36:21 future-card pm2[4846]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:36:21 future-card pm2[4846]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:36:21 future-card pm2[4846]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 33m    │ 0
Jul 09 09:36:21 future-card pm2[4846]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:36:21 future-card pm2[4846]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:20 future-card pm2[5168]: [PM2] Resurrecting
Jul 09 09:50:20 future-card pm2[5168]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:20 future-card pm2[5168]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:20 future-card pm2[5168]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:50:20 future-card pm2[5168]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:20 future-card pm2[5168]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 47m    │ 0
Jul 09 09:50:20 future-card pm2[5168]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:20 future-card pm2[5168]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:20 future-card pm2[5200]: [PM2] Resurrecting
Jul 09 09:50:20 future-card pm2[5200]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:20 future-card pm2[5200]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:20 future-card pm2[5200]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:50:20 future-card pm2[5200]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:20 future-card pm2[5200]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 47m    │ 0
Jul 09 09:50:20 future-card pm2[5200]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:20 future-card pm2[5200]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:21 future-card pm2[5233]: [PM2] Resurrecting
Jul 09 09:50:21 future-card pm2[5233]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:21 future-card pm2[5233]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:21 future-card pm2[5233]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:50:21 future-card pm2[5233]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:21 future-card pm2[5233]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 47m    │ 0
Jul 09 09:50:21 future-card pm2[5233]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:21 future-card pm2[5233]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:22 future-card pm2[5265]: [PM2] Resurrecting
Jul 09 09:50:22 future-card pm2[5265]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:22 future-card pm2[5265]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:22 future-card pm2[5265]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:50:22 future-card pm2[5265]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:22 future-card pm2[5265]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 47m    │ 0
Jul 09 09:50:22 future-card pm2[5265]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:22 future-card pm2[5265]:  Use `pm2 show <id|name>` to get more details about an app
Jul 09 09:50:23 future-card pm2[5295]: [PM2] Resurrecting
Jul 09 09:50:23 future-card pm2[5295]: [PM2] Restoring processes located in /home/carles/.pm2/dump.pm2
Jul 09 09:50:23 future-card pm2[5295]: ┌──────────┬────┬─────────┬──────┬──────┬────────┬─────────┬────────┬──
Jul 09 09:50:23 future-card pm2[5295]: │ App name │ id │ version │ mode │ pid  │ status │ restart │ uptime │ c
Jul 09 09:50:23 future-card pm2[5295]: ├──────────┼────┼─────────┼──────┼──────┼────────┼─────────┼────────┼──
Jul 09 09:50:23 future-card pm2[5295]: │ hello    │ 0  │ N/A     │ fork │ 3268 │ online │ 0       │ 47m    │ 0
Jul 09 09:50:23 future-card pm2[5295]: └──────────┴────┴─────────┴──────┴──────┴────────┴─────────┴────────┴──
Jul 09 09:50:23 future-card pm2[5295]:  Use `pm2 show <id|name>` to get more details about an app```

I expect sudo systemctl start pm2-carles to run and work, instead I am getting "pm2-carles.service - PM2 process manager
   Loaded: loaded (/etc/systemd/system/pm2-carles.service; enabled; vendor preset: enabled)
   Active: failed (Result: protocol) since Tue 2019-07-09 09:50:23 UTC; 1min 2s ago
     Docs: https://pm2.keymetrics.io/
  Process: 5295 ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect (code=exited, status=0/SUCCESS)"

1 个答案:

答案 0 :(得分:1)

我们需要先杀死现有的master进程,然后用systemd重启pm2 master进程。以下步骤将解决您的问题。

  1. 运行 pm2 kill 以终止已启动的主进程。
  2. 运行 pm2 startup systemd
  3. 运行它在第 2 步中生成的命令
<块引用>

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 启动 systemd -u USERNAME --hp /home/USERNAME

  1. 运行 sudo systemctl start pm2-USERNAME,现在你有一个由 systemd 管理的 pm2 主进程。

  2. 您可以使用 systemctl status pm2-USERNAME 进行验证。

  3. 运行 pm2 save 将您的应用配置保存到 /home/USERNAME/.pm2

因此 systemd 启动的 pm2 主进程可以在服务器重启后恢复。

您可以找到有关此问题的更多信息 here at the github