ubuntu16 自定義開機服務

2021-09-28 18:34:08 字數 2509 閱讀 1116

首先說一下那些更改/etc/init.d下檔案的那些部落格,要麼就是我學藝不精,要麼就是你們胡編亂造,要麼就是你們忙著謄抄的時候**遺漏了,反正我是試了好多次,沒成功,果斷放棄了。

蒐集了一些靠譜的資料,下面是我的步驟:

1.進入路徑:

cd /etc/systemd/system
這裡面都是systemctl控制的服務

2.編寫自己的服務,名字自定義,我這裡是jxkq.service,後面帶個.service:

[unit]

description=jiaxunkaoqin service

after=syslog.target network.target

[service]

execstart=/usr/local/kaoqin/kaoqin.sh

execreload=/bin/kill -s hup $mainpid

execstop=/bin/kill -s quit $mainpid

privatetmp=true

[install]

wantedby=multi-user.target

description:服務描述,不重要,隨便寫,就是乙個簡短的服務陳述,服務主要看檔名jxkq.service

execstart:此服務啟動時開啟的指令碼或者命令

execstop:此服務停止時開啟的指令碼或者命令

其它的都是預設的。

3./usr/local/kaoqin/kaoqin.sh:

#!/bin/bash

bin=my_interactive_face_detection_demo

source /opt/intel/computer_vision_sdk/bin/setupvars.sh

source /opt/intel/computer_vision_sdk/bin/setupenv.sh

while [ 1 ]

do then

procid=`pgrep $`

if [ "" == "$procid" ]

then

cd / #防止程式路徑不存在導致切換路徑失敗,遞迴呼叫當前或者未知路徑下的同名指令碼

./$ -m_ag $ag32 -m_em $em32

fielse

exit 0

fisleep 10

done

這個指令碼是乙個守護程序,用來監視可執行程式my_interactive_face_detection_demo是否異常關閉,若關閉則重啟

這裡特別需要注意的是:系統服務預設都是root下啟動的,所以要執行特定的程式時需要注意環境變數的設定,這裡兩句source語句都是設定環境變數的。

4.手動啟動服務:

sudo systemctl start jxkq
檢視狀態:

systemctl status jxkq
關閉服務:

systemctl stop jxkq
重啟服務:

systemctl restart jxkq
開機自啟動服務:

sudo systemctl enable jxkq
示例:

systemctl status jxkq

● jxkq.service - jiaxunkaoqin service

loaded: loaded (/etc/systemd/system/jxkq.service; enabled; vendor preset: enabled)

active: active (running) since 五 2019-10-18 14:50:55 cst; 19s ago

process: 29751 execstop=/bin/kill -s quit $mainpid (code=exited, status=0/success)

main pid: 29770 (kaoqin.sh)

tasks: 52

memory: 71.1m

cpu: 33.018s

cgroup: /system.slice/jxkq.service

├─29770 /bin/bash /usr/local/kaoqin/kaoqin.sh

└─29808 ./my_interactive_face_detection_demo -m_ag /opt/intel//computer_vision_sdk_2018.5.445/deployment_tools/inference_engine/share/../../intel_models/age-gender-recognition-retail-0013/fp32/age

重新啟動電腦後,服務會自動開機執行,sh指令碼也會開機執行,相應的程式就會被開啟。至此自定義服務完畢。

ubuntu16啟用daytime服務

1.安裝xinted 先用cat etc services grep daytime 看一下是否有daytime服務,如果沒有的話需要安裝xinted 因為daytime服務包含在xinetd服務中。直接輸入命令 sudo apt get install xinetd 2.修改配置檔案 修改xine...

angularjs1 6,自定義服務

無標題文件 title script src angular.min.js script head 當你初試angular 時,很自然地就會往controller 和scope 裡堆滿不必要的邏輯。一定要早點意識到,controller 這一層應該很薄 也就是說,應用裡大部分的業務邏輯和持久化資料都...

自定義shell指令碼服務開機自啟動

需求 啟動linux是需要新增自定義ip位址到eth0網絡卡 在 etc rc.d init.d目錄下編輯auto run文字 bin bash add ip eth0 ip addr add 10.8.2.1 32 dev eth0 新增auto run服務 chkconfig add auto ...