方法一,
編輯 /etc/rc.d/rc.local檔案
格式為 程式名 程式路徑
例如 a.sh /home/a.sh
第二種方法
只需要將your_prog_name替換為你真正的指令碼或執行檔案的名稱,將prog_path設定為具體的路徑即可。
代碼如下 |
複製代碼 |
# vim /etc/init.d/your_prog_name #!/bin/bash # # Comments to support chkconfig # chkconfig: - 98 02 # description: your_prog_name service script # # Source function library. . /etc/init.d/functions ### Default variables prog_name="your_prog_name" prog_path="/usr/bin/${prog_name}" pidfile="/var/run/${prog_name}.pid" options="-c your_conf_file" # Check if requirements are met [ -x "${prog_path}" ] || exit 1 RETVAL=0 start(){ echo -n $"Starting $prog_name: " daemon $prog_path $options RETVAL=$? PID=$(pidof ${prog_path}) [ ! -z "${PID}" ] && echo ${PID} > ${pidfile} echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name return $RETVAL } stop(){ echo -n $"Shutting down $prog_name: " killproc -p ${pidfile} RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name return $RETVAL } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status $prog_path RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|status}" RETVAL=1 esac exit $RETVAL # chmod +x /etc/init.d/your_prog_name # chkconfig your_prog_name on |