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  .....

完畢


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM