Last active
December 16, 2015 09:19
-
-
Save liuyanghejerry/5411947 to your computer and use it in GitHub Desktop.
Redis-server management script for CentOS 6.3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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