Octofarm: 推荐自动启动 npm(在 linux 下)?

创建于 2020-04-28  ·  5评论  ·  资料来源: OctoFarm/OctoFarm

在 linux 下启动完成后是否有推荐的自动启动 npm 的方法。 我曾尝试使用 init.d 执行此操作,但没有成功。

question

最有用的评论

我在使用 Ubuntu 时成功使用了 systemd 服务文件。 正如 James 所说,新版本将随 pm2 一起发布。 使用 pm2,您可以运行pm2 startup ,它会检测您的 init 系统并输出一个命令来运行以生成启动文件。 我刚刚做到了,它似乎工作得很好。

完全披露:在今天之前我什至从未听说过 pm2,所以我不得不做一些研究,这就是我发现的和我所做的,它似乎有效。

这是我运行pm2 startup时发生的情况

ubuntu<strong i="10">@octofarm</strong>:~$ OctoFarm/node_modules/pm2/bin/pm2 startup
[PM2] Init System found: systemd
ubuntu
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu

然后在我运行命令后它告诉我:

ubuntu<strong i="14">@octofarm</strong>:~$ sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
[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=ubuntu
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/ubuntu/.pm2
PIDFile=/home/ubuntu/.pm2/pm2.pid
Restart=on-failure

ExecStart=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 resurrect
ExecReload=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 reload all
ExecStop=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

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

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

所有5条评论

很多人使用名为 pm2 的 npm 包。

您可以使用npm install pm2 -g

然后运行以下。

pm2 startup

在最后一个之后复制并粘贴 pm2 给你的输出。

pm2 start app.js --name OctoFarm

pm2 save

https://pm2.keymetrics.io/docs/usage/startup/

此处为您提供了有关它的更多信息,如果您遇到困难,请告诉我。

1.1.5 附带 pm2 作为依赖项,它使用它运行,我希望能够在启动时启用启动命令,所以它都是自动的,但我还没有深入研究它。

我在使用 Ubuntu 时成功使用了 systemd 服务文件。 正如 James 所说,新版本将随 pm2 一起发布。 使用 pm2,您可以运行pm2 startup ,它会检测您的 init 系统并输出一个命令来运行以生成启动文件。 我刚刚做到了,它似乎工作得很好。

完全披露:在今天之前我什至从未听说过 pm2,所以我不得不做一些研究,这就是我发现的和我所做的,它似乎有效。

这是我运行pm2 startup时发生的情况

ubuntu<strong i="10">@octofarm</strong>:~$ OctoFarm/node_modules/pm2/bin/pm2 startup
[PM2] Init System found: systemd
ubuntu
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu

然后在我运行命令后它告诉我:

ubuntu<strong i="14">@octofarm</strong>:~$ sudo env PATH=$PATH:/usr/bin /home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
[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=ubuntu
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/ubuntu/.pm2
PIDFile=/home/ubuntu/.pm2/pm2.pid
Restart=on-failure

ExecStart=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 resurrect
ExecReload=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 reload all
ExecStop=/home/ubuntu/OctoFarm/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

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

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

感谢您对你们两位的快速回复。 今天晚些时候会尝试这个。 我喜欢/讨厌 Linux 系统——大约有 10 种不同的方式来做所有事情。 我在 1980 年代后期开始使用 BSD Unix。

没问题,我暂时将其打开以提醒我向 README/Wiki 添加一些注释

添加了用于执行此跨平台操作的安装文档

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

NotExpectedYet picture NotExpectedYet  ·  27评论

MTrab picture MTrab  ·  123评论

juangonzalezpr picture juangonzalezpr  ·  10评论

Polloman93 picture Polloman93  ·  6评论

3DRemake picture 3DRemake  ·  7评论