From: Adam Dickmeiss Date: Mon, 18 Mar 2013 13:50:04 +0000 (+0100) Subject: Deb: idzebra-2.0-utils includes init.d script X-Git-Tag: v2.0.55~15 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=1d5d4f08cb84516d75fcb5e6ed4199b6454cccd6 Deb: idzebra-2.0-utils includes init.d script Includes logrotate as well. The zebrasrv init script listens on port 2100. At this time, zebra.cfg, is not part of the package. Administrator must install or modify $CONFIG to point to a working zebra.cfg. --- diff --git a/debian/idzebra-2.0-common.dirs b/debian/idzebra-2.0-common.dirs new file mode 100644 index 0000000..228ff9e --- /dev/null +++ b/debian/idzebra-2.0-common.dirs @@ -0,0 +1 @@ +etc/idzebra diff --git a/debian/idzebra-2.0-common.init b/debian/idzebra-2.0-common.init deleted file mode 100644 index 5a0dc02..0000000 --- a/debian/idzebra-2.0-common.init +++ /dev/null @@ -1,231 +0,0 @@ -#! /bin/sh -# Start and stop toolkit lite administered idzebra script for Debian. -# change runlevels using update-rc.d - -test -x /usr/bin/zebrasrv || exit 0 -test -x /usr/bin/zebraidx || exit 0 -test -f /etc/default/zebra || exit 0 -source /etc/default/zebra - -# Now sourced from /etc/default/zebra -ZEBRA_USER=zebra -ZEBRA_GROUP=zebra - -#ZEBRA_CONF_FILE=/etc/zebra.conf -#ZEBRA_LOG_DIR=/var/log/zebra -#ZEBRA_PID_DIR=/var/run/zebra -#ZEBRA_TMP_DIR=/var/tmp/zebra - -ZEBRA_DIRS="/home/marc/projects/alvis" -ZEBRA_INDEX_DIRS="data" - -# set socket connection method -#ZEBRA_SOCKET="tcp:@:210" -ZEBRA_SOCKET="unix:db/socket" - - -# define display message -display_ZEBRA_message(){ - echo "Usage:" - echo " As root:" - echo -n " /etc/init.d/zebra {start|stop|reload|force-reload|restart}" - echo " [/path/to/root/dir]" - echo " As root or $ZEBRA_USER:" - echo " /etc/init.d/zebra {index|reindex} [/path/to/root/dir [sub/dir] ]" -} - -# make sure we are root or $ZEBRA_USER -ZEBRA_CURR_USER=`whoami`; -if [ $ZEBRA_CURR_USER != $ZEBRA_USER -a $ZEBRA_CURR_USER != "root" ] ; then - display_ZEBRA_message ; - echo " Error: you are not root or $ZEBRA_USER"; - exit 1; -fi - - -# perform usual init.d daemon services -case "$1" in - start) - # make sure we are root - if [ `whoami` != root ]; then - display_ZEBRA_message ; - echo " Error: you are not root"; - exit 1; - fi - - # read zebra dir from command line - if [ $2 ] ; then - ZEBRA_DIRS=$2 - fi - - # loop through all entries defined in /etc/zebra.conf - for d in $ZEBRA_DIRS; do - echo -n "Starting zebra: " - echo -n "$d " ; - - if [ ! -f $d/db/zebra.cfg ] ; then - echo ""; - echo " Error: config file $d/db/zebra.cfg not found"; - continue; - fi - - if [ ! -f $d/db/lock/zebrasrv.pid ] ; then - start-stop-daemon --start --quiet --background --pidfile $d/db/lock/zebrasrv.pid --exec /usr/bin/zebrasrv -- -w $d -u $ZEBRA_USER -c db/zebra.cfg -l db/server.log $ZEBRA_SOCKET ; - - # check for running zebra not performed - #sleep 1 - #if [ -f $d/db/lock/zebrasrv.pid ] ; then - # echo -n "started " - #cat $d/db/lock/zebrasrv.pid - # echo -n " " - #else - # echo -n "error " - #fi - else - echo -n "already running " - fi - echo - done - #ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` - ;; - - stop) - # make sure we are root - if [ `whoami` != root ]; then - display_ZEBRA_message ; - echo " Error: you are not root"; - exit 1; - fi - - # read zebra dir from command line - if [ $2 ] ; then - ZEBRA_DIRS=$2 - fi - - # loop through all entries defined in /etc/zebra.conf - for d in $ZEBRA_DIRS; do - echo -n "Stopping zebra: " - echo -n "$d " ; - - if [ ! -f $d/db/zebra.cfg ] ; then - echo ""; - echo " Error: config file $d/db/zebra.cfg not found"; - continue; - fi - - if [ -f $d/db/lock/zebrasrv.pid ] ; then - start-stop-daemon --stop --quiet --oknodo --pidfile $d/db/lock/zebrasrv.pid ; - #sleep 1 - #if ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` ; then - # kill -9 `cat $d/db/lock/zebrasrv.pid` - # echo -n "-9 " - #fi - #if [ -f $d/db/lock/zebrasrv.pid ] && ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` ; then - # echo -n "error " - #else - # echo -n "stopped " - #fi - #if [ -f $d/db/lock/zebrasrv.pid ] ; then - #rm -f $d/db/lock/zebrasrv.pid - #echo -n "removed PID file" - #fi - else - echo -n "already dead " - fi - echo - done - #ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` - ;; - - restart|reload|force-reload) - # make sure we are root - if [ `whoami` != root ]; then - display_ZEBRA_message ; - echo " Error: you are not root"; - exit 1; - fi - - $0 stop $2 - #sleep 1 - $0 start $2 - ;; - - reindex|index) - # make sure that indexing is done as user $ZEBRA_USER - if test `whoami` != $ZEBRA_USER; then - su -s /bin/sh -c "$0 $*" $ZEBRA_USER - exit 0 - fi - - # read zebra dir from command line - if [ $2 ] ; then - ZEBRA_DIRS=$2 - fi - - for d in $ZEBRA_DIRS; do - # allow all scripts to be called with one specific entrie - # directory as third argument - - if [ ! -f $d/db/zebra.cfg ] ; then - echo -n "Indexing zebra: " - echo "$d " - echo " Error: config file $d/db/zebra.cfg not found"; - continue; - fi - - if [ $3 ] ; then - # only indexing one additionally directory - ZEBRA_INDEX_DIRS=$3; - if [ ! -d $d/$ZEBRA_INDEX_DIRS ] ; then - #$0 ; # trigger user info - echo " Error: there is no directory $3"; - echo " in zebra dir $d"; - echo " Can not index $d/$ZEBRA_INDEX_DIRS"; - exit 1; - fi - if ( echo $ZEBRA_INDEX_DIRS | grep "^/" ) ; then - #$0 ; # trigger user info - echo " Error: third argument $3"; - echo " must not contain leading slash"; - exit 1; - fi - - echo -n "Indexing zebra: " - echo -n "$d " - - (cd $d ; - # initalization and commiting db to get a fresh slate - for DIR in $ZEBRA_INDEX_DIRS ; do - echo -n "$DIR " - zebraidx -L -l db/index.log -c db/zebra.cfg update $DIR ; - done - zebraidx -l db/index.log -c db/zebra.cfg commit ; - ) - echo - else - # indexing a whole entrie - findZEBRA_INDEX_DIRD makes the work - # findZEBRA_INDEX_DIRS "$d" ; - echo -n "Indexing zebra: " - echo -n "$d " - (cd $d ; - # initalization and commiting db to get a fresh slate - zebraidx -l db/index.log -c db/zebra.cfg init ; - for DIR in $ZEBRA_INDEX_DIRS ; do - echo -n "$DIR " - zebraidx -L -l db/index.log -c db/zebra.cfg update $DIR ; - done - zebraidx -l db/index.log -c db/zebra.cfg commit ; - ) - echo - fi - done - ;; - - *) - display_ZEBRA_message ; - exit 1; -esac - -exit 0 - - diff --git a/debian/idzebra-2.0-utils.postinst b/debian/idzebra-2.0-utils.postinst index 84225c2..06378fb 100644 --- a/debian/idzebra-2.0-utils.postinst +++ b/debian/idzebra-2.0-utils.postinst @@ -14,3 +14,13 @@ update-alternatives --quiet --install /usr/bin/zebrasrv zebrasrv \ --slave /usr/share/man/man8/zebrasrv.8.gz zebrasrv.8.gz \ /usr/share/man/man8/zebrasrv-2.0.8.gz +if [ -x "/etc/init.d/zebrasrv" ]; then + update-rc.d zebrasrv defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d zebrasrv start || exit $? + else + /etc/init.d/zebrasrv start || exit $? + fi +fi + + diff --git a/debian/idzebra-2.0-utils.zebrasrv.default b/debian/idzebra-2.0-utils.zebrasrv.default new file mode 100644 index 0000000..686f879 --- /dev/null +++ b/debian/idzebra-2.0-utils.zebrasrv.default @@ -0,0 +1,15 @@ +# Defaults for zebrasrv initscript +# sourced by /etc/init.d/zebrasrv +# +# This is a POSIX shell fragment + +# Full path to zebra server +#DAEMON=/usr/sbin/zebrasrv-2.0 + +# Options that are passed to the Daemon. +#DAEMON_OPTS="-l /var/log/zebrasrv -u nobody tcp:@6:2100" +# Note that options -D, -c , -p are set automatically. Should NOT be set + +# zebra.cfg (will be supplied with option -c) +#CONFIG="/etc/idzebra/zebra.cfg" + diff --git a/debian/idzebra-2.0-utils.zebrasrv.init b/debian/idzebra-2.0-utils.zebrasrv.init new file mode 100644 index 0000000..1e78f85 --- /dev/null +++ b/debian/idzebra-2.0-utils.zebrasrv.init @@ -0,0 +1,159 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: zebrasrv +# Required-Start: $local_fs $remote_fs $network $named $time +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Controls the zebrasrv daemon +# Description: Controls the IDZebra server daemon +# /usr/bin/zebrasrv-2.0 . +### END INIT INFO + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +NAME=zebrasrv +DAEMON=/usr/bin/$NAME +DAEMON_OPTS="-l /var/log/zebrasrv.log -u nobody tcp:@6:2100" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +CONFIG=/etc/idzebra/zebra.cfg + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# If no CONFIG, bail out +[ -r $CONFIG ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + $DAEMON_OPTS -D -c $CONFIG -p $PIDFILE \ + || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + #[ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" = no ] && \ + log_daemon_msg "Starting $DESC" "$NAME" + log_end_msg 1 + ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" = no ] && \ + log_daemon_msg "Stopping $DESC" "$NAME" + log_end_msg 1 + ;; + esac + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/debian/idzebra-2.0-utils.zebrasrv.logrotate b/debian/idzebra-2.0-utils.zebrasrv.logrotate new file mode 100644 index 0000000..b94e255 --- /dev/null +++ b/debian/idzebra-2.0-utils.zebrasrv.logrotate @@ -0,0 +1,13 @@ +/var/log/zebrasrv.log { + weekly + missingok + rotate 4 + compress + delaycompress + notifempty + postrotate + if [ -f /var/run/zebrasrv.pid ]; then + /etc/init.d/zebrasrv force-reload > /dev/null + fi + endscript +} diff --git a/debian/rules b/debian/rules index e833251..907bf16 100755 --- a/debian/rules +++ b/debian/rules @@ -79,11 +79,11 @@ binary-arch: build install dh_install --sourcedir=debian/tmp # dh_installmenu # dh_installdebconf -# dh_installlogrotate + dh_installlogrotate --name=zebrasrv # dh_installemacsen # dh_installpam # dh_installmime -# dh_installinit + dh_installinit --name=zebrasrv # dh_installcron # dh_installinfo dh_installman