您的位置:首页 > 运维架构 > Apache

Linux下添加自定义脚本到开机自启动,标准rpm,举例:设置Apache自启动

2017-05-17 17:43 721 查看
写一个脚本,名字为:autostart.sh,放在/etc/init.d/目录下,赋予权限chmod +x /etc/init.d/autostart.sh

代码如下

#!/bin/sh
#chkconfig:2345 90 20
#description:Autostart server daemon
#shell脚本主体自定义
#....... start    ....
#....... stop     ......
#....... restart    ....


这样的话,service命令就可以使用了,看看chkconfg可不可使用

进入/etc/rc.d/init.d/
chkconfig --list autostart     //如果出现service  autostart supports.... ---add autostart')


执行

chkconfig autostart on
chkconfig --list autostart


返回

autostart      0:off    1:off   2:on   3:on  4:on    5:on    6:off


也可以关闭

chkconfig autostart off


不同的运行级定义如下:
# 0 - 停机(千万不能把initdefault 设置为0 )
# 1 - 单用户模式       # s   init s = init 1
# 2 - 多用户,没有 NFS
# 3 - 完全多用户模式(标准的运行级)
# 4 - 没有用到
# 5 - X11 多用户图形模式(xwindow)
# 6 - 重新启动 (千万不要把initdefault 设置为6 )

然后 init.6 重启测试

修改Apache来实现同理自启动

cd /etc/init.d                  //进入此目录
cp /usr/local/apache/bin/apachectl ./       //复制文件到当前目录
mv apachectl httpd               //找到apachectl,给它来个新命名为httpd
vim httpd                    //修改文件,把以下两行代码放置头部 #!/bin/sh下面
#chkconfig:2345 91 25
#description:Httpd server daemon


service httpd start
service httpd stop  ..测试,如果影响访问,然后测试chkconfig
chkconfig http on
chkconfig --list httpd  .....


完毕
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: