A script that can configure the Redis database to boot automatically

Source: Internet
Author: User
Tags redis redis server

Share a script that can configure the Redis database to boot automatically

At first want to put order redis-server/etc/redis/redis.conf join to/etc/rc.d/rc.local unexpectedly not, had to find another way
The first step is to write the main service boot SH script/etc/init.d/redis

The code is as follows Copy Code
#!/bin/bash
#
# Redis-this script starts and stops the Redis-server daemon
#
# Chkconfig:-80 12
# Description:redis is a persistent key-value database
# Processname:redis-server
# config:/etc/6379.conf
# Pidfile:/redis/redis6379.pid
Path=/usr/local/bin:/sbin:/usr/bin:/bin

redisport=6379
Ex_ec=/usr/local/bin/redis-server
Redis_cli=/usr/local/bin/redis-cli

Pidfile=/redis/redis6379.pid
conf= "/etc/6379.conf"

Case "$" in
Start
If [f $PIDFILE]
Then
echo "$PIDFILE exists, process is already running or crashed"
Else
echo "Starting Redis server ..."
$EX _ec $CONF
Fi
If ["$?" = "0"]
Then
echo "Redis is running ..."
Fi
;;
Stop
if [!-F $PIDFILE]
Then
echo "$PIDFILE does not exist, process isn't running"
Else
pid=$ (Cat $PIDFILE)
echo "Stopping ..."
$REDIS _cli-p $REDISPORT SHUTDOWN
While [-X ${pidfile}]
Todo
echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
echo "Redis stopped"
Fi
;;
Restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2
Exit 1
Esac



File deposited in/etc/init.d/redis

Then modify the permissions and Chkconfig

chmod 0777/etc/init.d/redis
Chkconfig Redis on

Join to boot boot vi/etc/rc.d/rc.local

Add the following 2 lines

Service Redis Start

Done

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.