Here is the file you requested.
Code:
#!/bin/sh
#
# the path to your PID file
HTTPD_PIDFILE=/srv/apache2/logs/httpd.pid
HOSTNAME=`hostname`
MYSQL_PIDFILE=/srv/mysql/data/mysqld.pid
#
# the path to your httpd binary, including options if necessary
HTTPD="/srv/apache2/bin/httpd -f /srv/apache2/conf/httpd.conf"
MYSQL_START="/srv/mysql/bin/safe_mysqld --port=3306 --socket=/srv/mysql/tmp/mysql.sock --old-passwords --datadir=/srv/mysql/data --err-log=/srv/mysql/data/mysqld.log --pid-file=/srv/mysql/data/mysqld.pid"
MYSQL_STOP="/srv/mysql/bin/mysqladmin --socket=/srv/mysql/tmp/mysql.sock -u root -p shutdown"
MYSQL_PASSWORD="FZ9G201"
#
# a command that outputs a formatted text version of the HTML at the
# url given on the command line. Designed for lynx, however other
# programs may work.
LYNX="lynx -dump"
#
# the URL to your server's mod_status status page. If you do not
# have one, then status and fullstatus will not work.
STATUSURL="http://localhost/server-status"
MYSQL_STATUS=""
HTTPD_STATUS=""
MYSQL_PID=""
HTTPD_PID=""
PID=""
ERROR=0
SERVER=both
export LD_LIBRARY_PATH="/srv/apache2/lib:/srv/common/lib:$LD_LIBRARY_PATH"
export PATH=$PATH:/srv/php/bin
export PHPRC=/srv/php/etc
get_pid() {
PID=""
PIDFILE=$1
# check for pidfile
if [ -f $PIDFILE ] ; then
PID=`cat $PIDFILE`
fi
}
get_apache_pid() {
get_pid $HTTPD_PIDFILE
if [ ! $PID ]; then
return
fi
if [ $PID -gt 0 ]; then
HTTPD_PID=$PID
fi
}
get_mysql_pid() {
get_pid $MYSQL_PIDFILE
if [ ! $PID ]; then
return
fi
if [ $PID -gt 0 ]; then
MYSQL_PID=$PID
fi
}
is_service_running() {
PID=$1
if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
RUNNING=1
else
RUNNING=0
fi
return $RUNNING
}
is_mysql_running() {
get_mysql_pid
is_service_running $MYSQL_PID
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
MYSQL_STATUS="mysql not running"
else
MYSQL_STATUS="mysql already running"
fi
return $RUNNING
}
is_apache_running() {
get_apache_pid
is_service_running $HTTPD_PID
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
HTTPD_STATUS="apache not running"
else
HTTPD_STATUS="apache already running"
fi
return $RUNNING
}
test_apache_config() {
if $HTTPD -t; then
ERROR=0
else
ERROR=8
echo "apache config test fails, aborting"
exit $ERROR
fi
}
start_mysql() {
is_mysql_running
RUNNING=$?
if [ $RUNNING -eq 1 ]; then
echo "$0 $ARG: mysql (pid $MYSQL_PID) already running"
exit
fi
$MYSQL_START &
if [ $? -eq 0 ]; then
echo "$0 $ARG: mysql started at port 3306"
sleep 2
else
echo "$0 $ARG: mysql could not be started"
ERROR=3
fi
}
stop_mysql() {
NO_EXIT_ON_ERROR=$1
is_mysql_running
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
echo "$0 $ARG: $MYSQL_STATUS"
if [ "x$NO_EXIT_ON_ERROR" != "xno_exit" ]; then
exit
else
return
fi
fi
echo "MySQL will prompt you for the root password."
if [ "x$MYSQL_PASSWORD" != "x" ]; then
MYSQL_STOP="$MYSQL_STOP --password=$MYSQL_PASSWORD"
fi
$MYSQL_STOP
is_mysql_running
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
echo "$0 $ARG: mysql stopped"
else
echo "$0 $ARG: mysql could not be stopped"
ERROR=4
fi
}
start_apache() {
test_apache_config
is_apache_running
RUNNING=$?
if [ $RUNNING -eq 1 ]; then
echo "$0 $ARG: httpd (pid $HTTPD_PID) already running"
exit
fi
if $HTTPD ; then
echo "$0 $ARG: httpd started at port 8081"
else
echo "$0 $ARG: httpd could not be started"
ERROR=3
fi
}
stop_apache() {
NO_EXIT_ON_ERROR=$1
test_apache_config
is_apache_running
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
echo "$0 $ARG: $HTTPD_STATUS"
if [ "x$NO_EXIT_ON_ERROR" != "xno_exit" ]; then
exit
else
return
fi
fi
get_apache_pid
if kill $HTTPD_PID ; then
echo "$0 $ARG: httpd stopped"
else
echo "$0 $ARG: httpd could not be stopped"
ERROR=4
fi
}
help() {
echo "usage: $0 help"
echo " $0 (start|stop|restart)"
echo " $0 (start|stop|restart) apache"
echo " $0 (start|stop|restart) mysql"
cat <<EOF
help - this screen
start - start the service(s)
stop - stop the service(s)
restart - restart or start the service(s)
EOF
exit 0
}
noserver() {
echo -e "ERROR: $1 is not a valid server. Please, select 'mysql' or 'apache'\n"
help
}
[ $# -lt 1 ] && help
if [ ! -z ${2} ]; then
[ "${2}" != "mysql" ] && [ "${2}" != "apache" ] && noserver $2
SERVER=$2
fi
if [ "x$3" != "x" ]; then
MYSQL_PASSWORD=$3
fi
case $1 in
help) help
;;
start)
if [ "${SERVER}" != "both" ]; then
start_${2}
else
start_mysql
start_apache
fi
;;
stop) if [ "${SERVER}" != "both" ]; then
stop_${2}
else
stop_apache "no_exit"
stop_mysql
fi
;;
restart) if [ "${SERVER}" != "both" ]; then
stop_${2} "no_exit"
sleep 2
start_${2}
else
stop_apache "no_exit"
stop_mysql "no_exit"
start_mysql
start_apache
fi
;;
esac
exit $ERROR
Bookmarks