aprsc/src/rpm/aprsc.init

200 lines
3.8 KiB
Bash

#!/bin/sh
#
# aprsc Start or stop the aprsc server
#
# chkconfig: 2345 55 25
# description: Provide an APRS-IS server for the amateur radio APRS network
#
# processname: aprsc
# config: /opt/aprsc/etc/aprsc.conf
# pidfile: /opt/aprsc/logs/aprsc.pid
### BEGIN INIT INFO
# Provides: aprsc
# Required-Start: $syslog $network $local_fs
# Required-Stop: $syslog $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop aprsc
# Description: aprsc provides an APRS-IS server for the amateur radio APRS network
### END INIT INFO
# source function library
. /etc/rc.d/init.d/functions
# pull in sysconfig settings
[ -f /etc/sysconfig/aprsc ] && . /etc/sysconfig/aprsc
RETVAL=0
NAME="aprsc"
prog="aprsc"
lockfile=/var/lock/subsys/$prog
DIRNAME=aprsc
BASEDIR=/opt/$DIRNAME
APRSC=$BASEDIR/sbin/aprsc
PID_FILE=$BASEDIR/logs/aprsc.pid
if [ "$STARTAPRSC" != "yes" ];then
echo "Starting of $NAME not enabled in /etc/sysconfig/$NAME."
exit 0
fi
# copy files required for chrooted operation
prepare_chroot () {
echo "Preparing chroot for aprsc..."
/bin/cp -p /etc/resolv.conf /etc/nsswitch.conf /etc/hosts /etc/gai.conf $BASEDIR/etc/
# live upgrade requires libraries to be visible within chroot, so
# set up a read-only bind mount of /lib
grep -q "$DIRNAME/lib " /proc/mounts || \
( mount --bind /lib $BASEDIR/lib \
&& mount -o remount,ro,bind $BASEDIR/lib )
if [ -e /lib64 ]; then
grep -q "$DIRNAME/lib64 " /proc/mounts || \
( mount --bind /lib64 $BASEDIR/lib64 \
&& mount -o remount,ro,bind $BASEDIR/lib64 )
fi
grep -q "$DIRNAME/usr/lib " /proc/mounts || \
( mount --bind /usr/lib $BASEDIR/usr/lib \
&& mount -o remount,ro,bind $BASEDIR/usr/lib )
if [ -e /usr/lib64 ]; then
grep -q "$DIRNAME/usr/lib64 " /proc/mounts || \
( mount --bind /usr/lib64 $BASEDIR/usr/lib64 \
&& mount -o remount,ro,bind $BASEDIR/usr/lib64 )
fi
}
check_configuration() {
echo "Testing aprsc configuration..."
if ! $APRSC $DAEMON_OPTS -y > /dev/null 2>&1; then
$APRSC $DAEMON_OPTS -y || true
exit 1
fi
}
start()
{
[ -x $APRSC ] || exit 5
[ -f /opt/aprsc/etc/aprsc.conf ] || exit 6
prepare_chroot
ulimit -c unlimited
echo -n $"Starting $prog: "
$APRSC $DAEMON_OPTS && success || failure
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
if [ -f $PID_FILE ] ; then
killproc -p $PID_FILE $APRSC
else
failure $"Stopping $prog"
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $lockfile
echo
}
reload()
{
check_configuration
echo -n $"Reloading $prog: "
if [ -f $PID_FILE ] ; then
killproc -p $PID_FILE $APRSC -USR1
else
failure $"Reloading $prog"
fi
RETVAL=$?
echo
}
liveupgrade()
{
check_configuration
prepare_chroot
echo -n $"Performing live upgrade of $prog: "
if [ -f $PID_FILE ] ; then
killproc -p $PID_FILE $APRSC -USR2
else
failure $"Performing live upgrade of $prog"
fi
RETVAL=$?
echo
}
restart() {
check_configuration
stop
start
}
force_reload() {
restart
}
rh_status() {
status -p $PID_FILE aprsc
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
start
;;
stop)
if ! rh_status_q; then
rm -f $lockfile
exit 0
fi
stop
;;
restart)
restart
;;
reload)
rh_status_q || exit 7
reload
;;
liveupgrade)
rh_status_q || exit 7
liveupgrade
;;
force-reload)
force_reload
;;
condrestart|try-restart)
rh_status_q || exit 0
if [ -f $lockfile ] ; then
if [ $RETVAL -eq 0 ] ; then
stop
# avoid race
sleep 3
start
else
RETVAL=6
fi
fi
;;
status)
rh_status
RETVAL=$?
if [ $RETVAL -eq 3 -a -f $lockfile ] ; then
RETVAL=2
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|liveupgrade|status}"
RETVAL=2
esac
exit $RETVAL