Group :: Banco de dados
RPM: redis
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
#!/bin/sh
#
# redis redis-server - Persistent key-value db
#
# chkconfig: - 20 80
# description: redis-server is a persistent key-value db \
# This script starts and stops the redis daemon.
# processname: redis-server
# config: /etc/redis/redis.conf
# pidfile: /var/run/redis/redis-server.pid
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
# Description: redis-server - Persistent key-value db
### END INIT INFO
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1
# Source function library.
. /etc/init.d/functions
PIDDIR=/var/run/redis/
PIDFILE=$PIDDIR/redis-server.pid
LOCKFILE=/var/lock/subsys/redis
REDIS_DAEMON=/usr/sbin/redis-server
REDIS_CLI=/usr/bin/redis-cli
SYSCONFIG=/etc/sysconfig/redis
REDIS_USER=_redis
REDIS_GROUP=_redis
CONFIG_FILE=/etc/redis/redis.conf
CLI_ARGS=''
STOP_METHOD="TERM"
WAIT_TIMEOUT=300
SHUTDOWN_CMD='shutdown'
RETVAL=0
SourceIfExists "$SYSCONFIG"
call_cli()
{
CMD=$1
[ "foo$CMD" = "foo" ] && CMD='save'
if [ -f $PIDFILE ]; then
$REDIS_CLI $CLI_ARGS $CMD
if [ $? -ne 0 ]; then
failure "Fail to run 'redis-cli $CLI_ARGS $CMD'"
fi
else
msg_not_running "redis-server"
fi
}
start()
{
mkdir -p $PIDDIR
chown root:$REDIS_GROUP $PIDDIR
chmod 0775 $PIDDIR
start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --user $REDIS_USER --expect-user $REDIS_USER -- $REDIS_DAEMON $CONFIG_FILE
RETVAL=$?
return $RETVAL
}
is_running()
{
status --pidfile "$PIDFILE" --expect-user $REDIS_USER -- redis-server >/dev/null
return $?
}
kill_daemon()
{
# Immediately daemon with SIGKILL signal
echo -n "Stopping redis-server service (KILLing it): "
stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $REDIS_USER -KILL -- $REDIS_DAEMON
RETVAL=$?
return $RETVAL
}
stop_wait()
{
for i in `seq 1 $1`; do
is_running || return
printf '%5s' "$i"
sleep 1
printf "\b\b\b\b\b \b\b\b\b\b"
done
return 255
}
term_daemon()
{
echo -n "Sending TERM signal to redis-server: "
stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $REDIS_USER -TERM -- $REDIS_DAEMON
echo -n "Waiting, while redis-server actualy stopped:"
stop_wait $WAIT_TIMEOUT
RETVAL=$?
if [ $RETVAL -eq 255 ]; then
echo_failure
echo
stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user $REDIS_USER -- $REDIS_DAEMON
RETVAL=$?
else
echo_success
echo
fi
return $RETVAL
}
shutdown_daemon()
{
if is_running; then
echo -n "Shutdown redis-server, saving databases... "
call_cli "$SHUTDOWN_CMD"
if is_running; then # Stil running - something wrong
echo_failure
echo
echo -n "Can't stop daemon - something wrong. Check log file for details."
return 255
else
echo_success
rm -f "$LOCKFILE"
fi
else
msg_not_running "redis-server"
echo_passed
fi
echo
return 0
}
stop()
{
# NOTE: using standard 'stop_daemon --pidfile ... --lockfile ... --expect-user ... -- ...' COULD CAUSE A DATA LOSS.
case "$STOP_METHOD" in
KILL|kill|SIGKILL)
kill_daemon
RETVAL=$?
;;
SHUTDOWN|shutdown)
shutdown_daemon
RETVAL=$?
;;
TERM|term|SIGTERM)
term_daemon
RETVAL=$?
;;
*)
echo "Unknown method '$STOP_METHOD' to stop redis-server - check '$SYSCONFIG' file"
echo "Using TERM method as default"
term_daemon
RETVAL=$?
esac
return $RETVAL
}
restart()
{
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
# No way to reload - restart only
restart
;;
restart)
restart
;;
condstop)
if [ -e "$LOCKFILE" ]; then
stop
fi
;;
condrestart)
if [ -e "$LOCKFILE" ]; then
restart
fi
;;
condreload)
if [ -e "$LOCKFILE" ]; then
restart
fi
;;
status)
status --pidfile "$PIDFILE" --expect-user $REDIS_USER -- redis-server
RETVAL=$?
;;
save)
if [ -e "$LOCKFILE" ]; then
echo "Saving Redis databases ..."
call_cli save
fi
;;
*)
msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status|save}"
RETVAL=1
esac
exit $RETVAL