서비스가 중지되면 다시 시작하기 위해 노력하고 있습니다.
나는 찾고 있었다upstart
, 서비스를 다시 시작합니다. 좀 찾았어답변.
테스트를 위해 서비스를 받았습니다 apache2
. 아래와 같이 코드를 변경했습니다.
# File : /etc/init.d/apache2
...
...
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
# either "stop" or "graceful-stop"
local STOP=$1
# can't use pidofproc from LSB here
local AP_RET=0
# send stopping apache event
echo "Stopping....."
initctl emit stopping-apache2
if pidof $DAEMON > /dev/null 2>&1 ; then
if [ -e $PIDFILE ] && pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE) > /dev/null 2>&1 ; then
AP_RET=2
else
AP_RET=1
fi
else
AP_RET=0
fi
# AP_RET is:
# 0 if Apache (whichever) is not running
# 1 if Apache (whichever) is running
# 2 if Apache from the PIDFILE is running
if [ $AP_RET = 0 ] ; then
# send stopping apache event
echo "Stopped.....1"
initctl emit stopped-apache2
return 1
fi
if [ $AP_RET = 2 ] && apache_conftest ; then
$APACHE2CTL $STOP > /dev/null 2>&1
apache_wait_stop $?
# send stopping apache event
echo "Stopped.....2"
initctl emit stopped-apache2
return $?
else
if [ $AP_RET = 2 ]; then
clear_error_msg
APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
killproc -p $PIDFILE $DAEMON
apache_wait_stop $?
# send stopping apache event
echo "Stopped.....3"
initctl emit stopped-apache2
return $?
elif [ $AP_RET = 1 ] ; then
APACHE2_INIT_MESSAGE="There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand".
# send stopping apache event
echo "Stopped.....4"
initctl emit stopped-apache2
return 2
fi
fi
}
...
...
메모: 다음을 사용하여 메시지를 내보냅니다.initctl emit stopped-apache2
그런 다음 apache2.conf
이 이벤트에 대해 시작 작업을 수행하도록 변경되었습니다.
# File /etc/init/apache2.conf
# apache2
# the purpose of this job is
# * start apache2 in upstart rather than SysV startup
start on stopped-apache2
stop on runlevel [016]
pre-start script
export RUNLEVEL=2
[ -f /var/lib/apache2.enable ] && /etc/init.d/apache2 start
end script
post-stop exec /etc/init.d/apache2 stop
아파치를 중지하면 메시지가 나타납니다.
root@localhost:~# /etc/init.d/apache2 stop
[....] Stopping web server: apache2Stopping.....
Stopped.....2
. ok
하지만 실행되지 않는 것 같습니다 start on stopped-apache2
.
또한 을 사용하여 작업을 다시 시작합니다 initctl restart apache2
.
내가 뭔가를 놓쳤나요?
답변1
Upstart 기능을 사용할 수 있습니다 respawn
. 여기에 있는 Apache용 시작 작업을 사용하십시오.https://bitbucket.org/CameronNemo/upstart-jobs/src/2090612200fa588412e3fe22aec5ba3747ae88d2/apache2.conf?at=master
그런 다음 이라는 줄을 추가하면 됩니다 respawn
.