Skip to content

Instantly share code, notes, and snippets.

@liuyanghejerry
Last active December 16, 2015 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuyanghejerry/5411947 to your computer and use it in GitHub Desktop.
Save liuyanghejerry/5411947 to your computer and use it in GitHub Desktop.
Redis-server management script for CentOS 6.3.
#!/bin/bash
# chkconfig: - 80 12
# description: Controller for redis-server
# processname: redis
# useage: redis {start|stop|restart}
# notice, you need to edit these 4 variables bellow to suit your condition
BIN="/usr/local/redis/bin/redis-server"
CONFIG="/usr/local/redis/conf/redis.conf"
PID="/usr/local/redis/run/redis.pid"
USER="redis"
# user can be add as: adduser --system --create-home -b /usr/local/redis --shell /sbin/nologin --user-group redis
set -e
function start {
if [ -e "$PID" ];then
echo "redis-server already running...."
exit 1
fi
echo "starting redis-server at $BIN with config $CONFIG"
# su - "$USER" -c "$BIN" "$CONFIG"
sudo -u "$USER" -H "$BIN" "$CONFIG"
}
function stop {
echo "stoping $BIN ..."
killall -w "$BIN"
echo "done."
}
function restart {
stop
start
}
function status {
echo "unsupport function"
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
*)
echo "Usage: redis {start|stop|restart}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment