[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [bug] Restarting Daemons on package install/upgrade.



On Thu, 23 Dec 1999, Wichert Akkerman wrote:

> >   Do we have a generic way to test whether a daemon is enabled for
> > a given runlevel?  That is -- one that works with filerc as well
> > as sysvinit?

> Not yet. At some point debconf will provide that information.

I don't see, how debconf can remember what servers are running in the
_actual_ runlevel (which may differ from the default run level and may
change from time to time).

A more generic way is the start-rc.d script written by Ingo Saitz
<ingo@stud.uni-hannover.de> and adapted to file-rc by me.  This script
should be packaged near update-rc.d in dpkg (diverted by file-rc).
You run this script with the <daemon> from /etc/init.d/<daemon> as a
parameter and it starts this daemon with only if it should be active
in the actual run level.

I'll attach the two scripts to this message.

But I fear, that we have to change the policy before we can use these
scripts...

Ciao

        Roland

-- 
 * roland@spinnaker.de * http://www.spinnaker.de/ *
#!/bin/sh
#
# start-rc.d	Start the initscript if it shold run in this runlevel
#
# Version:	1.0  06-Oct-1999  ingo@stud.uni-hannover.de
#
# Usage:	start-rc.d <daemon>
# Depends:	sysvinit
#
# Copyright (C) 1999 Ingo Saitz <ingo@stud.uni-hannover.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License.
#

# Which initskript to start?
daemon=$1

# The current runlevel is the second field in the output of the runlevel
# command.
runlevel=`runlevel | cut -d\  -f2`

# Test if there exists a startup-link for the current runlevel
if test -e /etc/rc${runlevel}.d/S??${daemon}; then

    # Execute the initskript
    /etc/init.d/${daemon} start
fi
#! /bin/sh
#
# $Id: start-rc.d,v 1.3 1999/10/06 23:02:55 roland Exp $
#
# Usage: start-rc.d <daemon>
#
# Starts <daemon> if this daemon is active in the actual runlevel
# or started in "rcS" according to runlevel.conf.
#
# This script was written by Roland Rosenfeld <roland@spinnaker.de>,
# it is based on an idea of Ingo Saitz <ingo@stud.uni-hannover.de> and
# some code from the other file-rc scripts (update-rc.d, rc, rcS).
#
##########################################################################
#
#   Copyright (C) 1999  Roland Rosenfeld <roland@spinnaker.de>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation; either version 2 of
#   the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
##########################################################################

basename=$1

# Get the actual runlevel using runlevel(8). This command outputs the
# previous runlevel and the actual runlevel. We only use the latter.
runlevel=`runlevel`
runlevel=${runlevel##* }

CFGFILE=/etc/runlevel.conf

element() {
    local element list IFS

    element="$1"
        
    [ "$2" = "in" ] && shift
    list="$2"
    [ "$list" = "-" ] && return 1
    [ "$list" = "*" ] && return 0

    IFS=","
    set -- $list
    case $element in
        "$1" | "$2" | "$3" | "$4" | "$5" | "$6" | "$7" | "$8" | "$9")
            return 0
    esac
    return 1
}


while read LINE
do
    case $LINE in
	\#*|"") continue
    esac

    set -- $LINE
    SORT_NO="$1"; STOP="$2"; START="$3"; CMD="$4"

    [ "$CMD" = "/etc/init.d/$basename" ] || continue

    if element "$runlevel" in "$START" || element "S" in "$START"
    then
	/etc/init.d/$basename start
	exit 0
    fi
done < $CFGFILE

Reply to: