After installing redis-2.8.13, I found that there was no self-launching script and wrote one yourself:
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
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
The main reason is that the shell script file is in DOS format, that is, the end of each line is identified by \ r \ n, while the Unix file line end is identified by \ n;
Solution:
(1) using the Linux command Dos2unix filename to convert files directly to UNIX format
(2) Use the SED command sed-i "s/\r//" filename or sed-i "s/^m//" filename to replace the end character directly with the UNIX format
(3) VI filename Open file, execute: Set Ff=unix set file for Unix, then execute: WQ, save to UNIX format.
I tend to use the third program, the most simple and practical.
This completes the entire Redis self-starting service script.