Daemon status with init scripts

If none of the more specific forums is the right place to ask

Daemon status with init scripts

Postby mamars » 2006-01-09 23:02

Hi Debians,

I am new to GNU/Debian Linux and just setup my first system. However I was wondering why the initscripts in /etc/init.d/ just don't have a status arg like SuSE. Gentoo, which I also had a look at, has also a very nice feature where you can check with one command what service is running and which are unused. Does anybody know a good solution?
Greets

mamars
User avatar
mamars
 
Posts: 4
Joined: 2005-11-21 18:46
Location: Germany

Postby epostma » 2006-01-10 08:48

I can't really give you a prefab solution, but the following two (more or less obvious) procedures give you some information:

1) Just look at
Code: Select all
ps -ef

or if you want to know if sshd is up in a script, do something like
Code: Select all
if ps -e | egrep 'ssh+d' > /dev/null ; then ... fi

(the plus is in there to prevent the (e)grep command itself from showing up).

2) Look at the files in /var/run. E.g.:
Code: Select all
 $ cat /var/run/sshd.pid
3493
 $ cat /proc/3493/cmdline
/usr/sbin/sshd


HTH,
epostma
 
Posts: 67
Joined: 2006-01-06 13:58

Postby mamars » 2006-01-12 11:50

Thank you for your suggestion.
However, I think, that Debian is not prepared for such a feature, because you need at least two thinks, as far as I can assess this.

    1. A "status case" in the init scripts
    2. A universal script which handles "nice" output


I had a look at a SuSE system. My former Gentoo system was cleaned for Debian so I don't know how they handle this.

SuSE uses rc{service} which are sym.linked to /etc/init.d/{service}
Postfix for example looks like this:

Code: Select all
# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running


Look for the executables
Code: Select all
MASTER_BIN=/usr/lib/postfix/master
POSTFIX_BIN=/usr/sbin/postfix
test -x $POSTFIX_BIN || exit 5
test -x $MASTER_BIN || exit 5


Then they use startproc, killproc and checkproc for start, stop, status cases.

The "Starting postfix .... " is done in this file, the result however is done by the rc.status script which is sourced.

Here is just an extract of the rc.status:
Code: Select all
# check whether splash screen animations are installed.
_rc_splash=0
test -f /etc/sysconfig/bootsplash && . /etc/sysconfig/bootsplash
test -x /sbin/splash && _rc_splash=1

if test -z "$LINES" -o -z "$COLUMNS" ; then
    eval `stty size 2>/dev/null | (read L C; \
          echo LINES=${L:-24} COLUMNS=${C:-80})`
fi
test $LINES   -eq 0 && LINES=24
test $COLUMNS -eq 0 && COLUMNS=80
export LINES COLUMNS

if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb" && stty size > /dev/null 2>&1 ; then
         esc=`echo -en "\033"`
        extd="${esc}[1m"
        warn="${esc}[1;31m"
        done="${esc}[1;32m"
        attn="${esc}[1;33m"
        norm=`echo -en "${esc}[m\017"`
        stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`

     rc_done="${stat}${done}done${norm}"
  rc_running="${stat}${done}running${norm}"
   rc_failed="${stat}${warn}failed${norm}"
   rc_missed="${stat}${warn}missing${norm}"
  rc_skipped="${stat}${attn}skipped${norm}"
     rc_dead="${stat}${warn}dead${norm}"
   rc_unused="${stat}${extd}unused${norm}"
  rc_unknown="${stat}${attn}unknown${norm}"
  rc_done_up="${esc}[1A${rc_done}"
rc_failed_up="${esc}[1A${rc_failed}"
    rc_reset="${norm}"
     rc_save="${esc}7"
  rc_restore="${esc}8"
    function rc_cuu () { echo -en "\033[${1}A"; }
    function rc_timer_on () {


It's really a pity that Debian lacks these functions :( .

so long
mamars
User avatar
mamars
 
Posts: 4
Joined: 2005-11-21 18:46
Location: Germany

Postby epostma » 2006-01-16 14:25

Hi again,

Actually, the rc.status file just contains the functions used to print out the pieces "... done" and such. I think you want to look at (for e.g. postfix, to stay with the same example) for the part where it says something like:
Code: Select all
case $1 in

Then there's a section for all the possible arguments, including one that starts like this:
Code: Select all
status)

The code after that is executed if you run
Code: Select all
/etc/init.d/postfix status

Now I don't have a SuSE system at hand here, so I can't give you the line numbers or something, and it might even be that a couple of scripts do things differently. But this is usually the general structure.

The equivalent of startproc and killproc in Debian is called start-stop-daemon, by the way. As we already discussed, there's no equivalent to checkproc (which is what you'd want).

HTH,
epostma
 
Posts: 67
Joined: 2006-01-06 13:58


Return to General Questions

Who is online

Users browsing this forum: No registered users and 10 guests

fashionable