Hes*_*ian 10 startup services nodejs npm 16.04
我需要在 16.4 上永久运行“node js”项目
并使用永久包在 ubuntu 的后台运行
现在我想向 ubuntu 添加一个启动服务,但我搜索没有结果。
我创建了一个名为文件test.conf
到/etc/init.d
测试.conf:
start on startup
exec forever start /root/node/node_modules/.bin/www
Run Code Online (Sandbox Code Playgroud)
Geo*_*sen 13
在最简单的使用中systemd service
:
安装forever
:
[sudo] npm install forever -g
Run Code Online (Sandbox Code Playgroud)编写并存储脚本以在首选位置运行。
写Systemd service
:
[Unit]
Description=forever service
After=network.target
[Service]
ExecStart=/home/george/.npm-global/bin/forever start /root/node/node_modules/.bin/www
ExecStop=/home/george/.npm-global/bin/forever stop /root/node/node_modules/.bin/www
Restart=always
RestartSec=10 # Restart service after 10 seconds if node service crashes
StandardOutput=syslog # Output to syslog
StandardError=syslog # Output to syslog
SyslogIdentifier=nodejs-example
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)将systemd service
文件另存/etc/systemd/system
为myforever.service
(或使用您喜欢的任何名称)。
启动服务并在启动时启用。
sudo systemctl start myforever.service
sudo systemctl enable myforever.service
Run Code Online (Sandbox Code Playgroud)检查它是否正在运行:
sudo systemctl status myforever.service
Run Code Online (Sandbox Code Playgroud)要随时停止和禁用它:
sudo systemctl stop myforever.service
sudo systemctl disable myforever.service
Run Code Online (Sandbox Code Playgroud)笔记:
systemd service
许多可用选项的简化版本myforever
没有.service
扩展名的情况下调用,systemd
会选择正确的文件/home/george/.npm-global/bin/forever
是我的node
模块保存的地方,你的会有所不同。找到它which forever
附加信息:
https://www.axllent.org/docs/view/nodejs-service-with-systemd/
归档时间: |
|
查看次数: |
38143 次 |
最近记录: |