redis-2.8.13 Self-Starting service script

Source: Internet
Author: User
Tags redis redis server egrep

After installing redis-2.8.13, I found that there was no self-launching script and wrote one yourself:

Script one:

#!/bin/sh

# chkconfig:345
# Description:startup and shutdown script for Redis
redis_dir=/usr/local/bin
#export $ Redis_dir

redis_conf=/etc/redis.conf redis_pid=/var/run/redis.pid case $ in
    start|s)
        Redis-server $REDIS _conf
        ;;

    ' Stop ')
        echo "Stopping Redis ..."
        kill ' cat $REDIS _pid '
        ;;

    ' Restart ' | ' Reload ' | ' R ')
        ${0} stop
        ${0} start
        ;

    List ' | ' L ')
        ps aux | egrep ' (pid|redis-server) '
        ;;

    *)
echo "Usage: ' basename $ ' {start|restart|reload|stop|list}"
Esac

Script two:

#!/bin/sh
# chkconfig:345 #
Description:startup and shutdown script for Redis
Redis_dir=/usr/local/bi n
#export $REDIS _dir

redis_conf=/etc/redis.conf redis_pid=/var/run/redis.pid case $ in
    start |s)
        if test-x $REDIS _dir/redis-server
        then
            echo "Starting REDIS ..."
            if $REDIS _dir/redis-server $ redis_conf
            then
            echo "OK"
            else
                echo "failed"
            fi
    Else
        echo "couldn ' t find Redis Server ($REDIS _dir/redis-server) "
    fi
        ;;

    ' Stop ')
        echo "Stopping Redis ..."
        kill ' cat $REDIS _pid '
        ;;

    ' Restart ' | ' Reload ' | ' R ')
        ${0} stop
        ${0} start
        ;

    List ' | ' L ')
        ps aux | egrep ' (pid|redis-server) '
        ;;

    *)
echo "Usage: ' basename $ ' {start|restart|reload|stop|list}"
Esac

CP./REDISD/ETC/RC.D/INIT.D/REDISD

Registration Service:

chmod +X/ETC/RC.D/INIT.D/REDISD

Chkconfig--add REDISD

Chkconfig--level 345 REDISD on

Chkconfig--list REDISD

Start the service:

/etc/init.d/redis2 start

With different parameters on behalf of different service requirements, the parameters are: start,restart,reload,stop,list


Prompt for such an error when executing a shell script:

/bin/bash^m:bad interpreter:no such file or dire

The main reason is that the shell script file is in DOS format, that is, the end of each line is identified by \ r \ n, while the Unix file line end is identified by \ n;

Solution:

(1) using the Linux command Dos2unix filename to convert files directly to UNIX format
(2) Use the SED command sed-i "s/\r//" filename or sed-i "s/^m//" filename to replace the end character directly with the UNIX format
(3) VI filename Open file, execute: Set Ff=unix set file for Unix, then execute: WQ, save to UNIX format.

I tend to use the third program, the most simple and practical.



This completes the entire Redis self-starting service script.

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.