Linux下把api安装成服务并自启动
一、发布程序
以.net,把发布包整个拷到/opt/api下,全目录地址为:/opt/api/server,执行程序是testServer 为例
二、编写执行脚本
在opt/api下新建执行脚本start.sh,内容如下
#!/bin/bash
/opt/api/server/testServer &
三、编写服务
在/etc/systemd/system下新建test.service,内容如下
[Unit]
Description=TEST services
[Service]
Type=forking
ExecStart=/opt/start.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
四、控制服务
systemctl enable test.service #服务开机自启动
systemctl start test.service #服务启动
systemctl stop test.service #服务停止
systemctl status test.service #查看服务运行状态