#!/bin/sh # chkconfig: 35 97 10 # description: Associate processes to socket (vserver support) # processname: findproc # pidfile: /var/run/findproc.pid cd / PIDFILE=/var/run/findproc.pid SUBSYS=/var/lock/subsys/findproc NAME=findproc SUBUNIXSOCK=/var/run/sub-findproc.sock SUBPIDFILE=/var/run/sub-findproc.pid OPTIONS= # Load the information about vservers and user/groups loadconfig_master(){ # Define the root server # Sometime, findproc is used inside a vserver, so we provide the XID of the master XID=$1 /usr/sbin/$NAME-control clear /usr/sbin/$NAME-control vserver $XID / /usr/sbin/findproc-mapug --userfile /etc/passwd --groupfile /etc/group --xid $XID /usr/sbin/$NAME-control /usr/sbin/$NAME-control commit } loadconfig_vservers(){ # Repeat for all vservers if [ -f /proc/self/vinfo ] ; then for vserv in `vserver-list --running` do XID=`cat /var/run/vservers/$vserv.ctx | sed 's/=/ /' | ( read a b; echo $b)` VSERVERDIR=`/usr/lib/vserver/printconf.sh $vserv | grep VSERVERDIR | sed 's/=/ /' | ( read a b; echo $b)` /usr/sbin/$NAME-control -s $SUBUNIXSOCK vserver $XID $VSERVERDIR /usr/sbin/findproc-mapug --userfile $VSERVERDIR/etc/passwd --groupfile $VSERVERDIR/etc/group --xid $XID \ /usr/sbin/$NAME-control -s $SUBUNIXSOCK done fi /usr/sbin/$NAME-control -s $SUBUNIXSOCK commit } case "$1" in start) echo -n "Starting $NAME: " if [ -f /proc/self/vinfo ]; then # We are running with a vserver aware kernel XID=`cat /proc/self/vinfo | grep XID: | (read a b; echo $b)` if [ "$XID" = 0 ] ; then # We are in the master /usr/sbin/chcontext --silent --ctx 1 /usr/sbin/$NAME --daemon $OPTIONS \ --foruser root --pidfile $SUBPIDFILE --unixsock $SUBUNIXSOCK --partialok /usr/sbin/$NAME --daemon $OPTIONS --subunixsock $SUBUNIXSOCK loadconfig_vservers loadconfig_master 0 else # We are running inside a vserver, so there is no sub-findproc /usr/sbin/$NAME --daemon $OPTIONS loadconfig_master $XID fi else /usr/sbin/$NAME --daemon $OPTIONS loadconfig_master 0 fi echo $NAME touch $SUBSYS ;; stop) echo -n "Stopping $NAME: " if [ -f $PIDFILE ] ; then if [ -f /proc/self/vinfo ] ; then XID=`cat /proc/self/vinfo | grep XID: | (read a b; echo $b)` if [ "$XID" = 0 ] ; then /usr/sbin/$NAME-control -s $SUBUNIXSOCK quit 2>/dev/null rm -f $SUBPIDFILE fi fi /usr/sbin/$NAME-control quit 2>/dev/null rm -f $SUBSYS rm -f $PIDFILE echo "$NAME" else echo fi ;; restart) $0 stop sleep 5 $0 start ;; reload) if [ -f /proc/self/vinfo ] ; then loadconfig_vservers fi loadconfig_master ;; status) if [ ! -f $PIDFILE ] ; then echo Service $NAME is not running elif ! /usr/sbin/$NAME-control printconf >/dev/null 2>/dev/null then echo Service $NAME is not running echo Unclean shutdown else echo Service $NAME is running fi ;; *) echo "Usage: $NAME {start|stop|restart|reload|status}" exit 1 esac exit 0