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.