chkconfig 管理服務需 init 腳本包含特定註釋標籤,缺失則報錯。
vi /etc/init.d/mysql3306#!/bin/sh 之後、任何命令之前加入:
# chkconfig: 2345 10 90
# description: MySQL 3306 instance
2345:啟動運行級(2=多用戶無網、3=多用戶有網、4=保留、5=圖形界面)。10:啟動優先級(0-100,數字越小越早啟動)。90:停止優先級(數字越大越晚停止)。chkconfig --add mysql3306
chkconfig --level 2345 mysql3306 on
service mysql3306 start
| 級別 | 名稱 | 描述 |
|---|---|---|
| 0 | Halt | 關機 |
| 1 | Single User | 單用戶維護模式 |
| 2 | Multi-user No Network | 無網絡多用戶命令行 |
| 3 | Multi-user Network | 有網絡多用戶命令行(伺服器常用) |
| 4 | Unused | 保留 |
| 5 | Graphical | 圖形界面多用戶 |
| 6 | Reboot | 重啟 |
#!/bin/bash
# chkconfig: 2345 80 20
# description: Custom Service Description
# processname: custom_daemon
# config: /etc/custom.conf
# pidfile: /var/run/custom.pid
start() { ... }
stop() { ... }
case "$1" in
start) start ;;
stop) stop ;;
restart) stop; start ;;
status) status custom_daemon ;;
*) echo "Usage: $0 {start|stop|restart|status}"; exit 1 ;;
esac