1、生成開機啟動 pm2 服務(wù)的配置文件
運行: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
執(zhí)行
pm2 save
2、pm2 save
, 保存當(dāng)前 pm2 運行的各個應(yīng)用保存到 /root/.pm2/dump.pm2下,開機重啟時讀取該文件中的內(nèi)容啟動相關(guān)應(yīng)用。
[root@xx ~]# pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /root/.pm2/dump.pm2
3、查看配置是否開啟:使用命令systemctl status pm2-root.service文章來源:http://www.zghlxwxcb.cn/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/
官方相關(guān)文檔:http://pm2.keymetrics.io/docs/usage/startup/#generating-a-startup-script文章來源地址http://www.zghlxwxcb.cn/news/detail-519788.html
到了這里,關(guān)于pm2設(shè)置開機啟動的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!