1.init.d簡介
init.d腳本是用來啓動一些系統服務或者自己定義的程序的一個腳本。這些腳本可以在系統啓動的時候執行。一個簡單init.d腳本例子,在/etc/init.d/文件中新建/etc/init.d/example文件,輸入:
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=10
STOP=15
start() {
echo start
# commands to launch application
}
stop() {
echo stop
# commands to kill application
}
一個默認init.d腳本會有一下幾個方法
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if that fails)
enable Enable service autostart
disable Disable service autostart
我們可以通過 /etc/init.d/example start 來啓動start()命令。
會輸出:
start
我們可以通過 /etc/init.d/example restart 來啓動restart()命令。
會輸出:
stop
start