第一步:
sudo vim /lib/systemd/system/myapp.service
#如果/etc/systemd/system/myapp.service有过修改,需要进行更新,执行下面这个命令
systemctl daemon-reload
#查看服务是否被正确识别
systemctl list-unit-files|grep myapp
第二部:
[Unit]
#服务描述,写有意义的内容,便于识别
Description=myapp service
After=network.target syslog.target
Wants=network.target
[Service]
Type=simple
#启动服务的命令(此处写你的frps的实际安装目录)
WorkingDirectory=/myapp_path //所在目录
ExecStart=/myapp_path/startMyApp.sh
#ExecStart=/your/path/frps -c /your/path/frps.ini //目录和路径
[Install]
WantedBy=multi-user.target
第三部:
#查看系统服务文件是否被识别
# systemctl list-unit-files|grep myapp
--------------------------
myapp.service disabled
#自启动
# systemctl enable myapp.service
# systemctl list-unit-files|grep myapp
--------------------------
myapp.service enabled
第四部:
# 启动myapp服务
sudo systemctl start myapp
# 自启动
sudo systemctl enable myapp
# 重启应用
sudo systemctl restart myapp
# 停止应用
sudo systemctl stop myapp
# 查看应用的日志
sudo systemctl status myapp