-
-
Save soomtong/a80269c8d52cd6239c37 to your computer and use it in GitHub Desktop.
redis db manage script
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 | |
| ## Please update your redis.conf demonize mode to yes `daemonize yes` | |
| if [ -z $1 ] ; then | |
| echo "Usage: $0 [start|stop|restart] " | |
| exit 1 | |
| fi | |
| # Source the common setup functions for startup scripts | |
| test -r /etc/rc.common || exit 1 | |
| . /etc/rc.common | |
| # Set up some defaults | |
| CFGPATH='/usr/local/etc/redis.conf' | |
| REDIS_PORT=6379 | |
| StartService(){ | |
| /usr/local/bin/redis-server $CFGPATH --port $REDIS_PORT > /dev/null 2>&1 & | |
| } | |
| StopService() { | |
| pidfile=/usr/local/var/run/redis.pid | |
| # If the lockfile exists, it contains the PID | |
| if [ -e $pidfile ]; then | |
| pid=`cat $pidfile` | |
| fi | |
| # If we don't have a PID, check for it | |
| if [ "$pid" == "" ]; then | |
| pid=`/usr/sbin/lsof -i tcp:$REDIS_PORT | tail -1 | awk '{print $2}'` | |
| fi | |
| # If we've found a PID, let's kill it | |
| if [ "$pid" != "" ]; then | |
| kill -15 $pid | |
| fi | |
| } | |
| RestartService() { | |
| StopService | |
| sleep 3 | |
| StartService | |
| } | |
| RunService $1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment