阅读 1237

Linux开机自启脚本

Centos7:

创建启动脚本frps.sh
#!/bin/sh

nohup ./frps -c frps.ini >/dev/null 2>&1 &
复制代码
创建任务脚本frps.sh
cd /etc/rc.d/init.d/
vim frps.sh

#!/bin/sh
#chkconfig: 2345 20 80

cd /root/frp_0.26.0_linux_amd64/
./frps.sh

#添加到任务
chkconfig --add frps.sh
#开机启动
chkconfig frps.sh on
复制代码
其他方式:

etc/rc.d/rc.local或/etc/rc.local文件,在末尾增加如下内容

su - user -c '/root/frp_0.26.0_linux_amd64/frps.sh'
chmod +x /etc/rc.d/rc.local
复制代码

OpenWRT/LEDE(编辑/etc/init.d/frp):

#!/bin/sh /etc/rc.common
 
START=90
STOP=90
SERVICE=frpc
USE_PROCD=1
PROC="/root/frp/frpc -c /root/frp/frpc.ini"
 
start_service()
 
{
    procd_open_instance
    procd_set_param command $PROC
    procd_set_param respawn
    procd_close_instance
 
}
 
service_triggers()
{
    procd_add_reload_trigger "rpcd"
}
复制代码
设置开机启动:
/etc/init.d/frp start
/etc/init.d/frp enable && echo on
复制代码
OpenWRT natapp启动脚本:
#!/bin/sh /etc/rc.common
### BEGIN INIT INFO
# Provides:          natapp.cn
# Required-Start:    $network $remote_fs $local_fs
# Required-Stop:     $network $remote_fs $local_fs
# Short-Description: natapp 开机启动脚本 for openwrt
# Description:
# https://github.com/natapp/natapp_autostart/tree/master/OpenWRT
### END INIT INFO

START=76

NAME=natapp
DAEMON=/usr/natapp/$NAME
PIDFILE=/var/run/$NAME.pid

start() {
   if [ -f $PIDFILE ]; then
        echo -n "$NAME already running"
        echo "."
    else
        echo "Starting $NAME..."
	    start-stop-daemon -S -x $DAEMON  -p $PIDFILE -m -b
        echo "."
    fi
}
stop() {
        echo "Stoping $NAME..."
        start-stop-daemon -K  -p $PIDFILE  -s TERM
        rm -rf $PIDFILE
        echo "."
}
复制代码
文章分类
后端
文章标签