yapi icon indicating copy to clipboard operation
yapi copied to clipboard

yapi系统服务自启动方案centos7.3

Open quanapp opened this issue 7 years ago • 1 comments

版本号

1.8.0

什么问题

已在centos7.3下设置为系统自启动,详细方案如下:

=================================

1.建立系统服务文件

vi /lib/systemd/system/yapi.service
复制代码

[Unit] Description=yapi After=network.target remote-fs.target nss-lookup.target

[Service] Type=forking ExecStart=/bin/bash -c 'nohup node /usr/local/nodejs/bin/my-yapi/vendors/server/app.js >/dev/null 2>&1 &' ExecReload=/bin/bash -c 'kill -9 $(ps -ef|grep app.js|grep -v grep|awk '{print $2}');nohup node /usr/local/nodejs/bin/my-yapi/vendors/server/app.js >/dev/null 2>&1 &' ExecStop=/bin/bash -c 'kill -9 $(ps -ef|grep app.js|grep -v grep|awk '{print $2}')' PrivateTmp=true

[Install] WantedBy=multi-user.target

2.设置文件权限

chmod 754 yapi.service

3.服务重载 systemctl daemon-reload

4.启动服务

设置开机自启动 systemctl enable yapi.service

停止开机自启动: systemctl disable yapi.service

启动服务: systemctl start yapi.service

查看服务当前状态: systemctl status yapi.service

重新启动服务: systemctl restart yapi.service

quanapp avatar Aug 05 '19 08:08 quanapp

补充几点:

  • 上述代码中 /usr/local/nodejs/bin/my-yapi 这个路径要替换为你实际部署YApi的路径
  • 2.设置文件权限的准确代码为 chmod 754 /lib/systemd/system/yapi.service

mokeyjay avatar Aug 12 '19 15:08 mokeyjay