linux 自启动 | 三种方式自启动

linux 实现自启动有多种方式,通过Linux 底层启动原理介绍,便可以理解以下几种方式

这里简单介绍一下这几种方式

一、自定义开机程序   /etc/rc.d/rc.local 

1.vim  /etc/rc.d/rc.local 
2.在exit0 之前添加启动命令

二、 通过服务的方式自启动

其中

1.在/etc/init.d 下建立相关程序的启动脚本ln -s /etc/init.d/服务名 /etc/rc.d/rc3.d/S100服务名 //S:开机自启动 100:启动顺序
2.chkconfig --add 服务名

(1)启动关闭服务
chkconfig 服务名 on 开机自启动    
chkconfig 服务名 off 关闭自启动
(2)启动关闭服务
service 服务名 start 手动启动服务
service 服务名 stop 手动关闭服务 

三、定时启动脚本
1. /root下写好启动的shell文件

1
2
3
4
5
6
7
8
9
10
#! /bin/sh
A=`netstat -anp | grep ":8080" grep "LISTEN" wc -l`
echo $A
if [ $A -eq 0 ]
then
/etc/init.d/tomcat start
echo "tomcat重启中"
else
echo "tomcat正在运行中"
fi

  

2. crontab -e 
3. 设置好定时时间 
4. 设置为每分钟检查一次 //*/1 * * * * 脚本目录



原文地址:https://www.cnblogs.com/wxiaote/p/10861665.html