給linux添加服務的步驟:
第一:編寫服務指令碼,命名為:testService
start(){ echo "start testService" /usr/local/bin/testService & #可執行檔路徑 exit 0;}stop(){ echo -n "stop testService" if pkill testService then echo " [ok]" else echo " [failed]" fi}case "$1" instart) start ;;stop) stop ;;restart) stop start ;;*) echo "usage: $0 start|stop|restart" exit 0;esac
第二:把檔案testService拷貝到/etc/init.d/目錄下面
第三:就可以執行service testService start (stop 、 restart)來操作檔案了。
但是今天遇到意見鬱悶的事,
第一:檢查檔案是否在/usr/init.d/目錄下面,檔案確確實實存在
第二:執行service testService start ,報錯,未識別的服務,
第三:檢查指令檔,是否正確,確確實實正確,執行其他服務都能執行
檢查了下/usr/init.d/testServic的許可權,如下:
[root@~]# service testService startuapd: 未被識別的服務[root@~]# ll /etc/init.d/testService #檢查許可權---------- 1 root root 1025 08-30 17:47 /etc/init.d/testService #檔案許可權[root@~]# [root@~]# chmod 033 /etc/init.d/testService #設定檔案許可權[root@~]# service uapd startstart testService [確定][root@~]#
解決:
1、先檢查了檔案的許可權,此時即使檔案在/etc/init.d/testService目錄下,仍然不能使用服務
2、設定了檔案許可權後,服務能夠正常識別了