沙滩星空的博客沙滩星空的博客

debian使用/etc/rc.local设置frp开机启动

本文适用于 Debian 11 Bullseye, Debian 10 Buster 和 Debian 9 Strech。

一般我们都是推荐使用 systemd 写个系统服务,但是对于一些简单的脚本或者懒人来说,添加命令到 /etc/rc.local 文件更方便,但是自从 Debian 9 开始,Debian 默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的:

root@debian ~ # cat /lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

默认情况下服务为关闭状态

root@debian ~ # systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)

1. 创建开机启动脚本

设frp文件夹路径为: /home/yourname/frp_0.42.0_linux_amd64
创建启动脚本: /home/yourname/frp_0.42.0_linux_amd64/nohupfrpc.sh

一定记得使用绝对路径,否则开机启动会失败

vim /home/yourname/frp_0.42.0_linux_amd64/nohupfrpc.sh

#!/bin/sh
nohup /home/yourname/frp_0.42.0_linux_amd64/frpc -c /home/yourname/frp_0.42.0_linux_amd64/frpc.ini > /home/yourname/frp_0.42.0_linux_amd64/nohup.out 2>&1 &

2. 创建 /etc/rc.local 文件

手动添加 /etc/rc.local 文件:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/yourname/frp_0.42.0_linux_amd64/nohupfrpc.sh
exit 0

3. 赋予 /etc/rc.local 文件可执行权限, 并启动 rc-local 服务

chmod +x /etc/rc.local
systemctl start rc-local
systemctl enable rc-local

Debian 11 Bullseye 解决 /etc/rc.local 开机启动问题 https://u.sb/debian-rc-local/
使用systemd写系统服务 http://blog.catmes.com/archives/systemd-timer.html

未经允许不得转载:沙滩星空的博客 » debian使用/etc/rc.local设置frp开机启动

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址