通过/etc/rc.local实现开机自动拉起服务

来源:互联网 发布:全民淘宝客 编辑:程序博客网 时间:2024/06/05 05:35
添加服务到/etc/rc.local
如自动拉起apache服务:

/etc/rc.local:


#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch /var/lock/subsys/local/usr/sbin/apachectl start


服务是关闭的
[root@limt ~]# chkconfig --list|grep httphttpd           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭[root@limt httpd]# rebootBroadcast message from root@limt        (/dev/pts/1) at 21:25 ...The system is going down for reboot NOW!



开机后http进程已经启动:
[root@limt ~]# ps -ef|grep httproot      2907     1  0 21:29 ?        00:00:00 /usr/sbin/nss_pcache 163842 off /etc/httpd/aliasroot      2909     1  0 21:29 ?        00:00:00 /usr/sbin/httpd -k startroot      2984  2909  0 21:29 ?        00:00:00 /usr/bin/crlhelper 196611 2909 /etc/httpd/aliasapache    2987  2909  0 21:29 ?        00:00:00 /usr/sbin/httpd -k startapache    2988  2909  0 21:29 ?        00:00:00 /usr/sbin/httpd -k startapache    2989  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2990  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2991  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2992  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2993  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2994  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k startapache    2995  2909  0 21:30 ?        00:00:00 /usr/sbin/httpd -k start



对于有些服务最好在启动前先停止服务,因为有些服务进程有LOCK文件,如果异常停机后LOCK文件没有删除,在随机启动的时候会报服务已启动,通过在启动前先停止服务开消除LOCK文件来正常启动服务
如:


#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch /var/lock/subsys/local/usr/sbin/apachectl stop/usr/sbin/apachectl start

0 0