Daemon

為什麼守護程序不執行

  • September 8, 2012

我的守護程序曾經在 10.04 下執行,但在 12.04 上不再自動啟動。如果我手動啟動它

/etc/init.d/sqlexecd 啟動,它可以工作。

這是 uname -a 的輸出

Linux steamboy 3.2.0-30-generic-pae 
#48-Ubuntu SMP Fri Aug 24 17:14:09 UTC 2012 i686 i686 i386 GNU/Linux

這是 chkconfig -l sqlexecd 的輸出

sqlexecd                  0:off  1:off  2:on   3:on   4:on   5:on   6:off

這是守護程序。我很清楚它不會停止。

#! /bin/bash
#
# informix - Script to start/stop the Informix database servitron.
#
# Revision History:
# ewilde      2004Mar23  Initial coding.
#
# chkconfig: 2345 12 78
# description: Informix SQL database server.
# processname: sqlexecd
# config: /usr/share/informix/etc/sqlhosts
# pidfile: /var/run/informix/sqlexecd.pid

# Source function library.
#/etc/init.d/functions
# LSB compliance (kinda)
if [ -f /lib/lsb/init-functions ]; then
   . /lib/lsb/init-functions;
else
   log_begin_msg()   { echo "$@"; };
   log_success_msg() { echo "$@"; };
   log_warning_msg() { echo "$@"; };
   fi;

# Source networking configuration.
#. /etc/network

# Information about what and where we're running.
prog="Informix"
export INFORMIXDIR="/usr/share/informix"
lockfile="/var/lock/sqlexecd"
logfile="/var/log/sqlexecd.log"
process="sqlexecd"
service="steamboy"
owner="informix"


# Start up Informix.
start()
{
# Set up the logfile.
touch ${logfile}
chown ${owner}.${owner} ${logfile}
chmod 0664 ${logfile}

# Start the servitron.
${INFORMIXDIR}/lib/${process} ${service} -l ${logfile} >/dev/null 2>&1

# How'd that go?
ret=$?
if [ $ret -eq 0 ]; then
    echo $"Starting sqlexecd: " /bin/true
else
    echo $"Starting sqlexecd: " /bin/false
fi

# Locking, if necessary.
[ $ret -eq 0 ] && touch ${lockfile}
return $ret
}

# Stop Informix.
stop()
{

# If there's a lock file, try to find the PID.
if [ -f ${lockfile} ]; then
    SQLPID=`ps -eo pid,args | grep ${INFORMIXDIR} | grep ${process} | sed -n 's/^ *\([0-9]*\).*/\1/p'`
    if [ x"$SQLPID" != x ]; then

         # Kill the PID.
         kill -9 $SQLPID
         ret=$?

         # See how it went.
         if [ $ret -eq 0 ]; then
              action $"Stopping $prog: " /bin/true
         else
              action $"Stopping $prog: " /bin/false
         fi

         # Clean up the lock file.
         [ $ret -eq 0 ] && rm -f ${lockfile}
         return $ret
    fi
fi

# Not running.
return 0
}

# Restart Informix.
restart()
{
stop
start
}

# Conditional restart of Informix.
condrestart()
{
[ -e ${lockfile} ] && restart || :
}

# See how we were called.
case "${1}" in
    start)
         start
         ;;
    stop)
         stop
         ;;
    status)
     ps -ef | grep sqlexecd
         #status ${process}
         ;;
    restart)
         restart
         ;;
    condrestart)
         condrestart
         ;;
    *)
         echo $"Usage: $0 {start|stop|status|condrestart|restart}"
         exit 1
esac

exit $?

這是日誌中的錯誤。但是,手動啟動後啟動時不會發生此錯誤。

2012-09-08 12:28:19.475867 Starting Daemon INFORMIX-SQL Version 7.25.UC6R1 
Command Line = /usr/share/informix/lib/sqlexecd steamboy -l /var/log/sqlexecd.log
INFORMIXDIR  = /usr/share/informix
dbservername = steamboy
nettype      = sesoctcp
hostname     = steamboy
servicename  = informix
options      = # Well-known Informix TCP port
2012-09-08 12:28:19.478349 daemon err = -25572: Network driver cannot bind a name to the port.
System error = 99.
root@steamboy:/var/log#

我還應該配置什麼使其自動啟動?

謝謝。

編輯:

這似乎是一個服務執行順序依賴問題,我已經將它添加到我的守護程序中,包括 #!/bin/bash 之後的 -e

#!/bin/bash -e
### BEGIN INIT INFO
# Provides:          sqlexecd
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     3 5
# Default-Stop:      1 
# Short-Description: Simple script to run Informix SE daemon.
### END INIT INFO
#

這些更改都不會改變原始錯誤。

這是根據要求的網路守護程序:

#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          networking
# Required-Start:
# Required-Stop:     $local_fs
# Should-Start:      ifupdown
# Should-Stop:       ifupdown
# Default-Start:
# Default-Stop:      0 6
# Short-Description: Raise network interfaces.
### END INIT INFO

PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

[ -x /sbin/ifup ] || exit 0

. /lib/lsb/init-functions

# helper function to set the usplash timeout. https://launchpad.net/bugs/21617
usplash_timeout () {
   TIMEOUT=$1
   if [ -x /sbin/usplash_write ]; then
       /sbin/usplash_write "TIMEOUT $TIMEOUT" || true
   fi
}

process_options() {
   [ -e /etc/network/options ] || return 0
   log_warning_msg "/etc/network/options still exists and it will be IGNORED! Read README.Debian of netbase."
}

check_network_file_systems() {
   [ -e /proc/mounts ] || return 0

   if [ -e /etc/iscsi/iscsi.initramfs ]; then
   log_warning_msg "not deconfiguring network interfaces: iSCSI root is mounted."
   exit 0
   fi

   exec 9<&0 < /proc/mounts
   while read DEV MTPT FSTYPE REST; do
   case $DEV in
   /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
       log_warning_msg "not deconfiguring network interfaces: network devices still mounted."
       exit 0
       ;;
   esac
   case $FSTYPE in
   nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
       log_warning_msg "not deconfiguring network interfaces: network file systems still mounted."
       exit 0
       ;;
   esac
   done
   exec 0<&9 9<&-
}

check_network_swap() {
   [ -e /proc/swaps ] || return 0

   exec 9<&0 < /proc/swaps
   while read DEV MTPT FSTYPE REST; do
   case $DEV in
   /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
       log_warning_msg "not deconfiguring network interfaces: network swap still mounted."
       exit 0
       ;;
   esac
   done
   exec 0<&9 9<&-
}

case "$1" in
start)
   /lib/init/upstart-job networking start
   ;;

stop)
   check_network_file_systems
   check_network_swap

   # Anything that manages network interfaces *MUST* wait for this event
   initctl emit deconfiguring-networking

   log_action_begin_msg "Deconfiguring network interfaces"
   if [ "$VERBOSE" != no ]; then
       if ifdown -a --exclude=lo; then
       log_action_end_msg $?
       else
       log_action_end_msg $?
       fi
   else
       if ifdown -a --exclude=lo >/dev/null 2>/dev/null; then
       log_action_end_msg $?
       else
       log_action_end_msg $?
       fi
   fi
   ;;

force-reload|restart)
   process_options

   log_warning_msg "Running $0 $1 is deprecated because it may not enable again some interfaces"
   log_action_begin_msg "Reconfiguring network interfaces"
   ifdown -a --exclude=lo || true
   if ifup -a --exclude=lo; then
       log_action_end_msg $?
   else
       log_action_end_msg $?
   fi
   ;;

*)
   echo "Usage: /etc/init.d/networking {start|stop}"
   exit 1
   ;;
esac

exit 0
Network driver cannot bind a name to the port.

我對 Informix 不熟悉,但我懷疑它只能在網路服務啟動後才能啟動。由於您使用的是 Red Hat 風格的初始化腳本,因此無法確保這一點。

僅更改lsb 標頭是不夠的。將整個sqlexecd腳本更改為 Debian 樣式,然後重試。

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