chkconfig 添加脚本开机自启动

摘要:
第一行告诉chkconfig默认情况下应该在哪个运行级别启动服务,以及启动和停止优先级。在任何运行级别,都应该使用-而不是运行级别列表。用反斜杠继续。例如,Rand.init有以下三行:#chkconfig:23452080#描述:保存并恢复系统熵池以提高#随机数生成的质量。这意味着随机脚本应该在2、3、4和5级启动。其启动优先级应为20,停止优先级应为80。你应该能够清楚描述中所写的内容;使行继续。此行前面的多余空间将被忽略。

1./etc/rc.local  自启动

2.通过chkconfig管理

如何让一个脚本被chkconfig管理

[root@oldboyedu01 ~]# vim /etc/init.d/oldgirld

# chkconfig: 2345 99 99  ##这步必须的  vim /etc/init.d/crond 配置中可见

# description:[XM1]  Saves and restores system entropy pool for

echo 1

~  

[root@oldboyedu01 ~]# chmod +x /etc/init.d/oldgirld  ##给文件加x执行权限

[root@oldboyedu01 ~]# chkconfig --add oldgirld  ##添加自启动

[root@oldboyedu01 ~]# chkconfig |grep old

oldgirld       0:off       1:off       2:on       3:on       4:on       5:on6:off

翻译

RUNLEVEL FILES

       Each service which should be manageable by chk-

       config  needs two or more commented lines added

       to its init.d script. The first line tells chk-

       config  what  runlevels  the  service should be

       started in by default, as well as the start and

       stop  priority  levels.  If  the service should

       not, by default, be started in any runlevels, a

       -  should  be  used  in  place of the runlevels

       list.  The second line contains  a  description

       for  the  service,  and  may be extended across

       multiple lines with backslash continuation.

       For example, random.init has these three lines:

       # chkconfig: 2345 20 80

       # description: Saves and restores system entropy pool for

       #              higher quality random number generation.

       This  says  that  the  random  script should be

       started in levels 2, 3,  4,  and  5,  that  its

       start  priority should be 20, and that its stop

       priority should be 80.  You should be  able  to

       figure  out  what  the  description says; the

       causes the line to  be  continued.   The  extra

       space in front of the line is ignored.

译:

RUNLEVEL文件每个服务应该由chkconfig管理,chkconfig需要添加到init.d脚本中的两个或更多注释行。第一行告诉chkconfig默认应该在什么运行级别启动服务,以及启动和停止优先级级别。在任何运行级别中,都应该使用a-来代替runlevel列表。通过反斜杠的延续。例如,Rand.init有以下三行:#chkconfig:2345 20 80#Description:保存和恢复系统熵池以提高质量#随机数生成。这意味着随机脚本应该在级别2、3、4和5中启动,它的开始优先级应该是20,它的停止优先级应该是80。你应该能够弄清楚描述中写了什么;导致行被继续。该行前面的额外空间被忽略了。

# chkconfig: 2345 20 80

# description: Saves and restores system entropy pool for

# higher quality random number generation.

使用范例:

chkconfig --list #列出所有的系统服务

chkconfig --add httpd #增加httpd服务

chkconfig --del httpd #删除httpd服务

chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态

chkconfig --list #列出系统所有的服务启动情况

chkconfig --list mysqld #列出mysqld服务设置情况

chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭

chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级

如何增加一个服务:

1.服务脚本必须存放在/etc/ini.d/目录下;

2.chkconfig --add servicename

在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了; 3.chkconfig --level 35 mysqld on

修改服务的默认启动等级。


 [XM1]说明,注释

免责声明:文章转载自《chkconfig 添加脚本开机自启动》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇JAVA序列化:implements SerializableLeftoverDataException,依赖包,apache license 2.0下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

mysql8 安装,并且配置远程登录

1.下载mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 安装包 下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 2.解压mysql-8.0.18-linux-glibc2.12-x86_...

linux 下将tomcat注册成服务并开机启动

一、将startup.sh和shutdown.sh新建软连接到/usr/bin ln -s /usr/local/apache-tomcat-8.5.38/bin/startup.sh /usr/bin/startup.sh ln -s /usr/local/apache-tomcat-8.5.38/bin/shutdown.sh /usr/bin/shu...

设置Django生产环境系统重启后的自动启动项

前面,作者已经介绍了把Django部署到生产环境中的主要方法,现在我们来看一下如何设置项目开机启动。 在把Django项目部署到生产环境中时,我们前面使用安装包和源码安装了Nginx、uwsgi、redis等,这些应用安装后,不会使用系统默认服务一样来快速启停服务,需要到对应的安装目录下才能启动应用。如果服务因为某些原因重启,上述应用不能自动启用,实际生产...

apache 开机自启动脚本设置

默认我们源码编译安装apache,是不能使用service这个命令来启动的,通常我们启动的命令是: [root@localhost httpd-2.2.16]# /usr/local/apache2/bin/apachectl start /usr/local/apache2/bin/中的apachectl其实就是一个启动脚本,我们把他copy到/etc/...

Rhel6和rhel7的主要区别

内核版本 Rhel6.8的内核版本为2.6.32-642,rhel7使用的是3.10.x-x系列,最新的rhel7.3使用的是3.10.0-514。 文件系统的差别 Rhel7默认使用xfs文件系统,rhel6默认为ext4文件系统,但从rhel6.8起开始支持xfs系统。 设置默认启动级别 Rhel6:vim /etc/inittab 将末行的id:3:...

linux任务计划cron chkconfig工具 systemd管理服务 unit介绍 target介绍

[root@lizhipenglinux01 ~]# crontab -e  编写任务计划no crontab for root - using an empty one 20 11 29 01 1 echo "OK" > /root/cron.log      表示在1月29日(星期一)的11点20分执行:echo  "OK" > /ro...