lnmp搭建wordpress實例--啓動腳本



    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>  ---------------------
相關文章
相關標籤/搜索