LAMP 重启脚本 发表于 2012-06-30 | 分类于 Linux | | 阅读次数: | 字数统计: 321 自己手工安装的lamp,所以需要有个脚本来控制服务器的停止与启动。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATH# Check if user is rootif [ $(id -u) != "0" ]; then printf "Error: You must be root to run this script!\n" exit 1fiHOSTNAME=`hostname`MYSQLPIDFILE=/usr/local/mysql/data/$HOSTNAME.pidAPACHENAME=httpdAPACHEPIDFILE=/usr/local/apache/logs/$APACHENAME.pidfunction_start(){ printf "Starting LAMP...\n" /etc/init.d/httpd start if [ -f $MYSQLPIDFILE ]; then printf "MySQL is runing!\n" else /etc/init.d/mysqld start printf "MySQL start successfully!\n" fi}function_stop(){ printf "Stoping LAMP...\n" /etc/init.d/httpd stop if [ -f $MYSQLPIDFILE ]; then /etc/init.d/mysqld stop printf "MySQL program is stop\n" else printf "MySQL program is not runing!\n" fi}function_reload(){ printf "Reload LAMP...\n" /etc/init.d/mysqld reload /etc/init.d/httpd restart}function_restart(){ printf "Restart LAMP...\n" /etc/init.d/mysqld restart /etc/init.d/httpd restart}function_kill(){ kill `cat $APACHEPIDFILE` kill `cat $MYSQLPIDFILE`}function_status(){/etc/init.d/httpd status/etc/init.d/mysqld status}case "$1" in start) function_start ;; stop) function_stop ;; restart) function_stop function_start ;; reload) function_reload ;; kill) function_kill ;; status) function_status ;; *) printf "Usage: /root/lamp {start|stop|reload|restart|kill|status}\n"esacexit