frp 树莓派通过systemd设置开机启动

树莓派操作系统为

xxx@raspberrypi: $ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/

frp 版本为 frp_0.51.2_linux_arm64.tar.gz
按照官方的教程:https://gofrp.org/docs/setup/systemd/ 使用systemctl start frps可以成功启动frpc.

但是重启树莓派的时候 frpc 提示启动成功了但是进程里无显示。

xxx@raspberrypi:~ $ sudo systemctl status frpc
● frpc.service - frp client
     Loaded: loaded (/etc/systemd/system/frpc.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Wed 2023-08-02 20:20:25 CST; 13h ago
    Process: 520 ExecStart=/home/xxx/runFrp/frpc -c /home/xxx/runFrp/frpc.ini (code=exited, status=0/SUCCESS)
   Main PID: 520 (code=exited, status=0/SUCCESS)
        CPU: 102ms

Aug 02 20:20:24 raspberrypi systemd[1]: Started frp client.
Aug 02 20:20:25 raspberrypi systemd[1]: frpc.service: Succeeded.

查看frpc进程

xxx@raspberrypi: $ ps aux | grep frpc
xxx         4215  0.0  0.0   5912   672 pts/0    S+   09:46   0:00 grep --color=auto frpc

搜索到了一篇文章https://blog.csdn.net/Ruanes/article/details/108186316

通过设置[Service]部分,当frp服务启动失败时,时隔5秒后重新启动它

添加一个参数 RestartSec=5 问题成功解决
完整systemd代码 xxx@raspberrypi: $ vi /etc/systemd/system/frpc.service

[Unit]
Description = frp client
After = network.target syslog.target
Wants = network.target

[Service]
Type=simple
ExecStart=/home/xxx/runFrp/frpc -c /home/xxx/runFrp/frpc.ini
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

修改完之后需要执行 sudo systemctl daemon-reload 使命令生效

posted @ 2023-08-03 10:04  nil  阅读(312)  评论(2编辑  收藏  举报