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


    写一个脚本,名字为: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  .....

    完毕

  • 相关阅读:
    MyEclipse 2015 Stable 2.0破解方法
    GeoGlobe Server运维
    GeoGlobe Server运维
    Silverlight用户无法注册之MySql.Data.dll不一致
    Photoshop影像匀色技术
    GeoGlobe Server使用问题收集
    Windows Server 2008 R2中无法使用360免费Wifi的解决方案
    吉奥平台软件安装经验分享
    U盘中毒后变为快捷方式的解决方法
    主机访问虚拟机中新建的网站
  • 原文地址:https://www.cnblogs.com/wt645631686/p/6868713.html
Copyright © 2020-2023  润新知