1、生成开机启动 pm2 服务的配置文件
运行:pm2 startup 命令
pm2 startup
[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=root
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/node-v14.14.0-linux-x64/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/root/.pm2
PIDFile=/root/.pm2/pm2.pid
Restart=on-failure
ExecStart=/root/node-v14.14.0-linux-x64/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/root/node-v14.14.0-linux-x64/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/root/node-v14.14.0-linux-x64/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Target path
/etc/systemd/system/pm2-root.service
Command list
[ 'systemctl enable pm2-root' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-root.service
[PM2] Making script booting at startup...
[PM2] [-] Executing: systemctl enable pm2-root...
Created symlink from /etc/systemd/system/multi-user.target.wants/pm2-root.service to /etc/systemd/system/pm2-root.service.
[PM2] [v] Command successfully executed.
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save
[PM2] Remove init script via:
$ pm2 unstartup systemd
执行
pm2 save
2、pm2 save
, 保存当前 pm2 运行的各个应用保存到 /root/.pm2/dump.pm2下,开机重启时读取该文件中的内容启动相关应用。
[root@xx ~]# pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /root/.pm2/dump.pm2
3、查看配置是否开启:使用命令systemctl status pm2-root.service文章来源:https://www.toymoban.com/news/detail-519788.html
● pm2-root.service - PM2 process manager
Loaded: loaded (/etc/systemd/system/pm2-root.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://pm2.keymetrics.io/
官方相关文档:http://pm2.keymetrics.io/docs/usage/startup/#generating-a-startup-script文章来源地址https://www.toymoban.com/news/detail-519788.html
到了这里,关于pm2设置开机启动的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!