#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the Openstack Swift \
#	Account daemon.
#
# pidfile: /var/run/swift/account-server/swift-account-server.pid
# config:  /etc/swift/account-server.conf


# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 1
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1

. /usr/share/swift/init-functions.sh

SERVICE=account-server
NAME="Swift Account"
LOCKFILE=/var/lock/subsys/$SERVICE
CONFIG=/etc/swift/$SERVICE.conf

# Allow status as non-root.
if [ "$1" = status ]; then
	status $SERVICE "$NAME"
	exit $?
fi

# Check that account-server.conf exists.
[ -f $CONFIG ] || exit 6

# Check that we can read from it... so non-root users stop here
[ -r $CONFIG ] || exit 4

case "$1" in
start)
	start $SERVICE "$NAME"
	;;
stop)
	stop $SERVICE "$NAME"
	;;
restart)
	restart $SERVICE "$NAME"
	;;
reload)
	restart $SERVICE "$NAME"
	;;
status)
	status $SERVICE "$NAME"
	;;
condrestart)
	[ -f $LOCKFILE ] && restart $SERVICE "$NAME" || :
	;;
condstop)
	[ -f $LOCKFILE ] && stop $SERVICE "$NAME" || :
	;;
*)
	echo $"Usage: $0 {start|stop|restart|reload|status|condrestart|condstop}"
	exit 2
esac

exit $?
