nginx php-fpm memcached 均为编译安装,将脚本统一放置在/etc/init.d/ 下,造成启动服务的标准化。
1、编译安装后nginx启动、中止有些麻烦,将下面内容添加到/etc/init.d/nginx中,做为nginx的服务启动。
#!/bin/bash
#chkconfig: 345 85 15
#description:It is used to serve PATH=/usr/local/nginx/sbin:$PATH export PATH # check if root account if [ $(id -u) != "0" ];then printf "Error:You must be root account!\n" exit 1 fi #Define environment variables NGINX_PID=/usr/local/nginx/logs/nginx.pid NGINX_DAEMON=/usr/local/nginx/sbin/nginx #Function define fun_start() { printf "Starting nginx ...\n" if [ -f $NGINX_PID ];then printf "Nginx is running!\n" exit 1 else $NGINX_DAEMON printf "Nginx start successfully!\n" fi } fun_stop() { printf "Stoping Nginx...\n" if [ -f $NGINX_PID ];then kill $(cat $NGINX_PID) printf "Nginx is stopped!\n" else printf "Nginx is not running!\n" fi } fun_reload() { printf "Reloading Nginx...\n" if [ -f $NGINX_PID ];then $NGINX_DAEMON -s reload else printf "Nginx is not running!\n" fi } fun_restart() { printf "Restarting Nginx..." kill $(cat $NGINX_PID) $NGINX_DAEMON } fun_status() { if [ -f $NGINX_PID ];then printf "Nginx is running!\n" else printf "Nginx is stop!\n" fi } case "$1" in start) fun_start ;; stop) fun_stop ;; restart) fun_stop fun_start ;; reload) fun_reload ;; status) fun_status ;; *) printf "Usage:Only {start|stop|restart|reload|status}" esac exit ------------- < nginx script END> -------------- 说明:脚本中红色字体部分为将nginx添加为linux系统服务必须添加的语句,不然没法添加成功。 红色字体的意思为:启动级别 | 启动优先级 | 中止优先级 一、将nginx赋予执行权限,放置在/etc/init.d/下 二、chkconfig --add nginx 2、将php-fpm的启动脚本放置在/etc/init.d下 ln -s /usr/local/php5/sbin/php-fpm /etc/init.d/php-fpm 3、memcached启动脚本 路径:/etc/init.d/memcached 赋予执行权限 #!/bin/bash # check if root account if [ $(id -u) != "0" ];then printf "Error:You must be root account!\n" exit 1 fi memcache_prog=$(ps -ef | grep memcached | grep -v grep | wc -l) memcache_pid=$(ps -ef | grep memcached | grep -v grep | awk '{print $2}') mem=50 user=root port=12000 fun_start() if [ $memcache_prog != "0" ];then printf "memcached is running !\n" else memcached -d -m $mem -u $user -p $port printf "memcached is started!\n" fi fun_stop() if [ $memcache_prog = "0" ];then printf "memcached is not running !\n" else kill $memcache_pid printf "memcached is stopped\n" fi fun_status() if [ $memcache_prog != "0" ];then printf "memcached is running !\n" else printf "memcached is stopped!\n" fi case "$1" in start) fun_start ;; stop) fun_stop ;; restart) fun_stop fun_start ;; status) fun_status ;; *) printf "Usage:Only {start | stop | restart | status }\n" esac exit ------------- <memcached script END> ---------------------