How to write a Redis startup script using the shell

Source: Internet
Author: User
Tags config redis redis server
#!/bin/bash 
# 
# Init file for redis 
# From: JC
# Email:jiechao2013@gmail.com
# chkconfig: - 80 12 
# description: redis daemon 
# 
# processname: redis 
# config: /opt/redis-2.6.4/redis.conf 
# pidfile: /var/run/redis.pid 
     
source /etc/init.d/functions 
     
     
BIN="/opt/redis/bin"
CONFIG="/opt/redis-2.6.4/redis.conf"
PIDFILE="/var/run/redis.pid"
     
### Read configuration 
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
     
RETVAL=0 
prog="redis-server"
desc="Redis Server"
     
start() { 
     
    if [ -e $PIDFILE ];then 
        echo "$desc already running...."
        exit 1 
    fi 
     
    echo -n $"Starting $desc: "
    daemon $BIN/$prog $CONFIG & 
     
    RETVAL=$? 
    echo 
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
    return $RETVAL 
} 
     
stop() { 
    echo -n $"Stop $desc: "
    killproc $prog 
    RETVAL=$? 
    echo 
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
    return $RETVAL 
} 
     
restart() { 
    stop 
    start 
} 
     
     
case "$1" in
start)  
    start 
    ;; 
stop) 
    stop 
    ;; 
restart) 
    restart 
    ;; 
condrestart) 
    [ -e /var/lock/subsys/$prog ] && restart 
    RETVAL=$? 
    ;; 
status) 
    status $prog 
    RETVAL=$? 
    ;; 
  *) 
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    RETVAL=1 
esac 
     
exit $RETVAL


[Root@dg-web opt]#/etc/init.d/redis Status



Redis-server (PID 26147) is running ...



[Root@dg-web opt]# Netstat-lntp|grep Redis-server



TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 26147/redis-server



[Root@dg-web opt]#/etc/init.d/redis Stop



Stop redis Server: [OK]



[Root@dg-web opt]#/etc/init.d/redis Status



Redis-server is stopped



[Root@dg-web opt]# Netstat-lntp|grep Redis-server


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.