Ubuntu Setup Redis boot up

Source: Internet
Author: User
Tags redis redis server

Source: http://blog.chinaunix.net/uid-22312037-id-3484071.html

Today, calm down, the end of the Redis boot start regret. For me, this is a work of no small size, if it is to be fully understood. The difficulties are as follows:

1---Redis startup script, and shell script writing.

2---Linux service mechanism, how those processes will boot off.

Indeed, some difficulties have been encountered. Fortunately, today is a good state, all solved. So, the flow records are as follows.

Start the shell script as follows, of course, also refer to others.

#! /bin/sh

server_dir=/opt/redis-2.6.10
server_name=redis-server
demo= $server _dir/src/$server _name
configuration_file= $server _dir/redis.conf
pid_file= $server _dir/pid/redis.pid


start ()
{
  # Detects if the server exists and has execute permissions
  if test-x $demo
    echo "Starting Redis" 
  then
    #执行启动命令, returns the execution result
    if $demo $ Configuration_file 
    then
      echo  "OK"
    else
      echo  "Failed"
    fi
  Else
    Echo "Could not find Redis server ($demo)"
  fi
}

Stop ()
{
  #检测pid文件是否存在, if present, indicates running
  if TEST-E $pid _file
     then echo "Stopping Redis"
    #pid文件中只存储了进程号, so get the process number directly and kill
    if Kill ' cat $pid _file '
    Then
      echo "OK"
    else
      echo "Failed"
    fi
  Else
    echo "No server is running!"
    Exit 0
  Fi
} 

restart ()
{
  stop
  start
}


#检测输入的命令 case $ in 
  start)
    start
    ;;
  Stop)
    stop
    ;;
  restart|reload)
    restart
    ;;
  *)
    echo  "Bad command"
    exit 1
Esac

exit 0
Problems encountered:

Use of 1--shell case

Use of the 2--shell test command

3--shell Space (Assignment/judgment)


If the script passes after the test, you can do the next task: Set the script to start execution.



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.