Redhat

需要有關自定義初始化腳本的幫助

  • February 9, 2012

我正在嘗試為 redhat linux 上的程序設置一個初始化腳本:

#!/bin/sh
#
# Startup script for Conquest
#
# chkconfig: 345 85 15     - start or stop process definition within the boot process
# description: Conquest DICOM Server
# processname: conquest
# pidfile: /var/run/conquest.pid

# Source function library.      This creates the operating environment for the process to be started
. /etc/rc.d/init.d/functions

CONQ_DIR=/usr/local/conquest

case "$1" in
 start)
       echo -n "Starting Conquest DICOM server: "
       cd $CONQ_DIR && daemon --user mruser ./dgate -v                 - Starts only one process of a given name.
       echo
       touch /var/lock/subsys/conquest
       ;;
 stop)
       echo -n "Shutting down Conquest DICOM server: "
       killproc conquest
       echo
       rm -f /var/lock/subsys/conquest
       rm -f /var/run/conquest.pid      - Only if process generates this file
       ;;
 status)
       status conquest
       ;;
 restart)
       $0 stop
       $0 start
       ;;
 reload)
       echo -n "Reloading process-name: "
       killproc conquest -HUP
       echo
       ;;
 *)
       echo "Usage: $0 {start|stop|restart|reload|status}"
       exit 1
esac

exit 0

但是,cd $CONQ_DIR由於腳本錯誤,因此被忽略了:

# ./conquest start
Starting Conquest DICOM server: -bash: ./dgate: No such file or directory
                                                          [FAILED]

出於某種原因,我必須將 dgate 作為 ./dgate 執行。我無法指定完整路徑/usr/local/conquest/dgate

該軟體帶有一個用於 Debian 系統的初始化腳本,因此該腳本使用start-stop-daemon, 並帶有--chdirdgate 所在位置的選項,但我還沒有找到使用 Redhat 守護程序功能執行此操作的方法。

為什麼不只是:

daemon --user mruser ${CONQ_DIR}/dgate -v

?

編輯:

cd ${CONQ_DIR} && daemon --user mruser ./dgate -v &

set -x舊問題仍然很舊:您可以使用腳本頂部的 (xtrace)來解決此類問題。另外,請考慮set -e,因此腳本會儘早出錯。

引用自:https://serverfault.com/questions/130062