在裏以python腳本爲例
#vim /etc/init/open-status.conf
其中open-status.conf中的內容即爲我們要編輯的,在後續啓動中也會用到(open-status),如start open-status其實就是調用了open-status.conf的配置。
內容如下:
description "Listen to the status information of the open*** and connect to the database to write data"
author "[email protected]"
start on runlevel [234]
stop on runlevel [0156]
chdir /opt/script/open***/python
exec /opt/script/open***/python/open-status.py
respawn
需要重新載入:
# initctl reload-configuration
注意:
以上的路徑必須存在且腳本要有可執行權限
#start open-status
即可啓動我們腳本
查看我們守護進程:
#ps -ef | grep open
root@Open***:~# ps -ef | grep open
open*** 3397 1 0 Aug28 ? 00:21:00 /usr/sbin/open*** --writepid /run/open***/server.pid --daemon o***-server --cd /etc/open*** --config /etc/open***/server.conf --script-security 2