显示 SysV 服务
chkconfig —list
systemd 服务
systemctl list-unit-files
查看在具体 target 启用的服务请执行
systemctl list-dependencies [target]
eg:systemctl list-dependencies aliyun.service
必备条件
# 找到node位置$ whereis node# node: /usr/local/system_config/node-v16.13.1-linux-x64/bin/node# 建立软连接$ sudo ln -s /usr/local/system_config/node-v16.13.1-linux-x64/bin/node /usr/bin/node# 全局安装forever$ npm i forever -g# 找到forever位置$ whereis node/usr/local/system_config/node-v16.13.1-linux-x64/bin/forever# 软连接文件位置$ cd /usr/bin# 如果文件名被占用,就删掉之前的 rm -rf node
linux上npm install时提示/usr/bin/env: node: Permission denied
配置快捷命令
1.vim /etc/init.d/nodeforever 复制一下文本,粘贴进去
#!/bin/sh# chkconfig: 2345 85 15# description: Startup script for nodeserver.# exit on first errorset -e# points to the root for forever configexport "FOREVER_ROOT=/root/.forever"#LOG=/data/nodeserver/log#PID=/data/nodeserver/pidstarts=("/usr/local/system_config/node-v16.13.1-linux-x64/bin/forever --sourceDir /usr/local/nginx/web-api start ./bin/www")stops=("/usr/local/system_config/node-v16.13.1-linux-x64/bin/forever stopall")# start functiondo_start(){for i in "${starts[@]}"do$idone}# stop functiondo_stop(){for i in "${stops[@]}"do$idone}# Decide what command is being calledcase "$1" instart)echo "Starting nodeserver..."do_startecho "done.";;stop)echo "Stoping nodeserver..."do_stopecho "done.";;restart)echo "Restarting nodeserver..."do_stopdo_startecho "done.";;*)echo "Usage: nodeserver {start|stop|restart}" >&2exit 3;;esacexit 0
2.chmod 755 /etc/init.d/nodeforever
3.chkconfig —add nodeforever
4.使用nodeserver命令
service nodeforever start
service nodeforever stop
service nodeforever restart
设置开机启动
cd /lib/systemd/system/ (主目录)
cd /usr/lib/systemd/system/
# vim node-forever.service
[Unit]Description=node-forever.serviceAfter=network.target[Service]Type=forkingExecStart=/usr/bin/forever /usr/local/nginx/web-api start ./bin/wwwExecReload=/usr/bin/forever restartallExecStop=/usr/bin/forever stopallPrivateTmp=true[Install]WantedBy=multi-user.target
systemctl enable node-forever.service
systemctl disable node-forever.service
systemctl list-unit-files | grep node 查看状态
systemctl is-enabled node-forever.service
