系统版本为 Ubuntu 20.04.3 LTS
创建service文件
在/etc/systemd/system 下创建一个 frp-core.service 文件
内容为:
[Unit]
#当前服务的简单描述
Description=Frp Core
[Service]
# 要执行的bash文件
ExecStart=/home/ubuntu/frp/frp_core/start.sh
# 后台执行
Type=oneshot
# 设为yes,表示进程退出以后,服务仍然保持执行
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
/home/ubuntu/frp/frp_core/start.sh:
#!/bin/sh
# 一定要有上边那行 否则启动服务会报 203
echo '开机自启动'
重新加载服务
添加或修改配置文件后,需要重新加载
# 添加或修改配置文件后,需要重新加载
systemctl daemon-reload
# 开机启动
systemctl enable frp-core
# 关闭开机启动
systemctl disable frp-core
# 启动服务
systemctl start frp-core
# 停止服务
systemctl stop frp-core
# 重启服务
systemctl restart frp-core
# 查看服务状态
systemctl status frp-core
# 结束服务进程(服务无法停止时)
systemctl kill frp-core
之前也有用pm2 来管理启动项,有时候会出现重启后列表清空的情况,所以改用系统服务的方式来启动frp,这样能随地连上家里的树莓派了!
Systemd简介:https://fedoraproject.org/wiki/Systemd/zh-cn
Systemd.service 中文手册:http://www.jinbuguo.com/systemd/systemd.service.html