/etc/init.d/functions

/etc/init.d/functions:

[root@Management-Machine-140 ~]# vim /etc/init.d/functions  #僅展示前幾行
# -*-Shell-script-*-
#
# functions  This file contains functions to be used by most or all        #這個文件被/etc/init.d/下大多數的腳本調用,
#        shell scripts in the /etc/init.d directory.               #同時也被 /etc/rc.d/rc.sysinit ,例如 success、action、failure 等函數
#

TEXTDOMAIN=initscripts

# Make sure umask is sane
umask 022

# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH

# Get a sane screen width
[ -z "${COLUMNS:-}" ] && COLUMNS=80

主要功能:

 1 checkpid:檢查是否已存在pid,如果有一個存在,返回0(通過查看/proc目錄)

 2 daemon:啓動某個服務。/etc/init.d目錄部分腳本的start使用到這個

 3 killproc:殺死某個進程。/etc/init.d目錄部分腳本的stop使用到這個

 4 pidfileofproc:尋找某個進程的pid

 5 pidofproc:類似上面的,只是還查找了pidof命令

 6 status:返回一個服務的狀態

 7 echo_success,echo_failure,echo_passed,echo_warning分別輸出各類信息

 8 success,failure,passed,warning分別記錄日誌並調用相應的方法

 9 action:打印某個信息並執行給定的命令,它會根據命令執行的結果來調用 success,failure方法

10 strstr:判斷$1是否含有$2

11 confirm:顯示 "Start service $1 (Y)es/(N)o/(C)ontinue? [Y]"的提示信息,並返回選擇結果


實例:

執行shell腳本時報錯"action: command not found",原因是沒有加載此文件。

在腳本中加載此文件解決此問題


參考:https://www.cnblogs.com/sunfie/p/5149678.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章