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.