You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by John Iliffe <jo...@iliffe.ca> on 2017/03/28 02:22:13 UTC

[users@httpd] Run Control for Apache in Fedora 25

First, I know this is probably not an Apache question, but I'm hoping that 
someone on this list may have seen this problem before and knows the 
solution.

I know this is going to be very long winded, my apologies in advance, but I 
have done quite a bit of research so I have a good idea what won't work :-(

Problem:

OS is Fedora 25

Fedora replaces service with systemctl control using service files for 
starting and stopping daemons.  This is a bit different than the traditional 
init.d approach.  

I installed Apache-2.4.25 from source without using the Fedora installation 
so I had to produce my own start up scripts and used the compatibility 
feature of systemctl so httpd can be started from /etc/init.d/httpd

My startup script works perfectly UNTIL I reboot.  At that point the 
directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets deleted.  
I have a good idea of why this happens; it is this line in 
/etc/rc.d/init.d/functions which runs during shutdown or reboot:

	rm -f "${pid_file:-/var/run/$base.pid}"

It is obvious that $base includes the httpd/ subdirectory so that gets 
deleted too.

Changing the pid file location away from /var/run/httpd/ can't be done.  
Even if the start up script in init.d is changed systemctl expects to find 
it there.  So I changed the httpd.conf file to put it where systemctl wants 
it to be.

In case anyone wonders, I can put the pid file anywhere during start up but 
if I do that systemctl hangs and then times out during startup with a 
message that the pid file is unreadable, leaving httpd running and an 
orphan. Also "systemctl stop httpd" hangs and httpd stays up.  In this one  
case, "systemctl reboot" never completes; you end up having to push the 
reset button; although I would assume that in the fullness of time it might 
time out.

"systemctl status httpd" in this case shows that httpd is NOT running due 
to a missing resource (the pid file) even though it is up and running fine.

There is one obvious work-around, check for /var/run/httpd on startup in 
the init.d script, and it it isn't there, create it, but that begs the 
question of what am I not understanding.  

So, has anyone encountered this before.  I sure hope it isn't a fat finger 
error on my part but two days is enough for something like this.  I need 
help!

Here is the relevant part of the (current) httpd.conf file in 
/usr/apache-2.4.25/conf/httpd.conf 

# Added with 2.4.25, 25/3/2017, to work with Fedora which won't
#       relocate the pid file to the default location
PidFile /var/run/httpd/httpd.pid
#

and here is the complete init.d/httpd startup script. Mostly it was cribbed 
from the old server's (RHEL6 and apache-2.4.10) script.  A lot of the 
commented lines are where I have been trying to find a solution to the 
problem.  In general, one # is Red Hat's comments and two ## is my testing.

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#              server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
# This was damaged by Red Hat system update 23/4/2013.  Changed back to
# probable initial code.
#
# Converted for new prod04 server 26/3/2017 JI
#
## apachectl=/usr/sbin/apachectl
apachectl=/usr/apache-2.4.25/bin/apachectl
## httpd=${HTTPD-/usr/sbin/httpd}
httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this doesn't 
work
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init 
scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
##        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
    $apachectl -k start
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
        echo -n $"Stopping $prog: "
##      killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    $apachectl -k stop
        RETVAL=$?
        echo
##       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
        [ $RETVAL = 0 ]
}

reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
#        LSB=1 killproc -p ${pidfile} $httpd -HUP
    $apachectl -k restart
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        ;;
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|
force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac

exit $RETVAL


FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.  They 
were created automatically when I ran "systemctl enable" on httpd.

Any suggestions as to where to go next would be appreciated!

Regards,

John











---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by John Iliffe <jo...@iliffe.ca>.
See below.

One thing I notice is that the pid file path is in here too.  It could be 
that when I changed the path in the init.d file this one stayed; I'll check 
that now.

Also, looking at the reply from Kartik Vashishta; I notice a number of 
areas where there seems to be some incompatibility between the 
documentation in the man file for systemd.service and what is actually being 
generated.

I'm going through that in detail now.

John
==================================
On Tuesday 28 March 2017 10:41:38 Mitchell Krog Photography wrote:
> What does
> 
> sudo systemctl edit --full httpd
> 
> show you ???
> 
# Automatically generated by systemd-sysv-generator

[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/httpd
Description=LSB: start and stop Apache HTTP Server
Before=multi-user.target
Before=multi-user.target
Before=multi-user.target
Before=graphical.target
After=remote-fs.target
After=network-online.target
After=nss-lookup.target
After=distcache.service
Wants=network-online.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=no
PIDFile=/var/run/httpd/httpd.pid
ExecStart=/etc/rc.d/init.d/httpd start
ExecStop=/etc/rc.d/init.d/httpd stop
ExecReload=/etc/rc.d/init.d/httpd reload
> 
> From: John Iliffe <jo...@iliffe.ca> <jo...@iliffe.ca>
> Reply: users@httpd.apache.org <us...@httpd.apache.org>
> <us...@httpd.apache.org>
> Date: 28 March 2017 at 4:35:52 PM
> To: users@httpd.apache.org <us...@httpd.apache.org>
> <us...@httpd.apache.org> Subject:  Re: [users@httpd] Run Control for
> Apache in Fedora 25
> 
> Thank you Mickey.
> 
> That is exactly what the problem is; all /var/run subdirectories get
> deleted on reboot.
> 
> I tried to move the pid file to another location, for a start its
> default location under the apache install directory, but even directly
> on /var/run/, with the result that systemctl could not find it. The pid
> file was written correctly, under the correct name, and was readable by
> root, but was reported as missing by systemctl and as a result the
> "systemctl stop httpd" command didn't work. It just issued an error
> message and httpd kept right on running.
> 
> One trhing that I have been careful to do is keep the start up script at
> init.d/httpd pointed at the same location as httpd.conf.
> 
> I'm not sure why but systemctl seems to insist that that the httpd pid
> file be exactly /var/run/httpd/httpd.pid .
> 
> I think there must be a configuration parameter somewhere for systemctl
> but I have not been able to find it; can't believe it would be hard
> coded in the
> programme!
> 
> That said, thank you for the reply. It does give me the idea that I am
> on the right track.
> 
> John
> ===========================================
> 
> On Tuesday 28 March 2017 03:05:31 Mickey Nordstrom wrote:
> > Hi John,
> > 
> > I didn't read your full post so apologies if I'm not answering your
> > question. I have had similar problems on SuSE Linux whith systemd and
> > the solution was to create a file under /etc/tmpfiles.d with content
> > something like this:
> > 
> > d /var/run/httpd 770 webservd webservd
> > 
> > Modify it to the user and group that runs your httpd daemon.
> > 
> > This is needed because /run and /var/run are volatile and gets cleaned
> > out at each reboot.
> > 
> > /Mikael
> > 
> > On 28/03/17 04:22, John Iliffe wrote:
> > > First, I know this is probably not an Apache question, but I'm
> > > hoping that someone on this list may have seen this problem before
> > > and knows the solution.
> > > 
> > > I know this is going to be very long winded, my apologies in
> > > advance, but I have done quite a bit of research so I have a good
> > > idea what won't work :-(
> > > 
> > > Problem:
> > > 
> > > OS is Fedora 25
> > > 
> > > Fedora replaces service with systemctl control using service files
> > > for starting and stopping daemons. This is a bit different than the
> > > traditional init.d approach.
> > > 
> > > I installed Apache-2.4.25 from source without using the Fedora
> > > installation so I had to produce my own start up scripts and used
> > > the compatibility feature of systemctl so httpd can be started from
> > > /etc/init.d/httpd
> > > 
> > > My startup script works perfectly UNTIL I reboot. At that point the
> > > directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets
> > > deleted. I have a good idea of why this happens; it is this line in
> > > 
> > > /etc/rc.d/init.d/functions which runs during shutdown or reboot:
> > > rm -f "${pid_file:-/var/run/$base.pid}"
> > > 
> > > It is obvious that $base includes the httpd/ subdirectory so that
> > > gets deleted too.
> > > 
> > > Changing the pid file location away from /var/run/httpd/ can't be
> > > done. Even if the start up script in init.d is changed systemctl
> > > expects to find it there. So I changed the httpd.conf file to put it
> > > where systemctl wants it to be.
> > > 
> > > In case anyone wonders, I can put the pid file anywhere during start
> > > up but if I do that systemctl hangs and then times out during
> > > startup with a message that the pid file is unreadable, leaving
> > > httpd running and an orphan. Also "systemctl stop httpd" hangs and
> > > httpd stays up. In this one case, "systemctl reboot" never
> > > completes; you end up having to push the reset button; although I
> > > would assume that in the fullness of time it might time out.
> > > 
> > > "systemctl status httpd" in this case shows that httpd is NOT
> > > running due to a missing resource (the pid file) even though it is
> > > up and running fine.
> > > 
> > > There is one obvious work-around, check for /var/run/httpd on
> > > startup in the init.d script, and it it isn't there, create it, but
> > > that begs the question of what am I not understanding.
> > > 
> > > So, has anyone encountered this before. I sure hope it isn't a fat
> > > finger error on my part but two days is enough for something like
> > > this. I need help!
> > > 
> > > Here is the relevant part of the (current) httpd.conf file in
> > > /usr/apache-2.4.25/conf/httpd.conf
> > > 
> > > # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> > > # relocate the pid file to the default location
> > > PidFile /var/run/httpd/httpd.pid
> > > #
> > > 
> > > and here is the complete init.d/httpd startup script. Mostly it was
> > > cribbed from the old server's (RHEL6 and apache-2.4.10) script. A
> > > lot of the commented lines are where I have been trying to find a
> > > solution to the problem. In general, one # is Red Hat's comments and
> > > two ## is my testing.
> > > 
> > > #!/bin/bash
> > > #
> > > # httpd Startup script for the Apache HTTP Server
> > > #
> > > # chkconfig: - 85 15
> > > # description: The Apache HTTP Server is an efficient and extensible
> > > \ # server implementing the current HTTP standards. #
> > > processname: httpd
> > > # config: /etc/httpd/conf/httpd.conf
> > > # config: /etc/sysconfig/httpd
> > > # pidfile: /var/run/httpd/httpd.pid
> > > #
> > > ### BEGIN INIT INFO
> > > # Provides: httpd
> > > # Required-Start: $local_fs $remote_fs $network $named
> > > # Required-Stop: $local_fs $remote_fs $network
> > > # Should-Start: distcache
> > > # Default-Start: 2 3 4 5
> > > # Default-Stop: 0 1 6
> > > # Short-Description: start and stop Apache HTTP Server
> > > # Description: The Apache HTTP Server is an extensible server
> > > # implementing the current HTTP standards.
> > > ### END INIT INFO
> > > 
> > > # Source function library.
> > > . /etc/rc.d/init.d/functions
> > > 
> > > if [ -f /etc/sysconfig/httpd ]; then
> > > 
> > > . /etc/sysconfig/httpd
> > > 
> > > fi
> > > 
> > > # Start httpd in the C locale by default.
> > > HTTPD_LANG=${HTTPD_LANG-"C"}
> > > 
> > > # This will prevent initlog from swallowing up a pass-phrase prompt
> > > if # mod_ssl needs a pass-phrase from the user.
> > > INITLOG_ARGS=""
> > > 
> > > # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a
> > > server # with the thread-based "worker" MPM; BE WARNED that some
> > > modules may not # work correctly with a thread-based MPM; notably
> > > PHP will refuse to start. # Path to the apachectl script, server
> > > binary, and short-form for messages. # This was damaged by Red Hat
> > > system update 23/4/2013. Changed back to # probable initial code.
> > > #
> > > # Converted for new prod04 server 26/3/2017 JI
> > > #
> > > ## apachectl=/usr/sbin/apachectl
> > > apachectl=/usr/apache-2.4.25/bin/apachectl
> > > ## httpd=${HTTPD-/usr/sbin/httpd}
> > > httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> > > prog=httpd
> > > pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> > > ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this
> > > doesn't work
> > > lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> > > RETVAL=0
> > > STOP_TIMEOUT=${STOP_TIMEOUT-10}
> > > 
> > > # The semantics of these two functions differ from the way apachectl
> > > does # things -- attempting to start while running is a failure, and
> > > shutdown # when not running is also a failure. So we just do it the
> > > way init scripts
> > > # are expected to behave here.
> > > start() {
> > > 
> > > echo -n $"Starting $prog: "
> > > 
> > > ## LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
> > > 
> > > $apachectl -k start
> > > 
> > > RETVAL=$?
> > > echo
> > > [ $RETVAL = 0 ] && touch ${lockfile}
> > > return $RETVAL
> > > 
> > > }
> > > 
> > > # When stopping httpd, a delay (of default 10 second) is required
> > > # before SIGKILLing the httpd parent; this gives enough time for the
> > > # httpd parent to SIGKILL any errant children.
> > > stop() {
> > > 
> > > echo -n $"Stopping $prog: "
> > > 
> > > ## killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
> > > 
> > > $apachectl -k stop
> > > 
> > > RETVAL=$?
> > > echo
> > > 
> > > ## [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> > > 
> > > [ $RETVAL = 0 ]
> > > 
> > > }
> > > 
> > > reload() {
> > > 
> > > echo -n $"Reloading $prog: "
> > > if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
> > > 
> > > RETVAL=6
> > > echo $"not reloading due to configuration syntax error"
> > > failure $"not reloading $httpd due to configuration syntax
> > > error"
> > > 
> > > else
> > > 
> > > # Force LSB behaviour from killproc
> > > 
> > > # LSB=1 killproc -p ${pidfile} $httpd -HUP
> > > 
> > > $apachectl -k restart
> > > 
> > > RETVAL=$?
> > > if [ $RETVAL -eq 7 ]; then
> > > 
> > > failure $"httpd shutdown"
> > > 
> > > fi
> > > 
> > > fi
> > > echo
> > > 
> > > }
> > > 
> > > # See how we were called.
> > > case "$1" in
> > > 
> > > start)
> > > 
> > > start
> > > ;;
> > > 
> > > stop)
> > > 
> > > stop
> > > ;;
> > > 
> > > status)
> > > 
> > > status -p ${pidfile} $httpd
> > > RETVAL=$?
> > > ;;
> > > 
> > > restart)
> > > 
> > > stop
> > > ;;
> > > 
> > > status)
> > > 
> > > status -p ${pidfile} $httpd
> > > RETVAL=$?
> > > ;;
> > > 
> > > restart)
> > > 
> > > stop
> > > start
> > > ;;
> > > 
> > > condrestart|try-restart)
> > > 
> > > if status -p ${pidfile} $httpd >&/dev/null; then
> > > 
> > > stop
> > > start
> > > 
> > > fi
> > > ;;
> > > 
> > > force-reload|reload)
> > > 
> > > reload
> > > ;;
> > > 
> > > graceful|help|configtest|fullstatus)
> > > 
> > > $apachectl $@
> > > RETVAL=$?
> > > ;;
> > > 
> > > *)
> > > 
> > > echo $"Usage: $prog
> > > {start|stop|restart|condrestart|try-restart|
> > > 
> > > force-reload|reload|status|fullstatus|graceful|help|configtest}"
> > > 
> > > RETVAL=2
> > > 
> > > esac
> > > 
> > > exit $RETVAL
> > > 
> > > 
> > > FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.
> > > They were created automatically when I ran "systemctl enable" on
> > > httpd.
> > > 
> > > Any suggestions as to where to go next would be appreciated!
> > > 
> > > Regards,
> > > 
> > > John
> > > 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by Mitchell Krog Photography <mi...@gmail.com>.
Brilliant, so glad you got it sorted :)

Cheers
Mitch



From: John Iliffe <jo...@iliffe.ca> <jo...@iliffe.ca>
Reply: users@httpd.apache.org <us...@httpd.apache.org>
<us...@httpd.apache.org>
Date: 28 March 2017 at 6:08:33 PM
To: users@httpd.apache.org <us...@httpd.apache.org> <us...@httpd.apache.org>
Subject:  Re: [users@httpd] Run Control for Apache in Fedora 25

First, my sincere thanks to all the folks who responded so fast to my
problem. I have it fixed, I think. Testing so far seems to work as
expected.

The problem is that when "systemctl enable" generates the new unit file
(httpd.service) it didn't get it quite right. For one thing, it dropped
apachectl from the start up and used httpd directly. For another, the pid
file was being written to a directory that was transient, as noted in the
post by Mikael. In this case I had the reason in my initial post but
didn't understand it.

So.....

the solution is to generate a new unit file (read man page systemd.service)
and force the parameters you need. Delete the one generated by systemctl.
be sure that all of the related configuration files (httpd.service,
httpd.conf, init.d/httpd) match as far as where the files are going.

I used the sample in Stack Overflow suggested by Mitchell, modified a bit
to
match my installation. This works one for me.

-------------------------------------------
[Unit]
Description=The Apache HTTP Server

[Service]
Type=forking
EnvironmentFile=/usr/apache-2.4.25/bin/envvars
PIDFile=/var/run/httpd.pid
ExecStart=/usr/apache-2.4.25/bin/apachectl -k start
ExecReload=/usr/apache-2.4.25/bin/apachectl -k graceful
ExecStop=/usr/apache-2.4.25/bin/apachectl -k stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
---------------------------------------------

Regards,

John
========================================
On Tuesday 28 March 2017 10:35:44 Kartik Vashishta wrote:
> Maybe this will help:
> http://stackoverflow.com/questions/32977557/how-do-i-compile-apache-http
> d-2-4-16-with-systemd-support
>
> On Tue, Mar 28, 2017 at 9:35 AM, John Iliffe <jo...@iliffe.ca>
wrote:
> > Thank you Mickey.
> >
> > That is exactly what the problem is; all /var/run subdirectories get
> > deleted on reboot.
> >
> > I tried to move the pid file to another location, for a start its
> > default location under the apache install directory, but even
> > directly on /var/run/, with the result that systemctl could not find
> > it. The pid file was written correctly, under the correct name, and
> > was readable by root, but was reported as missing by systemctl and as
> > a result the "systemctl stop httpd" command didn't work. It just
> > issued an error message and httpd kept right on running.
> >
> > One trhing that I have been careful to do is keep the start up script
> > at init.d/httpd pointed at the same location as httpd.conf.
> >
> > I'm not sure why but systemctl seems to insist that that the httpd pid
> > file be exactly /var/run/httpd/httpd.pid .
> >
> > I think there must be a configuration parameter somewhere for
> > systemctl but I have not been able to find it; can't believe it would
> > be hard coded in the
> > programme!
> >
> > That said, thank you for the reply. It does give me the idea that I
> > am on the right track.
> >
> > John
> > ===========================================
> > ==============snip========================

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by John Iliffe <jo...@iliffe.ca>.
First, my sincere thanks to all the folks who responded so fast to my 
problem.  I have it fixed, I think.  Testing so far seems to work as 
expected.

The problem is that when "systemctl enable" generates the new unit file 
(httpd.service) it didn't get it quite right.  For one thing, it dropped 
apachectl from the start up and used httpd directly.  For another, the pid 
file was being written to a directory that was transient, as noted in the 
post by Mikael.  In this case I had the reason in my initial post but 
didn't understand it.

So.....

the solution is to generate a new unit file (read man page systemd.service) 
and force the parameters you need.  Delete the one generated by systemctl.  
be sure that all of the related configuration files (httpd.service, 
httpd.conf, init.d/httpd) match as far as where the files are going.

I used the sample in Stack Overflow suggested by Mitchell, modified a bit to 
match my installation.  This works one for me.

-------------------------------------------
[Unit]
Description=The Apache HTTP Server

[Service]
Type=forking
EnvironmentFile=/usr/apache-2.4.25/bin/envvars
PIDFile=/var/run/httpd.pid
ExecStart=/usr/apache-2.4.25/bin/apachectl -k start
ExecReload=/usr/apache-2.4.25/bin/apachectl -k graceful
ExecStop=/usr/apache-2.4.25/bin/apachectl -k stop
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
---------------------------------------------

Regards,

John
========================================
On Tuesday 28 March 2017 10:35:44 Kartik Vashishta wrote:
> Maybe this will help:
> http://stackoverflow.com/questions/32977557/how-do-i-compile-apache-http
> d-2-4-16-with-systemd-support
> 
> On Tue, Mar 28, 2017 at 9:35 AM, John Iliffe <jo...@iliffe.ca> wrote:
> > Thank you Mickey.
> > 
> > That is exactly what the problem is; all /var/run subdirectories get
> > deleted on reboot.
> > 
> > I tried to move the pid file to another location, for a start its
> > default location under the apache install directory, but even
> > directly on /var/run/, with the result that systemctl could not find
> > it.  The pid file was written correctly, under the correct name, and
> > was readable by root, but was reported as missing by systemctl and as
> > a result the "systemctl stop httpd" command didn't work.  It just
> > issued an error message and httpd kept right on running.
> > 
> > One trhing that I have been careful to do is keep the start up script
> > at init.d/httpd pointed at the same location as httpd.conf.
> > 
> > I'm not sure why but systemctl seems to insist that that the httpd pid
> > file be exactly  /var/run/httpd/httpd.pid .
> > 
> > I think there must be a configuration parameter somewhere for
> > systemctl but I have not been able to find it; can't believe it would
> > be hard coded in the
> > programme!
> > 
> > That said, thank you for the reply.  It does give me the idea that I
> > am on the right track.
> > 
> > John
> > ===========================================
> > ==============snip========================

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by Kartik Vashishta <ka...@gmail.com>.
Maybe this will help:
http://stackoverflow.com/questions/32977557/how-do-i-compile-apache-httpd-2-4-16-with-systemd-support

On Tue, Mar 28, 2017 at 9:35 AM, John Iliffe <jo...@iliffe.ca> wrote:

> Thank you Mickey.
>
> That is exactly what the problem is; all /var/run subdirectories get
> deleted on reboot.
>
> I tried to move the pid file to another location, for a start its default
> location under the apache install directory, but even directly on
> /var/run/, with the result that systemctl could not find it.  The pid file
> was written correctly, under the correct name, and was readable by root,
> but was reported as missing by systemctl and as a result the "systemctl
> stop httpd" command didn't work.  It just issued an error message and httpd
> kept right on running.
>
> One trhing that I have been careful to do is keep the start up script at
> init.d/httpd pointed at the same location as httpd.conf.
>
> I'm not sure why but systemctl seems to insist that that the httpd pid file
> be exactly  /var/run/httpd/httpd.pid .
>
> I think there must be a configuration parameter somewhere for systemctl but
> I have not been able to find it; can't believe it would be hard coded in
> the
> programme!
>
> That said, thank you for the reply.  It does give me the idea that I am on
> the right track.
>
> John
> ===========================================
>
> On Tuesday 28 March 2017 03:05:31 Mickey Nordstrom wrote:
> > Hi John,
> >
> > I didn't read your full post so apologies if I'm not answering your
> > question. I have had similar problems on SuSE Linux whith systemd and
> > the solution was to create a file under /etc/tmpfiles.d with content
> > something like this:
> >
> > d  /var/run/httpd 770 webservd webservd
> >
> > Modify it to the user and group that runs your httpd daemon.
> >
> > This is needed because /run and /var/run are volatile and gets cleaned
> > out at each reboot.
> >
> > /Mikael
> >
> > On 28/03/17 04:22, John Iliffe wrote:
> > > First, I know this is probably not an Apache question, but I'm hoping
> > > that someone on this list may have seen this problem before and knows
> > > the solution.
> > >
> > > I know this is going to be very long winded, my apologies in advance,
> > > but I have done quite a bit of research so I have a good idea what
> > > won't work :-(
> > >
> > > Problem:
> > >
> > > OS is Fedora 25
> > >
> > > Fedora replaces service with systemctl control using service files for
> > > starting and stopping daemons.  This is a bit different than the
> > > traditional init.d approach.
> > >
> > > I installed Apache-2.4.25 from source without using the Fedora
> > > installation so I had to produce my own start up scripts and used the
> > > compatibility feature of systemctl so httpd can be started from
> > > /etc/init.d/httpd
> > >
> > > My startup script works perfectly UNTIL I reboot.  At that point the
> > > directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets
> > > deleted. I have a good idea of why this happens; it is this line in
> > >
> > > /etc/rc.d/init.d/functions which runs during shutdown or reboot:
> > >     rm -f "${pid_file:-/var/run/$base.pid}"
> > >
> > > It is obvious that $base includes the httpd/ subdirectory so that gets
> > > deleted too.
> > >
> > > Changing the pid file location away from /var/run/httpd/ can't be
> > > done. Even if the start up script in init.d is changed systemctl
> > > expects to find it there.  So I changed the httpd.conf file to put it
> > > where systemctl wants it to be.
> > >
> > > In case anyone wonders, I can put the pid file anywhere during start
> > > up but if I do that systemctl hangs and then times out during startup
> > > with a message that the pid file is unreadable, leaving httpd running
> > > and an orphan. Also "systemctl stop httpd" hangs and httpd stays up.
> > > In this one case, "systemctl reboot" never completes; you end up
> > > having to push the reset button; although I would assume that in the
> > > fullness of time it might time out.
> > >
> > > "systemctl status httpd" in this case shows that httpd is NOT running
> > > due to a missing resource (the pid file) even though it is up and
> > > running fine.
> > >
> > > There is one obvious work-around, check for /var/run/httpd on startup
> > > in the init.d script, and it it isn't there, create it, but that begs
> > > the question of what am I not understanding.
> > >
> > > So, has anyone encountered this before.  I sure hope it isn't a fat
> > > finger error on my part but two days is enough for something like
> > > this.  I need help!
> > >
> > > Here is the relevant part of the (current) httpd.conf file in
> > > /usr/apache-2.4.25/conf/httpd.conf
> > >
> > > # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> > > #       relocate the pid file to the default location
> > > PidFile /var/run/httpd/httpd.pid
> > > #
> > >
> > > and here is the complete init.d/httpd startup script. Mostly it was
> > > cribbed from the old server's (RHEL6 and apache-2.4.10) script.  A
> > > lot of the commented lines are where I have been trying to find a
> > > solution to the problem.  In general, one # is Red Hat's comments and
> > > two ## is my testing.
> > >
> > > #!/bin/bash
> > > #
> > > # httpd        Startup script for the Apache HTTP Server
> > > #
> > > # chkconfig: - 85 15
> > > # description: The Apache HTTP Server is an efficient and extensible
> > > \ #              server implementing the current HTTP standards. #
> > > processname: httpd
> > > # config: /etc/httpd/conf/httpd.conf
> > > # config: /etc/sysconfig/httpd
> > > # pidfile: /var/run/httpd/httpd.pid
> > > #
> > > ### BEGIN INIT INFO
> > > # Provides: httpd
> > > # Required-Start: $local_fs $remote_fs $network $named
> > > # Required-Stop: $local_fs $remote_fs $network
> > > # Should-Start: distcache
> > > # Default-Start: 2 3 4 5
> > > # Default-Stop: 0 1 6
> > > # Short-Description: start and stop Apache HTTP Server
> > > # Description: The Apache HTTP Server is an extensible server
> > > #  implementing the current HTTP standards.
> > > ### END INIT INFO
> > >
> > > # Source function library.
> > > . /etc/rc.d/init.d/functions
> > >
> > > if [ -f /etc/sysconfig/httpd ]; then
> > >
> > >         . /etc/sysconfig/httpd
> > >
> > > fi
> > >
> > > # Start httpd in the C locale by default.
> > > HTTPD_LANG=${HTTPD_LANG-"C"}
> > >
> > > # This will prevent initlog from swallowing up a pass-phrase prompt if
> > > # mod_ssl needs a pass-phrase from the user.
> > > INITLOG_ARGS=""
> > >
> > > # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a
> > > server # with the thread-based "worker" MPM; BE WARNED that some
> > > modules may not # work correctly with a thread-based MPM; notably PHP
> > > will refuse to start. # Path to the apachectl script, server binary,
> > > and short-form for messages. # This was damaged by Red Hat system
> > > update 23/4/2013.  Changed back to # probable initial code.
> > > #
> > > # Converted for new prod04 server 26/3/2017 JI
> > > #
> > > ## apachectl=/usr/sbin/apachectl
> > > apachectl=/usr/apache-2.4.25/bin/apachectl
> > > ## httpd=${HTTPD-/usr/sbin/httpd}
> > > httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> > > prog=httpd
> > > pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> > > ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this
> > > doesn't work
> > > lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> > > RETVAL=0
> > > STOP_TIMEOUT=${STOP_TIMEOUT-10}
> > >
> > > # The semantics of these two functions differ from the way apachectl
> > > does # things -- attempting to start while running is a failure, and
> > > shutdown # when not running is also a failure.  So we just do it the
> > > way init scripts
> > > # are expected to behave here.
> > > start() {
> > >
> > >         echo -n $"Starting $prog: "
> > >
> > > ##        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
> > >
> > >     $apachectl -k start
> > >
> > >         RETVAL=$?
> > >         echo
> > >         [ $RETVAL = 0 ] && touch ${lockfile}
> > >         return $RETVAL
> > >
> > > }
> > >
> > > # When stopping httpd, a delay (of default 10 second) is required
> > > # before SIGKILLing the httpd parent; this gives enough time for the
> > > # httpd parent to SIGKILL any errant children.
> > > stop() {
> > >
> > >         echo -n $"Stopping $prog: "
> > >
> > > ##      killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
> > >
> > >     $apachectl -k stop
> > >
> > >         RETVAL=$?
> > >         echo
> > >
> > > ##       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> > >
> > >         [ $RETVAL = 0 ]
> > >
> > > }
> > >
> > > reload() {
> > >
> > >     echo -n $"Reloading $prog: "
> > >     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
> > >
> > >         RETVAL=6
> > >         echo $"not reloading due to configuration syntax error"
> > >         failure $"not reloading $httpd due to configuration syntax
> > >         error"
> > >
> > >     else
> > >
> > >         # Force LSB behaviour from killproc
> > >
> > > #        LSB=1 killproc -p ${pidfile} $httpd -HUP
> > >
> > >     $apachectl -k restart
> > >
> > >         RETVAL=$?
> > >         if [ $RETVAL -eq 7 ]; then
> > >
> > >             failure $"httpd shutdown"
> > >
> > >         fi
> > >
> > >     fi
> > >     echo
> > >
> > > }
> > >
> > > # See how we were called.
> > > case "$1" in
> > >
> > >   start)
> > >
> > >         start
> > >         ;;
> > >
> > >   stop)
> > >
> > >         stop
> > >         ;;
> > >
> > >   status)
> > >
> > >         status -p ${pidfile} $httpd
> > >         RETVAL=$?
> > >         ;;
> > >
> > >   restart)
> > >
> > >         stop
> > >         ;;
> > >
> > >   status)
> > >
> > >         status -p ${pidfile} $httpd
> > >         RETVAL=$?
> > >         ;;
> > >
> > >   restart)
> > >
> > >         stop
> > >         start
> > >         ;;
> > >
> > >   condrestart|try-restart)
> > >
> > >         if status -p ${pidfile} $httpd >&/dev/null; then
> > >
> > >                 stop
> > >                 start
> > >
> > >         fi
> > >         ;;
> > >
> > >   force-reload|reload)
> > >
> > >         reload
> > >         ;;
> > >
> > >   graceful|help|configtest|fullstatus)
> > >
> > >         $apachectl $@
> > >         RETVAL=$?
> > >         ;;
> > >
> > >   *)
> > >
> > >         echo $"Usage: $prog
> > >         {start|stop|restart|condrestart|try-restart|
> > >
> > > force-reload|reload|status|fullstatus|graceful|help|configtest}"
> > >
> > >         RETVAL=2
> > >
> > > esac
> > >
> > > exit $RETVAL
> > >
> > >
> > > FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.
> > > They were created automatically when I ran "systemctl enable" on
> > > httpd.
> > >
> > > Any suggestions as to where to go next would be appreciated!
> > >
> > > Regards,
> > >
> > > John
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > > For additional commands, e-mail: users-help@httpd.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by Kartik Vashishta <ka...@gmail.com>.
another link:
https://blacksaildivision.com/how-to-install-apache-on-centos

On Tue, Mar 28, 2017 at 9:41 AM, Mitchell Krog Photography <
mitchellkrog@gmail.com> wrote:

> What does
>
> sudo systemctl edit --full httpd
>
> show you ???
>
>
>
>
> From: John Iliffe <jo...@iliffe.ca> <jo...@iliffe.ca>
> Reply: users@httpd.apache.org <us...@httpd.apache.org>
> <us...@httpd.apache.org>
> Date: 28 March 2017 at 4:35:52 PM
> To: users@httpd.apache.org <us...@httpd.apache.org>
> <us...@httpd.apache.org>
> Subject:  Re: [users@httpd] Run Control for Apache in Fedora 25
>
> Thank you Mickey.
>
> That is exactly what the problem is; all /var/run subdirectories get
> deleted on reboot.
>
> I tried to move the pid file to another location, for a start its default
> location under the apache install directory, but even directly on
> /var/run/, with the result that systemctl could not find it. The pid file
> was written correctly, under the correct name, and was readable by root,
> but was reported as missing by systemctl and as a result the "systemctl
> stop httpd" command didn't work. It just issued an error message and httpd
> kept right on running.
>
> One trhing that I have been careful to do is keep the start up script at
> init.d/httpd pointed at the same location as httpd.conf.
>
> I'm not sure why but systemctl seems to insist that that the httpd pid
> file
> be exactly /var/run/httpd/httpd.pid .
>
> I think there must be a configuration parameter somewhere for systemctl
> but
> I have not been able to find it; can't believe it would be hard coded in
> the
> programme!
>
> That said, thank you for the reply. It does give me the idea that I am on
> the right track.
>
> John
> ===========================================
>
> On Tuesday 28 March 2017 03:05:31 Mickey Nordstrom wrote:
> > Hi John,
> >
> > I didn't read your full post so apologies if I'm not answering your
> > question. I have had similar problems on SuSE Linux whith systemd and
> > the solution was to create a file under /etc/tmpfiles.d with content
> > something like this:
> >
> > d /var/run/httpd 770 webservd webservd
> >
> > Modify it to the user and group that runs your httpd daemon.
> >
> > This is needed because /run and /var/run are volatile and gets cleaned
> > out at each reboot.
> >
> > /Mikael
> >
> > On 28/03/17 04:22, John Iliffe wrote:
> > > First, I know this is probably not an Apache question, but I'm hoping
> > > that someone on this list may have seen this problem before and knows
> > > the solution.
> > >
> > > I know this is going to be very long winded, my apologies in advance,
> > > but I have done quite a bit of research so I have a good idea what
> > > won't work :-(
> > >
> > > Problem:
> > >
> > > OS is Fedora 25
> > >
> > > Fedora replaces service with systemctl control using service files for
> > > starting and stopping daemons. This is a bit different than the
> > > traditional init.d approach.
> > >
> > > I installed Apache-2.4.25 from source without using the Fedora
> > > installation so I had to produce my own start up scripts and used the
> > > compatibility feature of systemctl so httpd can be started from
> > > /etc/init.d/httpd
> > >
> > > My startup script works perfectly UNTIL I reboot. At that point the
> > > directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets
> > > deleted. I have a good idea of why this happens; it is this line in
> > >
> > > /etc/rc.d/init.d/functions which runs during shutdown or reboot:
> > > rm -f "${pid_file:-/var/run/$base.pid}"
> > >
> > > It is obvious that $base includes the httpd/ subdirectory so that gets
> > > deleted too.
> > >
> > > Changing the pid file location away from /var/run/httpd/ can't be
> > > done. Even if the start up script in init.d is changed systemctl
> > > expects to find it there. So I changed the httpd.conf file to put it
> > > where systemctl wants it to be.
> > >
> > > In case anyone wonders, I can put the pid file anywhere during start
> > > up but if I do that systemctl hangs and then times out during startup
> > > with a message that the pid file is unreadable, leaving httpd running
> > > and an orphan. Also "systemctl stop httpd" hangs and httpd stays up.
> > > In this one case, "systemctl reboot" never completes; you end up
> > > having to push the reset button; although I would assume that in the
> > > fullness of time it might time out.
> > >
> > > "systemctl status httpd" in this case shows that httpd is NOT running
> > > due to a missing resource (the pid file) even though it is up and
> > > running fine.
> > >
> > > There is one obvious work-around, check for /var/run/httpd on startup
> > > in the init.d script, and it it isn't there, create it, but that begs
> > > the question of what am I not understanding.
> > >
> > > So, has anyone encountered this before. I sure hope it isn't a fat
> > > finger error on my part but two days is enough for something like
> > > this. I need help!
> > >
> > > Here is the relevant part of the (current) httpd.conf file in
> > > /usr/apache-2.4.25/conf/httpd.conf
> > >
> > > # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> > > # relocate the pid file to the default location
> > > PidFile /var/run/httpd/httpd.pid
> > > #
> > >
> > > and here is the complete init.d/httpd startup script. Mostly it was
> > > cribbed from the old server's (RHEL6 and apache-2.4.10) script. A
> > > lot of the commented lines are where I have been trying to find a
> > > solution to the problem. In general, one # is Red Hat's comments and
> > > two ## is my testing.
> > >
> > > #!/bin/bash
> > > #
> > > # httpd Startup script for the Apache HTTP Server
> > > #
> > > # chkconfig: - 85 15
> > > # description: The Apache HTTP Server is an efficient and extensible
> > > \ # server implementing the current HTTP standards. #
> > > processname: httpd
> > > # config: /etc/httpd/conf/httpd.conf
> > > # config: /etc/sysconfig/httpd
> > > # pidfile: /var/run/httpd/httpd.pid
> > > #
> > > ### BEGIN INIT INFO
> > > # Provides: httpd
> > > # Required-Start: $local_fs $remote_fs $network $named
> > > # Required-Stop: $local_fs $remote_fs $network
> > > # Should-Start: distcache
> > > # Default-Start: 2 3 4 5
> > > # Default-Stop: 0 1 6
> > > # Short-Description: start and stop Apache HTTP Server
> > > # Description: The Apache HTTP Server is an extensible server
> > > # implementing the current HTTP standards.
> > > ### END INIT INFO
> > >
> > > # Source function library.
> > > . /etc/rc.d/init.d/functions
> > >
> > > if [ -f /etc/sysconfig/httpd ]; then
> > >
> > > . /etc/sysconfig/httpd
> > >
> > > fi
> > >
> > > # Start httpd in the C locale by default.
> > > HTTPD_LANG=${HTTPD_LANG-"C"}
> > >
> > > # This will prevent initlog from swallowing up a pass-phrase prompt if
> > > # mod_ssl needs a pass-phrase from the user.
> > > INITLOG_ARGS=""
> > >
> > > # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a
> > > server # with the thread-based "worker" MPM; BE WARNED that some
> > > modules may not # work correctly with a thread-based MPM; notably PHP
> > > will refuse to start. # Path to the apachectl script, server binary,
> > > and short-form for messages. # This was damaged by Red Hat system
> > > update 23/4/2013. Changed back to # probable initial code.
> > > #
> > > # Converted for new prod04 server 26/3/2017 JI
> > > #
> > > ## apachectl=/usr/sbin/apachectl
> > > apachectl=/usr/apache-2.4.25/bin/apachectl
> > > ## httpd=${HTTPD-/usr/sbin/httpd}
> > > httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> > > prog=httpd
> > > pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> > > ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this
> > > doesn't work
> > > lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> > > RETVAL=0
> > > STOP_TIMEOUT=${STOP_TIMEOUT-10}
> > >
> > > # The semantics of these two functions differ from the way apachectl
> > > does # things -- attempting to start while running is a failure, and
> > > shutdown # when not running is also a failure. So we just do it the
> > > way init scripts
> > > # are expected to behave here.
> > > start() {
> > >
> > > echo -n $"Starting $prog: "
> > >
> > > ## LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
> > >
> > > $apachectl -k start
> > >
> > > RETVAL=$?
> > > echo
> > > [ $RETVAL = 0 ] && touch ${lockfile}
> > > return $RETVAL
> > >
> > > }
> > >
> > > # When stopping httpd, a delay (of default 10 second) is required
> > > # before SIGKILLing the httpd parent; this gives enough time for the
> > > # httpd parent to SIGKILL any errant children.
> > > stop() {
> > >
> > > echo -n $"Stopping $prog: "
> > >
> > > ## killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
> > >
> > > $apachectl -k stop
> > >
> > > RETVAL=$?
> > > echo
> > >
> > > ## [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> > >
> > > [ $RETVAL = 0 ]
> > >
> > > }
> > >
> > > reload() {
> > >
> > > echo -n $"Reloading $prog: "
> > > if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
> > >
> > > RETVAL=6
> > > echo $"not reloading due to configuration syntax error"
> > > failure $"not reloading $httpd due to configuration syntax
> > > error"
> > >
> > > else
> > >
> > > # Force LSB behaviour from killproc
> > >
> > > # LSB=1 killproc -p ${pidfile} $httpd -HUP
> > >
> > > $apachectl -k restart
> > >
> > > RETVAL=$?
> > > if [ $RETVAL -eq 7 ]; then
> > >
> > > failure $"httpd shutdown"
> > >
> > > fi
> > >
> > > fi
> > > echo
> > >
> > > }
> > >
> > > # See how we were called.
> > > case "$1" in
> > >
> > > start)
> > >
> > > start
> > > ;;
> > >
> > > stop)
> > >
> > > stop
> > > ;;
> > >
> > > status)
> > >
> > > status -p ${pidfile} $httpd
> > > RETVAL=$?
> > > ;;
> > >
> > > restart)
> > >
> > > stop
> > > ;;
> > >
> > > status)
> > >
> > > status -p ${pidfile} $httpd
> > > RETVAL=$?
> > > ;;
> > >
> > > restart)
> > >
> > > stop
> > > start
> > > ;;
> > >
> > > condrestart|try-restart)
> > >
> > > if status -p ${pidfile} $httpd >&/dev/null; then
> > >
> > > stop
> > > start
> > >
> > > fi
> > > ;;
> > >
> > > force-reload|reload)
> > >
> > > reload
> > > ;;
> > >
> > > graceful|help|configtest|fullstatus)
> > >
> > > $apachectl $@
> > > RETVAL=$?
> > > ;;
> > >
> > > *)
> > >
> > > echo $"Usage: $prog
> > > {start|stop|restart|condrestart|try-restart|
> > >
> > > force-reload|reload|status|fullstatus|graceful|help|configtest}"
> > >
> > > RETVAL=2
> > >
> > > esac
> > >
> > > exit $RETVAL
> > >
> > >
> > > FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.
> > > They were created automatically when I ran "systemctl enable" on
> > > httpd.
> > >
> > > Any suggestions as to where to go next would be appreciated!
> > >
> > > Regards,
> > >
> > > John
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > > For additional commands, e-mail: users-help@httpd.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by Mitchell Krog Photography <mi...@gmail.com>.
What does

sudo systemctl edit --full httpd

show you ???




From: John Iliffe <jo...@iliffe.ca> <jo...@iliffe.ca>
Reply: users@httpd.apache.org <us...@httpd.apache.org>
<us...@httpd.apache.org>
Date: 28 March 2017 at 4:35:52 PM
To: users@httpd.apache.org <us...@httpd.apache.org> <us...@httpd.apache.org>
Subject:  Re: [users@httpd] Run Control for Apache in Fedora 25

Thank you Mickey.

That is exactly what the problem is; all /var/run subdirectories get
deleted on reboot.

I tried to move the pid file to another location, for a start its default
location under the apache install directory, but even directly on
/var/run/, with the result that systemctl could not find it. The pid file
was written correctly, under the correct name, and was readable by root,
but was reported as missing by systemctl and as a result the "systemctl
stop httpd" command didn't work. It just issued an error message and httpd
kept right on running.

One trhing that I have been careful to do is keep the start up script at
init.d/httpd pointed at the same location as httpd.conf.

I'm not sure why but systemctl seems to insist that that the httpd pid file
be exactly /var/run/httpd/httpd.pid .

I think there must be a configuration parameter somewhere for systemctl but
I have not been able to find it; can't believe it would be hard coded in
the
programme!

That said, thank you for the reply. It does give me the idea that I am on
the right track.

John
===========================================

On Tuesday 28 March 2017 03:05:31 Mickey Nordstrom wrote:
> Hi John,
>
> I didn't read your full post so apologies if I'm not answering your
> question. I have had similar problems on SuSE Linux whith systemd and
> the solution was to create a file under /etc/tmpfiles.d with content
> something like this:
>
> d /var/run/httpd 770 webservd webservd
>
> Modify it to the user and group that runs your httpd daemon.
>
> This is needed because /run and /var/run are volatile and gets cleaned
> out at each reboot.
>
> /Mikael
>
> On 28/03/17 04:22, John Iliffe wrote:
> > First, I know this is probably not an Apache question, but I'm hoping
> > that someone on this list may have seen this problem before and knows
> > the solution.
> >
> > I know this is going to be very long winded, my apologies in advance,
> > but I have done quite a bit of research so I have a good idea what
> > won't work :-(
> >
> > Problem:
> >
> > OS is Fedora 25
> >
> > Fedora replaces service with systemctl control using service files for
> > starting and stopping daemons. This is a bit different than the
> > traditional init.d approach.
> >
> > I installed Apache-2.4.25 from source without using the Fedora
> > installation so I had to produce my own start up scripts and used the
> > compatibility feature of systemctl so httpd can be started from
> > /etc/init.d/httpd
> >
> > My startup script works perfectly UNTIL I reboot. At that point the
> > directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets
> > deleted. I have a good idea of why this happens; it is this line in
> >
> > /etc/rc.d/init.d/functions which runs during shutdown or reboot:
> > rm -f "${pid_file:-/var/run/$base.pid}"
> >
> > It is obvious that $base includes the httpd/ subdirectory so that gets
> > deleted too.
> >
> > Changing the pid file location away from /var/run/httpd/ can't be
> > done. Even if the start up script in init.d is changed systemctl
> > expects to find it there. So I changed the httpd.conf file to put it
> > where systemctl wants it to be.
> >
> > In case anyone wonders, I can put the pid file anywhere during start
> > up but if I do that systemctl hangs and then times out during startup
> > with a message that the pid file is unreadable, leaving httpd running
> > and an orphan. Also "systemctl stop httpd" hangs and httpd stays up.
> > In this one case, "systemctl reboot" never completes; you end up
> > having to push the reset button; although I would assume that in the
> > fullness of time it might time out.
> >
> > "systemctl status httpd" in this case shows that httpd is NOT running
> > due to a missing resource (the pid file) even though it is up and
> > running fine.
> >
> > There is one obvious work-around, check for /var/run/httpd on startup
> > in the init.d script, and it it isn't there, create it, but that begs
> > the question of what am I not understanding.
> >
> > So, has anyone encountered this before. I sure hope it isn't a fat
> > finger error on my part but two days is enough for something like
> > this. I need help!
> >
> > Here is the relevant part of the (current) httpd.conf file in
> > /usr/apache-2.4.25/conf/httpd.conf
> >
> > # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> > # relocate the pid file to the default location
> > PidFile /var/run/httpd/httpd.pid
> > #
> >
> > and here is the complete init.d/httpd startup script. Mostly it was
> > cribbed from the old server's (RHEL6 and apache-2.4.10) script. A
> > lot of the commented lines are where I have been trying to find a
> > solution to the problem. In general, one # is Red Hat's comments and
> > two ## is my testing.
> >
> > #!/bin/bash
> > #
> > # httpd Startup script for the Apache HTTP Server
> > #
> > # chkconfig: - 85 15
> > # description: The Apache HTTP Server is an efficient and extensible
> > \ # server implementing the current HTTP standards. #
> > processname: httpd
> > # config: /etc/httpd/conf/httpd.conf
> > # config: /etc/sysconfig/httpd
> > # pidfile: /var/run/httpd/httpd.pid
> > #
> > ### BEGIN INIT INFO
> > # Provides: httpd
> > # Required-Start: $local_fs $remote_fs $network $named
> > # Required-Stop: $local_fs $remote_fs $network
> > # Should-Start: distcache
> > # Default-Start: 2 3 4 5
> > # Default-Stop: 0 1 6
> > # Short-Description: start and stop Apache HTTP Server
> > # Description: The Apache HTTP Server is an extensible server
> > # implementing the current HTTP standards.
> > ### END INIT INFO
> >
> > # Source function library.
> > . /etc/rc.d/init.d/functions
> >
> > if [ -f /etc/sysconfig/httpd ]; then
> >
> > . /etc/sysconfig/httpd
> >
> > fi
> >
> > # Start httpd in the C locale by default.
> > HTTPD_LANG=${HTTPD_LANG-"C"}
> >
> > # This will prevent initlog from swallowing up a pass-phrase prompt if
> > # mod_ssl needs a pass-phrase from the user.
> > INITLOG_ARGS=""
> >
> > # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a
> > server # with the thread-based "worker" MPM; BE WARNED that some
> > modules may not # work correctly with a thread-based MPM; notably PHP
> > will refuse to start. # Path to the apachectl script, server binary,
> > and short-form for messages. # This was damaged by Red Hat system
> > update 23/4/2013. Changed back to # probable initial code.
> > #
> > # Converted for new prod04 server 26/3/2017 JI
> > #
> > ## apachectl=/usr/sbin/apachectl
> > apachectl=/usr/apache-2.4.25/bin/apachectl
> > ## httpd=${HTTPD-/usr/sbin/httpd}
> > httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> > prog=httpd
> > pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> > ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this
> > doesn't work
> > lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> > RETVAL=0
> > STOP_TIMEOUT=${STOP_TIMEOUT-10}
> >
> > # The semantics of these two functions differ from the way apachectl
> > does # things -- attempting to start while running is a failure, and
> > shutdown # when not running is also a failure. So we just do it the
> > way init scripts
> > # are expected to behave here.
> > start() {
> >
> > echo -n $"Starting $prog: "
> >
> > ## LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
> >
> > $apachectl -k start
> >
> > RETVAL=$?
> > echo
> > [ $RETVAL = 0 ] && touch ${lockfile}
> > return $RETVAL
> >
> > }
> >
> > # When stopping httpd, a delay (of default 10 second) is required
> > # before SIGKILLing the httpd parent; this gives enough time for the
> > # httpd parent to SIGKILL any errant children.
> > stop() {
> >
> > echo -n $"Stopping $prog: "
> >
> > ## killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
> >
> > $apachectl -k stop
> >
> > RETVAL=$?
> > echo
> >
> > ## [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> >
> > [ $RETVAL = 0 ]
> >
> > }
> >
> > reload() {
> >
> > echo -n $"Reloading $prog: "
> > if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
> >
> > RETVAL=6
> > echo $"not reloading due to configuration syntax error"
> > failure $"not reloading $httpd due to configuration syntax
> > error"
> >
> > else
> >
> > # Force LSB behaviour from killproc
> >
> > # LSB=1 killproc -p ${pidfile} $httpd -HUP
> >
> > $apachectl -k restart
> >
> > RETVAL=$?
> > if [ $RETVAL -eq 7 ]; then
> >
> > failure $"httpd shutdown"
> >
> > fi
> >
> > fi
> > echo
> >
> > }
> >
> > # See how we were called.
> > case "$1" in
> >
> > start)
> >
> > start
> > ;;
> >
> > stop)
> >
> > stop
> > ;;
> >
> > status)
> >
> > status -p ${pidfile} $httpd
> > RETVAL=$?
> > ;;
> >
> > restart)
> >
> > stop
> > ;;
> >
> > status)
> >
> > status -p ${pidfile} $httpd
> > RETVAL=$?
> > ;;
> >
> > restart)
> >
> > stop
> > start
> > ;;
> >
> > condrestart|try-restart)
> >
> > if status -p ${pidfile} $httpd >&/dev/null; then
> >
> > stop
> > start
> >
> > fi
> > ;;
> >
> > force-reload|reload)
> >
> > reload
> > ;;
> >
> > graceful|help|configtest|fullstatus)
> >
> > $apachectl $@
> > RETVAL=$?
> > ;;
> >
> > *)
> >
> > echo $"Usage: $prog
> > {start|stop|restart|condrestart|try-restart|
> >
> > force-reload|reload|status|fullstatus|graceful|help|configtest}"
> >
> > RETVAL=2
> >
> > esac
> >
> > exit $RETVAL
> >
> >
> > FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.
> > They were created automatically when I ran "systemctl enable" on
> > httpd.
> >
> > Any suggestions as to where to go next would be appreciated!
> >
> > Regards,
> >
> > John
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by John Iliffe <jo...@iliffe.ca>.
Thank you Mickey.

That is exactly what the problem is; all /var/run subdirectories get 
deleted on reboot.

I tried to move the pid file to another location, for a start its default 
location under the apache install directory, but even directly on 
/var/run/, with the result that systemctl could not find it.  The pid file 
was written correctly, under the correct name, and was readable by root, 
but was reported as missing by systemctl and as a result the "systemctl 
stop httpd" command didn't work.  It just issued an error message and httpd 
kept right on running.

One trhing that I have been careful to do is keep the start up script at 
init.d/httpd pointed at the same location as httpd.conf.

I'm not sure why but systemctl seems to insist that that the httpd pid file 
be exactly  /var/run/httpd/httpd.pid .

I think there must be a configuration parameter somewhere for systemctl but 
I have not been able to find it; can't believe it would be hard coded in the 
programme!

That said, thank you for the reply.  It does give me the idea that I am on 
the right track.

John
===========================================

On Tuesday 28 March 2017 03:05:31 Mickey Nordstrom wrote:
> Hi John,
> 
> I didn't read your full post so apologies if I'm not answering your
> question. I have had similar problems on SuSE Linux whith systemd and
> the solution was to create a file under /etc/tmpfiles.d with content
> something like this:
> 
> d  /var/run/httpd 770 webservd webservd
> 
> Modify it to the user and group that runs your httpd daemon.
> 
> This is needed because /run and /var/run are volatile and gets cleaned
> out at each reboot.
> 
> /Mikael
> 
> On 28/03/17 04:22, John Iliffe wrote:
> > First, I know this is probably not an Apache question, but I'm hoping
> > that someone on this list may have seen this problem before and knows
> > the solution.
> > 
> > I know this is going to be very long winded, my apologies in advance,
> > but I have done quite a bit of research so I have a good idea what
> > won't work :-(
> > 
> > Problem:
> > 
> > OS is Fedora 25
> > 
> > Fedora replaces service with systemctl control using service files for
> > starting and stopping daemons.  This is a bit different than the
> > traditional init.d approach.
> > 
> > I installed Apache-2.4.25 from source without using the Fedora
> > installation so I had to produce my own start up scripts and used the
> > compatibility feature of systemctl so httpd can be started from
> > /etc/init.d/httpd
> > 
> > My startup script works perfectly UNTIL I reboot.  At that point the
> > directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets
> > deleted. I have a good idea of why this happens; it is this line in
> > 
> > /etc/rc.d/init.d/functions which runs during shutdown or reboot:
> > 	rm -f "${pid_file:-/var/run/$base.pid}"
> > 
> > It is obvious that $base includes the httpd/ subdirectory so that gets
> > deleted too.
> > 
> > Changing the pid file location away from /var/run/httpd/ can't be
> > done. Even if the start up script in init.d is changed systemctl
> > expects to find it there.  So I changed the httpd.conf file to put it
> > where systemctl wants it to be.
> > 
> > In case anyone wonders, I can put the pid file anywhere during start
> > up but if I do that systemctl hangs and then times out during startup
> > with a message that the pid file is unreadable, leaving httpd running
> > and an orphan. Also "systemctl stop httpd" hangs and httpd stays up. 
> > In this one case, "systemctl reboot" never completes; you end up
> > having to push the reset button; although I would assume that in the
> > fullness of time it might time out.
> > 
> > "systemctl status httpd" in this case shows that httpd is NOT running
> > due to a missing resource (the pid file) even though it is up and
> > running fine.
> > 
> > There is one obvious work-around, check for /var/run/httpd on startup
> > in the init.d script, and it it isn't there, create it, but that begs
> > the question of what am I not understanding.
> > 
> > So, has anyone encountered this before.  I sure hope it isn't a fat
> > finger error on my part but two days is enough for something like
> > this.  I need help!
> > 
> > Here is the relevant part of the (current) httpd.conf file in
> > /usr/apache-2.4.25/conf/httpd.conf
> > 
> > # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> > #       relocate the pid file to the default location
> > PidFile /var/run/httpd/httpd.pid
> > #
> > 
> > and here is the complete init.d/httpd startup script. Mostly it was
> > cribbed from the old server's (RHEL6 and apache-2.4.10) script.  A
> > lot of the commented lines are where I have been trying to find a
> > solution to the problem.  In general, one # is Red Hat's comments and
> > two ## is my testing.
> > 
> > #!/bin/bash
> > #
> > # httpd        Startup script for the Apache HTTP Server
> > #
> > # chkconfig: - 85 15
> > # description: The Apache HTTP Server is an efficient and extensible 
> > \ #              server implementing the current HTTP standards. #
> > processname: httpd
> > # config: /etc/httpd/conf/httpd.conf
> > # config: /etc/sysconfig/httpd
> > # pidfile: /var/run/httpd/httpd.pid
> > #
> > ### BEGIN INIT INFO
> > # Provides: httpd
> > # Required-Start: $local_fs $remote_fs $network $named
> > # Required-Stop: $local_fs $remote_fs $network
> > # Should-Start: distcache
> > # Default-Start: 2 3 4 5
> > # Default-Stop: 0 1 6
> > # Short-Description: start and stop Apache HTTP Server
> > # Description: The Apache HTTP Server is an extensible server
> > #  implementing the current HTTP standards.
> > ### END INIT INFO
> > 
> > # Source function library.
> > . /etc/rc.d/init.d/functions
> > 
> > if [ -f /etc/sysconfig/httpd ]; then
> > 
> >         . /etc/sysconfig/httpd
> > 
> > fi
> > 
> > # Start httpd in the C locale by default.
> > HTTPD_LANG=${HTTPD_LANG-"C"}
> > 
> > # This will prevent initlog from swallowing up a pass-phrase prompt if
> > # mod_ssl needs a pass-phrase from the user.
> > INITLOG_ARGS=""
> > 
> > # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a
> > server # with the thread-based "worker" MPM; BE WARNED that some
> > modules may not # work correctly with a thread-based MPM; notably PHP
> > will refuse to start. # Path to the apachectl script, server binary,
> > and short-form for messages. # This was damaged by Red Hat system
> > update 23/4/2013.  Changed back to # probable initial code.
> > #
> > # Converted for new prod04 server 26/3/2017 JI
> > #
> > ## apachectl=/usr/sbin/apachectl
> > apachectl=/usr/apache-2.4.25/bin/apachectl
> > ## httpd=${HTTPD-/usr/sbin/httpd}
> > httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> > prog=httpd
> > pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> > ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this
> > doesn't work
> > lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> > RETVAL=0
> > STOP_TIMEOUT=${STOP_TIMEOUT-10}
> > 
> > # The semantics of these two functions differ from the way apachectl
> > does # things -- attempting to start while running is a failure, and
> > shutdown # when not running is also a failure.  So we just do it the
> > way init scripts
> > # are expected to behave here.
> > start() {
> > 
> >         echo -n $"Starting $prog: "
> > 
> > ##        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
> > 
> >     $apachectl -k start
> >     
> >         RETVAL=$?
> >         echo
> >         [ $RETVAL = 0 ] && touch ${lockfile}
> >         return $RETVAL
> > 
> > }
> > 
> > # When stopping httpd, a delay (of default 10 second) is required
> > # before SIGKILLing the httpd parent; this gives enough time for the
> > # httpd parent to SIGKILL any errant children.
> > stop() {
> > 
> >         echo -n $"Stopping $prog: "
> > 
> > ##      killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
> > 
> >     $apachectl -k stop
> >     
> >         RETVAL=$?
> >         echo
> > 
> > ##       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
> > 
> >         [ $RETVAL = 0 ]
> > 
> > }
> > 
> > reload() {
> > 
> >     echo -n $"Reloading $prog: "
> >     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
> >     
> >         RETVAL=6
> >         echo $"not reloading due to configuration syntax error"
> >         failure $"not reloading $httpd due to configuration syntax
> >         error"
> >     
> >     else
> >     
> >         # Force LSB behaviour from killproc
> > 
> > #        LSB=1 killproc -p ${pidfile} $httpd -HUP
> > 
> >     $apachectl -k restart
> >     
> >         RETVAL=$?
> >         if [ $RETVAL -eq 7 ]; then
> >         
> >             failure $"httpd shutdown"
> >         
> >         fi
> >     
> >     fi
> >     echo
> > 
> > }
> > 
> > # See how we were called.
> > case "$1" in
> > 
> >   start)
> >   
> >         start
> >         ;;
> >   
> >   stop)
> >   
> >         stop
> >         ;;
> >   
> >   status)
> >   
> >         status -p ${pidfile} $httpd
> >         RETVAL=$?
> >         ;;
> >   
> >   restart)
> >   
> >         stop
> >         ;;
> >   
> >   status)
> >   
> >         status -p ${pidfile} $httpd
> >         RETVAL=$?
> >         ;;
> >   
> >   restart)
> >   
> >         stop
> >         start
> >         ;;
> >   
> >   condrestart|try-restart)
> >   
> >         if status -p ${pidfile} $httpd >&/dev/null; then
> >         
> >                 stop
> >                 start
> >         
> >         fi
> >         ;;
> >   
> >   force-reload|reload)
> >   
> >         reload
> >         ;;
> >   
> >   graceful|help|configtest|fullstatus)
> >   
> >         $apachectl $@
> >         RETVAL=$?
> >         ;;
> >   
> >   *)
> >   
> >         echo $"Usage: $prog
> >         {start|stop|restart|condrestart|try-restart|
> > 
> > force-reload|reload|status|fullstatus|graceful|help|configtest}"
> > 
> >         RETVAL=2
> > 
> > esac
> > 
> > exit $RETVAL
> > 
> > 
> > FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories. 
> > They were created automatically when I ran "systemctl enable" on
> > httpd.
> > 
> > Any suggestions as to where to go next would be appreciated!
> > 
> > Regards,
> > 
> > John
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Run Control for Apache in Fedora 25

Posted by Mickey Nordstrom <mi...@gmail.com>.
Hi John,

I didn't read your full post so apologies if I'm not answering your question.
I have had similar problems on SuSE Linux whith systemd and the solution
was to create a file under /etc/tmpfiles.d with content something like this:

d  /var/run/httpd 770 webservd webservd

Modify it to the user and group that runs your httpd daemon.

This is needed because /run and /var/run are volatile and gets cleaned out
at each reboot.

/Mikael

On 28/03/17 04:22, John Iliffe wrote:
> First, I know this is probably not an Apache question, but I'm hoping that 
> someone on this list may have seen this problem before and knows the 
> solution.
>
> I know this is going to be very long winded, my apologies in advance, but I 
> have done quite a bit of research so I have a good idea what won't work :-(
>
> Problem:
>
> OS is Fedora 25
>
> Fedora replaces service with systemctl control using service files for 
> starting and stopping daemons.  This is a bit different than the traditional 
> init.d approach.  
>
> I installed Apache-2.4.25 from source without using the Fedora installation 
> so I had to produce my own start up scripts and used the compatibility 
> feature of systemctl so httpd can be started from /etc/init.d/httpd
>
> My startup script works perfectly UNTIL I reboot.  At that point the 
> directory where httpd.pid resides (/var/run/httpd/httpd.pid) gets deleted.  
> I have a good idea of why this happens; it is this line in 
> /etc/rc.d/init.d/functions which runs during shutdown or reboot:
>
> 	rm -f "${pid_file:-/var/run/$base.pid}"
>
> It is obvious that $base includes the httpd/ subdirectory so that gets 
> deleted too.
>
> Changing the pid file location away from /var/run/httpd/ can't be done.  
> Even if the start up script in init.d is changed systemctl expects to find 
> it there.  So I changed the httpd.conf file to put it where systemctl wants 
> it to be.
>
> In case anyone wonders, I can put the pid file anywhere during start up but 
> if I do that systemctl hangs and then times out during startup with a 
> message that the pid file is unreadable, leaving httpd running and an 
> orphan. Also "systemctl stop httpd" hangs and httpd stays up.  In this one  
> case, "systemctl reboot" never completes; you end up having to push the 
> reset button; although I would assume that in the fullness of time it might 
> time out.
>
> "systemctl status httpd" in this case shows that httpd is NOT running due 
> to a missing resource (the pid file) even though it is up and running fine.
>
> There is one obvious work-around, check for /var/run/httpd on startup in 
> the init.d script, and it it isn't there, create it, but that begs the 
> question of what am I not understanding.  
>
> So, has anyone encountered this before.  I sure hope it isn't a fat finger 
> error on my part but two days is enough for something like this.  I need 
> help!
>
> Here is the relevant part of the (current) httpd.conf file in 
> /usr/apache-2.4.25/conf/httpd.conf 
>
> # Added with 2.4.25, 25/3/2017, to work with Fedora which won't
> #       relocate the pid file to the default location
> PidFile /var/run/httpd/httpd.pid
> #
>
> and here is the complete init.d/httpd startup script. Mostly it was cribbed 
> from the old server's (RHEL6 and apache-2.4.10) script.  A lot of the 
> commented lines are where I have been trying to find a solution to the 
> problem.  In general, one # is Red Hat's comments and two ## is my testing.
>
> #!/bin/bash
> #
> # httpd        Startup script for the Apache HTTP Server
> #
> # chkconfig: - 85 15
> # description: The Apache HTTP Server is an efficient and extensible  \
> #              server implementing the current HTTP standards.
> # processname: httpd
> # config: /etc/httpd/conf/httpd.conf
> # config: /etc/sysconfig/httpd
> # pidfile: /var/run/httpd/httpd.pid
> #
> ### BEGIN INIT INFO
> # Provides: httpd
> # Required-Start: $local_fs $remote_fs $network $named
> # Required-Stop: $local_fs $remote_fs $network
> # Should-Start: distcache
> # Default-Start: 2 3 4 5
> # Default-Stop: 0 1 6
> # Short-Description: start and stop Apache HTTP Server
> # Description: The Apache HTTP Server is an extensible server
> #  implementing the current HTTP standards.
> ### END INIT INFO
>
> # Source function library.
> . /etc/rc.d/init.d/functions
>
> if [ -f /etc/sysconfig/httpd ]; then
>         . /etc/sysconfig/httpd
> fi
>
> # Start httpd in the C locale by default.
> HTTPD_LANG=${HTTPD_LANG-"C"}
>
> # This will prevent initlog from swallowing up a pass-phrase prompt if
> # mod_ssl needs a pass-phrase from the user.
> INITLOG_ARGS=""
>
> # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
> # with the thread-based "worker" MPM; BE WARNED that some modules may not
> # work correctly with a thread-based MPM; notably PHP will refuse to start.
> # Path to the apachectl script, server binary, and short-form for messages.
> # This was damaged by Red Hat system update 23/4/2013.  Changed back to
> # probable initial code.
> #
> # Converted for new prod04 server 26/3/2017 JI
> #
> ## apachectl=/usr/sbin/apachectl
> apachectl=/usr/apache-2.4.25/bin/apachectl
> ## httpd=${HTTPD-/usr/sbin/httpd}
> httpd=${HTTPD-/usr/apache-2.4.25/bin/httpd}
> prog=httpd
> pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
> ##>>>pidfile=${PIDFILE-/usr/apache-2.4.25/logs/httpd.pid} <<-- this doesn't 
> work
> lockfile=${LOCKFILE-/var/lock/subsys/httpd}
> RETVAL=0
> STOP_TIMEOUT=${STOP_TIMEOUT-10}
>
> # The semantics of these two functions differ from the way apachectl does
> # things -- attempting to start while running is a failure, and shutdown
> # when not running is also a failure.  So we just do it the way init 
> scripts
> # are expected to behave here.
> start() {
>         echo -n $"Starting $prog: "
> ##        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
>     $apachectl -k start
>         RETVAL=$?
>         echo
>         [ $RETVAL = 0 ] && touch ${lockfile}
>         return $RETVAL
> }
>
> # When stopping httpd, a delay (of default 10 second) is required
> # before SIGKILLing the httpd parent; this gives enough time for the
> # httpd parent to SIGKILL any errant children.
> stop() {
>         echo -n $"Stopping $prog: "
> ##      killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
>     $apachectl -k stop
>         RETVAL=$?
>         echo
> ##       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
>         [ $RETVAL = 0 ]
> }
>
> reload() {
>     echo -n $"Reloading $prog: "
>     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
>         RETVAL=6
>         echo $"not reloading due to configuration syntax error"
>         failure $"not reloading $httpd due to configuration syntax error"
>     else
>         # Force LSB behaviour from killproc
> #        LSB=1 killproc -p ${pidfile} $httpd -HUP
>     $apachectl -k restart
>         RETVAL=$?
>         if [ $RETVAL -eq 7 ]; then
>             failure $"httpd shutdown"
>         fi
>     fi
>     echo
> }
>
> # See how we were called.
> case "$1" in
>   start)
>         start
>         ;;
>   stop)
>         stop
>         ;;
>   status)
>         status -p ${pidfile} $httpd
>         RETVAL=$?
>         ;;
>   restart)
>         stop
>         ;;
>   status)
>         status -p ${pidfile} $httpd
>         RETVAL=$?
>         ;;
>   restart)
>         stop
>         start
>         ;;
>   condrestart|try-restart)
>         if status -p ${pidfile} $httpd >&/dev/null; then
>                 stop
>                 start
>         fi
>         ;;
>   force-reload|reload)
>         reload
>         ;;
>   graceful|help|configtest|fullstatus)
>         $apachectl $@
>         RETVAL=$?
>         ;;
>   *)
>         echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|
> force-reload|reload|status|fullstatus|graceful|help|configtest}"
>         RETVAL=2
> esac
>
> exit $RETVAL
>
>
> FYI, the usual "S" and "K" links are in /etc/rc[1-6].d directories.  They 
> were created automatically when I ran "systemctl enable" on httpd.
>
> Any suggestions as to where to go next would be appreciated!
>
> Regards,
>
> John
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org