redis-2.8.13 Self-Boot service script

Source: Internet
Author: User
Tags redis redis server egrep

After installing redis-2.8.13, I found that I did not start the script and wrote one myself:

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

To 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

Mainly because the shell script file is a DOS format, that is, each line ends with \ r \ n to identify, and UNIX-formatted file lines are identified by \ n;

Solution:

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

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



This completes the entire Redis 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.