Skip to content

Instantly share code, notes, and snippets.

@ihipop
Last active December 26, 2023 05:13
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save ihipop/4dc607caef7c874209521b10d18e35af to your computer and use it in GitHub Desktop.
Save ihipop/4dc607caef7c874209521b10d18e35af to your computer and use it in GitHub Desktop.
FRP systemd 启动脚本 FRP systemd init config

This Version Allow run as nobody AND ports below 1024

/etc/systemd/system/frps.service

[Unit]
Description=FRP Server Daemon

[Service]
Type=simple
AmbientCapabilities=CAP_NET_BIND_SERVICE
ExecStart=/opt/bin/frps -c /opt/etc/frps.ini
Restart=always
RestartSec=2s
User=nobody
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

Systems that without AmbientCapabilities support,You need apt install libcap2-bin then

[Unit]
Description=FRP Server Daemon

[Service]
Type=simple
ExecStartPre=-/usr/sbin/setcap cap_net_bind_service=+ep /opt/bin/frps
ExecStart=/opt/bin/frps -c /opt/etc/frps.ini
Restart=always
RestartSec=2s
User=nobody
PermissionsStartOnly=true
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

/etc/systemd/system/frpc.service

[Unit]
Description=FRP Client Daemon
After=network.target
Wants=network.target

[Service]
Type=simple
ExecStart=/opt/bin/frpc -c /opt/etc/frpc.ini
Restart=always
RestartSec=20s
User=nobody
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

Config

systemctl daemon-reload
systemctl enable frpc
systemctl status frpc
systemctl enable frps
systemctl status frps
@ZHLHZHU
Copy link

ZHLHZHU commented Mar 5, 2019

frpc.service的ExecStart应该是/opt/bin/frpc

@archchen
Copy link

应该放在/lib/systemd/system/目录下面
frpc最好使用@来支持多个客户端连接到不同的服务器
/lib/systemd/system/frpc@.service
[Unit]
Description=FRP Client Daemon
After=network.target
Wants=network.target

[Service]
Type=simple
ExecStart=/opt/bin/frpc -c /opt/etc/%i.ini
Restart=always
RestartSec=20s
User=nobody

[Install]
WantedBy=multi-user.target

@ihipop
Copy link
Author

ihipop commented Jul 9, 2019

frpc.service的ExecStart应该是/opt/bin/frpc

已经修改

@sillydanny
Copy link

很好, 我客戶端已經可以開機自啟動. 謝謝分享.

@andrew7baker
Copy link

想问下 After=network.target 时什么意思? 是指 网络启动好之后就行嘛。不需要用户名密码登录。
问这个问题的场景是这样: 装 frpc机器是不连显示器的。有时候重启还需要接显示器登录之后。fprc才启动。
理想情况是,断电重启后.frpc客户端就自动连上了。远程就可以 ssh了。

@ihipop
Copy link
Author

ihipop commented Sep 9, 2020

想问下 After=network.target 时什么意思? 是指 网络启动好之后就行嘛。不需要用户名密码登录。
问这个问题的场景是这样: 装 frpc机器是不连显示器的。有时候重启还需要接显示器登录之后。fprc才启动。
理想情况是,断电重启后.frpc客户端就自动连上了。远程就可以 ssh了。

https://www.freedesktop.org/software/systemd/man/systemd.special.html#network.target

https://www.freedesktop.org/software/systemd/man/systemd.special.html#network-online.target

@Eminlin
Copy link

Eminlin commented Nov 7, 2020

不要忘了这一句 sudo systemctl daemon-reload

@Lehmaning
Copy link

Lehmaning commented Dec 20, 2021

frpc.service 可以加一句:

ExecReload=frpc reload

前提是 frpc.ini 中有设定 admin_port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment