Centos7 安裝系統服務、開機自啓動

 

Centos7 安裝系統服務

 

1 編寫可執行程序

* 這裏能夠是任意編程語言(C、C++、Java、PHP、Python、Perl ...)編寫的程序;編程

當前假設此程序的執行目錄爲:bash

 /myservice/bin

2 編寫服務腳本

#! /bin/bash

# chkconfig: 2345 80 90
# description: this is your auto run program.

start() {
echo "starting service ..."
cd /myservice/bin
./start.sh
echo "ok"
}

stop() {
echo "stop service ..."
cd /myservice/bin
./stop.sh
echo "ok"
}

case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
stop
start
;;
*)

echo $"Usage: $0 {start|stop|restart}"
exit 0
esac

請注意檢查腳本的前面,是否有完整的兩行編程語言

#chkconfig: 2345 80 90
#description: this is your auto run program.

3 添加到服務 & 開機啓動項

chkconfig --add myservice
chkconfig --level 2345 myservice on

 4 chkconfig 參考命令

chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name
相關文章
相關標籤/搜索