1. 程式人生 > >linux基礎--debian開機自啟動指令碼

linux基礎--debian開機自啟動指令碼

1.debian沒有rc.local這個檔案的需要自建連線:

touch /etc/rc.local
chmod 755 /etc/rc.local
cd /etc/rc2.d  
ln -s ../rc.local ./S99rc.local
cd /etc/rc3.d
ln -s ../rc.local ./S99rc.local

l然後將要執行的shell路徑加到rc.local末尾

注意給許可權shell檔案和rc.local

2.1.指令碼檔案tomcat如下,放置在/etc/init.d/目錄

安裝啟動指令碼到system initscript。[email protected]:~# insserv -v -d/etc/init.d/tomcat

如果沒有insserv,安裝方法見:

aptitudeinstall insserv

或者執行級別設定 #update-rc.d tomcat start 2023 4 5 .stop 20 0 16. 格式:update-rc.d<basename>start|stop<order> <runlevels>
這是合併起來的寫法,注意它有2個點號,效果等於下面方法
update-rc.d tomcat defaults

說明:/etc/init.d/這個是目錄,下面存放著很多的服務程式(當然都是可執行的)。 /etc/init.d/httpd start就是啟動httpd的意思。 
1. 關於linux的啟動

init是所有程序的頂層
init讀取/etc/inittab,執行rc.sysinit指令碼
(注意檔名是不一定的,有些unix甚至會將語句直接寫在inittab中)

rc.sysinit指令碼作了很多工作:

init $PATH

config network

start swap function

set hostname

check root file system, repair if needed

check root space

....

rc.sysinit根據inittab執行rc?.d指令碼
linux是多使用者系統,getty是多使用者與單使用者的分水嶺
在getty之前執行的是系統指令碼

getty(get teletypewriter)

功能說明:是Unix類作業系統啟動時必須的三個步驟之一,用來開啟終端,進行終端的初始化,設定終端。

語  法:getty 

[-h][-d<組態配置檔案>][-r<延遲秒數>][-t<超時秒數>][-w<等待字串>][終端機編號][連線速率<終端機型別><管制線路>] 或 getty [-c<定義配置檔案>]

2. 關於rc.d所有啟動指令碼放置在 /etc/rc.d/init.d下rc?.d中放置的是init.d中指令碼的連結,命名格式是:S{number}{name}K{number}{name}S開始的檔案向指令碼傳遞start引數K開始的檔案向指令碼傳遞stop引數number決定執行的順序3. 啟動指令碼示例這是一個用來啟動httpd的 /etc/rc.d/init.d/apache 指令碼:程式碼:#!/bin/bash......可以看出他接受start,stop,restart,status引數然後可以這樣建立rc?.d的連結:程式碼:cd /etc/rc.d/init.d &&ln -sf ../init.d/apache ../rc0.d/K28apache &&ln -sf ../init.d/apache ../rc1.d/K28apache &&ln -sf ../init.d/apache ../rc2.d/K28apache &&ln -sf ../init.d/apache ../rc3.d/S32apache &&ln -sf ../init.d/apache ../rc4.d/S32apache &&ln -sf ../init.d/apache ../rc5.d/S32apache &&ln -sf ../init.d/apache ../rc6.d/K28apache4. 關於rc.local經常使用的 rc.local 則完全是習慣問題,不是標準。各個發行版有不同的實現方法,可以這樣實現:程式碼:touch /etc/rc.d/rc.localchmod +x /etc/rc.d/rc.localln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local5. 關於bash啟動指令碼/etc/profile/etc/bashrc~/.bash_profile~/.bashrc是bash的啟動指令碼一般用來設定單使用者的啟動環境,也可以實現開機單使用者的程式,但要明確他們都是屬於bash範疇而不是系統範疇。他們的具體作用介紹如下:/bin/bash這個命令解釋程式(後面簡稱shell)使用了一系列啟動檔案來建立一個執行環境:/etc/profile/etc/bashrc~/.bash_profile~/.bashrc~/.bash_logout每一個檔案都有特殊的功用並對登陸和互動環境有不同的影響。/etc/profile 和 ~/.bash_profile 是在啟動一個互動登陸shell的時候被呼叫。/etc/bashrc 和 ~/.bashrc 是在一個互動的非登陸shell啟動的時候被呼叫。~/.bash_logout 在使用者登出登陸的時候被讀取一個互動的登陸shell會在 /bin/login 成功登陸之後執行。一個互動的非登陸shell是通過命令列來執行的,如[prompt]$/bin/bash。一般一個非互動的shell出現在執行 shell指令碼的時候。之所以叫非互動的shell,是因為它不在命令列上等待輸入而只是執行指令碼程式。6. 關於開機程式的自動啟動系統指令碼可以放置在/etc/rc.d/init.d中並建立/etc/rc.d/rc?.d連結,也可以直接放置在/etc/rc.d/rc.local中。init.d指令碼包含完整的start,stop,status,reload等引數,是標準做法,推薦使用。為特定使用者使用的程式(如有的使用者需要使用中文輸入法而有的不需要)放置在~/中的bash啟動指令碼中。========================================================================設定系統自動啟動在/etc/init.d/下建立smsafe檔案內容:#!/bin/bash# chkconfig: 35 95 1# description: script to start/stop smsafecase $1 instart)sh /opt/startsms.sh;;stop)sh /opt/stopsms.sh;;*)echo "Usage: $0 (start|stop)";;esac更改許可權# chmod 775 smsafe加入自動啟動# chkconfig –add smsafe檢視自動啟動設定# chkconfig –list smsafesmsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off以後可以用以下命令啟動和停止指令碼# service smsafe start 啟動# service smsafe stop 停止