redis入门(8)

2021-05-19 16:13:04 浏览数 (1)

四.编写启动脚本

1.根据情况填写对应变量

vim man-redis

  1. #!/bin/bash
  2. install_dir=/usr/local
  3. server_dir=redis
  4. log_dir=/var/log
  5. port=6379
  6. if [[ "$1" == "start" ]];then
  7. netstat -unltp |grep :${port} &> /dev/null
  8. if [ $? -eq 0 ];then
  9. echo "redis Already started"
  10. exit
  11. fi
  12. nohup ${install_dir}/${server_dir}/bin/redis-server ${install_dir}/${server_dir} &> ${log_dir}/${server_dir}/redis.log &
  13. elif [[ "$1" == "stop" ]];then
  14. netstat -unltp |grep :${port} &> /dev/null
  15. if [ $? -eq 0 ];then
  16. pid=`netstat -unltp | grep :${port} | head -1 |awk '{print $7}' | awk -F'/' '{print $1}'`
  17. kill -9 $pid
  18. fi
  19. else
  20. echo "start | stop"
  21. fi

2.添加权限,并加入到bin目录下,后面就可以当命令一样使用

mv man-redis /usr/local/bin

chmod x /usr/local/bin/man-redis

man-redis start

0 人点赞