r83996 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83995‎ | r83996 | r83997 >
Date:04:29, 15 March 2011
Author:tstarling
Status:deferred (Comments)
Tags:
Comment:
Initial debianization. The init and preinst scripts are untested at this stage.
Modified paths:
  • /trunk/extensions/PoolCounter/daemon/Makefile (modified) (history)
  • /trunk/extensions/PoolCounter/daemon/debian (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/changelog (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/compat (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/control (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/copyright (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/poolcounter.init (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/preinst (added) (history)
  • /trunk/extensions/PoolCounter/daemon/debian/rules (added) (history)

Diff [purge]

Index: trunk/extensions/PoolCounter/daemon/debian/control
@@ -0,0 +1,14 @@
 2+Source: poolcounter
 3+Section: web
 4+Priority: extra
 5+Maintainer: Tim Starling <tstarling@wikimedia.org>
 6+Build-Depends: debhelper (>= 7), libevent-dev, build-essential
 7+Standards-Version: 3.8.3
 8+
 9+Package: poolcounter
 10+Architecture: any
 11+Depends: ${shlibs:Depends}, ${misc:Depends}
 12+Description: Network resource manager by Platonides for Wikimedia.
 13+ Manages a network-wide maximum process count in a computing cluster,
 14+ such as a web server cluster. A client is available for MediaWiki,
 15+ which limits resources dedicated to parsing a given article.
Index: trunk/extensions/PoolCounter/daemon/debian/compat
@@ -0,0 +1 @@
 2+7
Index: trunk/extensions/PoolCounter/daemon/debian/preinst
@@ -0,0 +1,33 @@
 2+#!/bin/sh
 3+
 4+# Borrowed from MySQL, not sure if that's where it came from originally -- TS
 5+
 6+# If we use NIS then errors should be tolerated. It's up to the
 7+# user to ensure that the poolcounter user is correctly setup.
 8+# Beware that there are two ypwhich one of them needs the 2>/dev/null!
 9+if test -n "`which ypwhich 2>/dev/null`" && ypwhich >/dev/null 2>&1; then
 10+ set +e
 11+fi
 12+
 13+# creating poolcounter group if he isn't already there
 14+if ! getent group poolcounter >/dev/null; then
 15+ # Adding system group: poolcounter.
 16+ addgroup --system poolcounter >/dev/null
 17+fi
 18+
 19+# creating poolcounter user if he isn't already there
 20+if ! getent passwd poolcounter >/dev/null; then
 21+ # Adding system user: poolcounter.
 22+ adduser \
 23+ --system \
 24+ --disabled-login \
 25+ --ingroup poolcounter \
 26+ --home / \
 27+ --gecos "PoolCounter" \
 28+ --shell /bin/false \
 29+ poolcounter >/dev/null
 30+fi
 31+
 32+# end of NIS tolerance zone
 33+set -e
 34+
Index: trunk/extensions/PoolCounter/daemon/debian/changelog
@@ -0,0 +1,5 @@
 2+poolcounter (1.0.0) unstable; urgency=low
 3+
 4+ * Initial debianization.
 5+
 6+ -- Tim Starling <tstarling@wikimedia.org> Tue, 15 Mar 2011 14:30:52 +1100
Index: trunk/extensions/PoolCounter/daemon/debian/copyright
@@ -0,0 +1,35 @@
 2+This work was packaged for Debian by:
 3+
 4+ Tim Starling <tstarling@wikimedia.org> on Tue, 15 Mar 2011 14:30:52 +1100
 5+
 6+It was downloaded from:
 7+
 8+ http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/PoolCounter/daemon
 9+
 10+Upstream Author(s):
 11+
 12+ Platonides
 13+
 14+License:
 15+
 16+ This program is free software: you can redistribute it and/or modify
 17+ it under the terms of the GNU General Public License as published by
 18+ the Free Software Foundation, either version 3 of the License, or
 19+ (at your option) any later version.
 20+
 21+ This package is distributed in the hope that it will be useful,
 22+ but WITHOUT ANY WARRANTY; without even the implied warranty of
 23+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 24+ GNU General Public License for more details.
 25+
 26+ You should have received a copy of the GNU General Public License
 27+ along with this program. If not, see <http://www.gnu.org/licenses/>.
 28+
 29+On Debian systems, the complete text of the GNU General
 30+Public License version 3 can be found in `/usr/share/common-licenses/GPL-3'.
 31+
 32+The Debian packaging is:
 33+
 34+ Copyright (C) 2011 Tim Starling <tstarling@wikimedia.org>
 35+
 36+and is licensed under the GPL version 3, see above.
Index: trunk/extensions/PoolCounter/daemon/debian/rules
@@ -0,0 +1,9 @@
 2+#!/usr/bin/make -f
 3+
 4+# Uncomment this to turn on verbose mode.
 5+#export DH_VERBOSE=1
 6+
 7+%:
 8+ dh $@
 9+
 10+override_dh_auto_configure:
Property changes on: trunk/extensions/PoolCounter/daemon/debian/rules
___________________________________________________________________
Added: svn:executable
111 + *
Index: trunk/extensions/PoolCounter/daemon/debian/poolcounter.init
@@ -0,0 +1,282 @@
 2+#!/bin/sh
 3+# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
 4+#
 5+# This is free software; you may redistribute it and/or modify
 6+# it under the terms of the GNU General Public License as
 7+# published by the Free Software Foundation; either version 2,
 8+# or (at your option) any later version.
 9+#
 10+# This is distributed in the hope that it will be useful, but
 11+# WITHOUT ANY WARRANTY; without even the implied warranty of
 12+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13+# GNU General Public License for more details.
 14+#
 15+# You should have received a copy of the GNU General Public License with
 16+# the Debian operating system, in /usr/share/common-licenses/GPL; if
 17+# not, write to the Free Software Foundation, Inc., 59 Temple Place,
 18+# Suite 330, Boston, MA 02111-1307 USA
 19+#
 20+### BEGIN INIT INFO
 21+# Provides: poolcounter
 22+# Required-Start: $network $local_fs
 23+# Required-Stop:
 24+# Should-Start: $named
 25+# Should-Stop:
 26+# Default-Start: 2 3 4 5
 27+# Default-Stop: 0 1 6
 28+# Short-Description: Wikimedia pool counter
 29+# Description: Wikimedia pool counter
 30+### END INIT INFO
 31+
 32+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 33+
 34+DAEMON=/usr/bin/poolcounterd # Introduce the server's location here
 35+NAME=poolcounter # Introduce the short server's name here
 36+DESC=poolcounter # Introduce a short description here
 37+LOGDIR=/var/log/poolcounter # Log directory to use
 38+
 39+PIDFILE=/var/run/$NAME.pid
 40+
 41+test -x $DAEMON || exit 0
 42+
 43+. /lib/lsb/init-functions
 44+
 45+# Default options, these can be overriden by the information
 46+# at /etc/default/$NAME
 47+DAEMON_OPTS="" # Additional options given to the server
 48+
 49+DIETIME=10 # Time to wait for the server to die, in seconds
 50+ # If this value is set too low you might not
 51+ # let some servers to die gracefully and
 52+ # 'restart' will not work
 53+
 54+#STARTTIME=2 # Time to wait for the server to start, in seconds
 55+ # If this value is set each time the server is
 56+ # started (on start or restart) the script will
 57+ # stall to try to determine if it is running
 58+ # If it is not set and the server takes time
 59+ # to setup a pid file the log message might
 60+ # be a false positive (says it did not start
 61+ # when it actually did)
 62+
 63+LOGFILE=$LOGDIR/$NAME.log # Server logfile
 64+DAEMONUSER=poolcounter # Users to run the daemons as. If this value
 65+ # is set start-stop-daemon will chuid the server
 66+
 67+# Include defaults if available
 68+if [ -f /etc/default/$NAME ] ; then
 69+ . /etc/default/$NAME
 70+fi
 71+
 72+# Use this if you want the user to explicitly set 'RUN' in
 73+# /etc/default/
 74+#if [ "x$RUN" != "xyes" ] ; then
 75+# log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
 76+# log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
 77+# exit 0
 78+#fi
 79+
 80+# Check that the user exists (if we set a user)
 81+# Does the user exist?
 82+if [ -n "$DAEMONUSER" ] ; then
 83+ if getent passwd | grep -q "^$DAEMONUSER:"; then
 84+ # Obtain the uid and gid
 85+ DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
 86+ DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
 87+ else
 88+ log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
 89+ exit 0
 90+ fi
 91+fi
 92+
 93+
 94+set -e
 95+
 96+running_pid() {
 97+# Check if a given process pid's cmdline matches a given name
 98+ pid=$1
 99+ name=$2
 100+ [ -z "$pid" ] && return 1
 101+ [ ! -d /proc/$pid ] && return 1
 102+ cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
 103+ # Is this the expected server
 104+ [ "$cmd" != "$name" ] && return 1
 105+ return 0
 106+}
 107+
 108+running() {
 109+# Check if the process is running looking at /proc
 110+# (works for all users)
 111+
 112+ # No pidfile, probably no daemon present
 113+ [ ! -f "$PIDFILE" ] && return 1
 114+ pid=`cat $PIDFILE`
 115+ running_pid $pid $DAEMON || return 1
 116+ return 0
 117+}
 118+
 119+start_server() {
 120+# Start the process using the wrapper
 121+ if [ -z "$DAEMONUSER" ] ; then
 122+ start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS
 123+ errcode=$?
 124+ else
 125+# if we are using a daemonuser then change the user id
 126+ start-stop-daemon --start --quiet --pidfile $PIDFILE \
 127+ --chuid $DAEMONUSER \
 128+ --exec $DAEMON -- $DAEMON_OPTS
 129+ errcode=$?
 130+ fi
 131+ return $errcode
 132+}
 133+
 134+stop_server() {
 135+# Stop the process using the wrapper
 136+ if [ -z "$DAEMONUSER" ] ; then
 137+ killproc -p $PIDFILE $DAEMON
 138+ errcode=$?
 139+ else
 140+# if we are using a daemonuser then look for process that match
 141+ start-stop-daemon --stop --quiet --pidfile $PIDFILE \
 142+ --user $DAEMONUSER \
 143+ --exec $DAEMON
 144+ errcode=$?
 145+ fi
 146+
 147+ return $errcode
 148+}
 149+
 150+reload_server() {
 151+ [ ! -f "$PIDFILE" ] && return 1
 152+ pid=pidofproc $PIDFILE # This is the daemon's pid
 153+ # Send a SIGUSR1
 154+ kill -USR1 $pid
 155+ return $?
 156+}
 157+
 158+force_stop() {
 159+# Force the process to die killing it manually
 160+ [ ! -e "$PIDFILE" ] && return
 161+ if running ; then
 162+ kill -15 $pid
 163+ # Is it really dead?
 164+ sleep "$DIETIME"s
 165+ if running ; then
 166+ kill -9 $pid
 167+ sleep "$DIETIME"s
 168+ if running ; then
 169+ echo "Cannot kill $NAME (pid=$pid)!"
 170+ exit 0
 171+ fi
 172+ fi
 173+ fi
 174+ rm -f $PIDFILE
 175+}
 176+
 177+
 178+case "$1" in
 179+ start)
 180+ log_daemon_msg "Starting $DESC " "$NAME"
 181+ # Check if it's running first
 182+ if running ; then
 183+ log_progress_msg "apparently already running"
 184+ log_end_msg 0
 185+ exit 0
 186+ fi
 187+ if start_server ; then
 188+ # NOTE: Some servers might die some time after they start,
 189+ # this code will detect this issue if STARTTIME is set
 190+ # to a reasonable value
 191+ [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
 192+ if running ; then
 193+ # It's ok, the server started and is running
 194+ log_end_msg 0
 195+ else
 196+ # It is not running after we did start
 197+ log_end_msg 1
 198+ fi
 199+ else
 200+ # Either we could not start it
 201+ log_end_msg 1
 202+ fi
 203+ ;;
 204+ stop)
 205+ log_daemon_msg "Stopping $DESC" "$NAME"
 206+ if running ; then
 207+ # Only stop the server if we see it running
 208+ errcode=0
 209+ stop_server || errcode=$?
 210+ log_end_msg $errcode
 211+ else
 212+ # If it's not running don't do anything
 213+ log_progress_msg "apparently not running"
 214+ log_end_msg 0
 215+ exit 0
 216+ fi
 217+ ;;
 218+ force-stop)
 219+ # First try to stop gracefully the program
 220+ $0 stop
 221+ if running; then
 222+ # If it's still running try to kill it more forcefully
 223+ log_daemon_msg "Stopping (force) $DESC" "$NAME"
 224+ errcode=0
 225+ force_stop || errcode=$?
 226+ log_end_msg $errcode
 227+ fi
 228+ ;;
 229+ restart|force-reload)
 230+ log_daemon_msg "Restarting $DESC" "$NAME"
 231+ errcode=0
 232+ stop_server || errcode=$?
 233+ # Wait some sensible amount, some server need this
 234+ [ -n "$DIETIME" ] && sleep $DIETIME
 235+ start_server || errcode=$?
 236+ [ -n "$STARTTIME" ] && sleep $STARTTIME
 237+ running || errcode=$?
 238+ log_end_msg $errcode
 239+ ;;
 240+ status)
 241+
 242+ log_daemon_msg "Checking status of $DESC" "$NAME"
 243+ if running ; then
 244+ log_progress_msg "running"
 245+ log_end_msg 0
 246+ else
 247+ log_progress_msg "apparently not running"
 248+ log_end_msg 1
 249+ exit 0
 250+ fi
 251+ ;;
 252+ reload)
 253+ #
 254+ # If the daemon can reload its config files on the fly
 255+ # for example by sending it SIGHUP, do it here.
 256+ #
 257+ # If the daemon responds to changes in its config file
 258+ # directly anyway, make this a do-nothing entry.
 259+ #
 260+ log_daemon_msg "Reloading $DESC configuration files" "$NAME"
 261+ if running ; then
 262+ reload_server
 263+ if ! running ; then
 264+ # Process died after we tried to reload
 265+ log_progress_msg "died on reload"
 266+ log_end_msg 1
 267+ exit 0
 268+ fi
 269+ else
 270+ log_progress_msg "server is not running"
 271+ log_end_msg 1
 272+ exit 0
 273+ fi
 274+ #;;
 275+
 276+ *)
 277+ N=/etc/init.d/$NAME
 278+ echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
 279+ exit 1
 280+ ;;
 281+esac
 282+
 283+exit 0
Index: trunk/extensions/PoolCounter/daemon/Makefile
@@ -4,6 +4,7 @@
55 OBJS=main.o client_data.o locks.o hash.o
66 LINK=-levent
77 HEADERS=prototypes.h client_data.h
 8+DESTDIR ?=
89
910 poolcounterd: $(OBJS)
1011 $(CC) $(LINK) $^ -o $@
@@ -16,3 +17,7 @@
1718
1819 clean:
1920 rm -f *.o prototypes.h
 21+
 22+install:
 23+ install -d $(DESTDIR)/usr/bin/
 24+ install poolcounterd $(DESTDIR)/usr/bin/

Comments

#Comment by Platonides (talk | contribs)   23:01, 18 March 2011

poolcounter.init completely misses the feature of gracefully being restarted (SIGUSR1).

Status & tagging log