Ubuntu | arm ubuntu armv7l 开发板 ubuntu 系统添加开机启动脚本
标签搜索

Ubuntu | arm ubuntu armv7l 开发板 ubuntu 系统添加开机启动脚本

王先生
2023-10-31 / 0 评论 / 18 阅读 / 正在检测是否收录...

写一个守护进程,每10秒检测一次,如果存在就没事,如果不存在就启动

添加sshd开机自启

在目录/root/下创建sshd守护进程脚本sshd_daemon.sh

#!/bin/bash

while true;do
   count=`ps -ef |grep "/sbin/sshd" |grep -v "grep" |wc -l`
#   echo $count
   if [ $count -eq 0 ];then
       nohup /sbin/sshd >~/sshd.log 2>&1 &
   fi
   sleep 10
done

在/etc/rc.local中添加守护进程执行

/root/sshd_daemon.sh &

重新启动一下开机服务以确保修改生效

sudo systemctl restart rc-local.service

添加pppd开机自启

在目录/root/下创建sshd守护进程脚本ppp-on_daemon.sh

#!/bin/bash

while true;do
   count=`ps -ef |grep "/etc/gosuncn/gosuncn_ppp_dialer" |grep -v "grep" |wc -l`
#   echo $count
   if [ $count -eq 0 ];then
       cd /etc/gosuncn/ && nohup ./ppp-on >~/ppp-on.log 2>&1 &
   fi
   sleep 10
done

在/etc/rc.local中添加守护进程执行

/root/ppp-on_daemon.sh &

重新启动一下开机服务以确保修改生效

sudo systemctl restart rc-local.service

两个添加完,/etc/rc.local完成文件如下:

vim /etc/rc.local
vim /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.

# rc.local this files is exist /etc/rc.local

/root/sshd_daemon.sh &
/root/ppp-on_daemon.sh &

exit 0

重新启动一下开机服务以确保修改生效

sudo systemctl restart rc-local.service