upstart newbie
unix boy
unixboy80 at gmail.com
Tue May 27 13:17:24 UTC 2014
Good Morning I'm a newbie to upstart trying to convert my
/etc/init.d/apache script over to upstart i just want to make sure that im
on the right track here is what ive done do far.
This is the Original Script
#!/bin/bash
### BEGIN INIT INFO
# Provides: httpd-avs
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: AVS
# Description: Start/Stop Apache Virtual Servers
### END INIT INFO
#
# Platform: Ubuntu
# update-rc.d: httpd-avs start 15 2 3 4 5 . stop 85 0 1 6 .
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd-avs
# Variables
AVSDIR=/usr/local/avs
HTTPD_AVS=httpd-avs
HTTPD_PREFIX="httpd-"
APACHECTL=bin/apache2ctl
PS="/bin/ps -ef"
GREP=/bin/grep
KILL="/bin/kill -9"
AWK=/usr/bin/awk
LOGGER=/usr/bin/logger
RM=/bin/rm
# Functions
# Start all servers
START ()
{
# Disable regular apache
/usr/sbin/service apache2 stop
/usr/sbin/update-rc.d -f apache2 remove
cd $AVSDIR
for SITE in ${HTTPD_PREFIX}*;
do
echo "Starting $SITE..."
$SITE/$APACHECTL start
sleep 1
# Check results
$PS|$GREP -v $GREP|$GREP -q $SITE
# Log failures to the syslog
if [ ! "$?" = "0" ];
then
echo "Instance $SITE failed to start."
$LOGGER -p local4.info "WARNING: httpd instance
$SITE failed to start."
else
echo "Instance $SITE started."
fi
done
}
# Stop all servers
STOP ()
{
cd $AVSDIR
for SITE in ${HTTPD_PREFIX}*;
do
echo "Stopping $SITE..."
$SITE/$APACHECTL stop
if [ "$?" = "0" ];
then
echo "Instance $SITE stopped."
else
echo "Instance $SITE failed to stop."
fi
done
# Check results
echo "Checking for hung httpd processes..."
sleep 5
$PS|$GREP -v $GREP|$GREP -v $HTTPD_AVS|$GREP -q httpd
# If there are hung httpd processes, kill them
if [ "$?" = "0" ];
then
echo "Some httpd processes not stopping; killing them..."
for PROCESS in "`$PS|$GREP -v $GREP|$GREP -v
$HTTPD_AVS|$GREP httpd|$AWK '{print $2}'`";
do
$KILL $PROCESS
done
fi
# Do a final check; log information to syslog either way
$PS|$GREP -v $GREP|$GREP -v $HTTPD_AVS|$GREP -q httpd
if [ "$?" = "0" ];
then
echo "Failed to kill all httpd instances."
$LOGGER -p local4.info "NOTICE: Failed to kill all httpd
instances."
exit 1
fi
echo "All httpd instances stopped."
$LOGGER -p local4.info "All httpd instances stopped."
}
# Script
case "$1" in
start)
START
;;
stop)
STOP
;;
restart)
STOP
START
;;
*)
echo "Usage: $0 [stop|start|restart]"
;;
esac
This is the Upstart Script
# httpd-avs - Apache Virtual Server
#
description "AvS Apache Virtual Server"
start on filesystem or runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
pre-start script
AVSDIR=/usr/local/avs
HTTPD_AVS=httpd-avs
HTTPD_PREFIX="httpd-"
APACHECTL=bin/apache2ctl
PS="/bin/ps -ef"
GREP=/bin/grep
KILL="/bin/kill -9"
AWK=/usr/bin/awk
LOGGER=/usr/bin/logger
RM=/bin/rm
# Disable regular apache
/usr/sbin/service apache2 stop
/usr/sbin/update-rc.d -f apache2 remove
cd $AVSDIR
for SITE in ${HTTPD_PREFIX}*;
do
echo "Starting $SITE..."
$SITE/$APACHECTL start
sleep 1
# Check results
$PS|$GREP -v $GREP|$GREP -q $SITE
# Log failures to the syslog
if [ ! "$?" = "0" ];
then
echo "Instance $SITE failed to start."
$LOGGER -p local4.info "WARNING: httpd instance
$SITE failed to start."
else
echo "Instance $SITE started."
fi
done
end script
post-stop script
cd $AVSDIR
for SITE in ${HTTPD_PREFIX}*;
do
echo "Stopping $SITE..."
$SITE/$APACHECTL stop
if [ "$?" = "0" ];
then
echo "Instance $SITE stopped."
else
echo "Instance $SITE failed to stop."
fi
done
# Check results
echo "Checking for hung httpd processes..."
sleep 5
$PS|$GREP -v $GREP|$GREP -v $HTTPD_AVS|$GREP -q httpd
# If there are hung httpd processes, kill them
if [ "$?" = "0" ];
then
echo "Some httpd processes not stopping; killing them..."
for PROCESS in "`$PS|$GREP -v $GREP|$GREP -v
$HTTPD_AVS|$GREP httpd|$AWK '{print $2}'`";
do
$KILL $PROCESS
done
fi
# Do a final check; log information to syslog either way
$PS|$GREP -v $GREP|$GREP -v $HTTPD_AVS|$GREP -q httpd
if [ "$?" = "0" ];
then
echo "Failed to kill all httpd instances."
$LOGGER -p local4.info "NOTICE: Failed to kill all httpd
instances."
exit 1
fi
echo "All httpd instances stopped."
$LOGGER -p local4.info "All httpd instances stopped."
end script
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140527/ea8f9e27/attachment.html>
More information about the upstart-devel
mailing list