How does one properly unregister httpd
from launching at reboot following a sudo wfsctl start
and subsequent sudo wfsctl stop
?
Background:
wfsctl
is a "WebDAV File Sharing control utility" released with macOS High Sierra. wfsctl
is located at /usr/sbin/wfsctl
.
In my case, after an initial install of macOS High Sierra, the Apache httpd
daemon is not initially serving content. (This was expected.) The observation that httpd was not serving could observed in various ways, including:
- type
localhost
into a web browser on the same machine - type
curl localhost
in the terminal on the same machine.
curl localhost
# curl: (7) Failed to connect to localhost port 80: Connection refused
When the wfsctl
WebDAV services are started for the first time, then httpd
is also started.
sudo wfsctl start
# ...
sudo wfsctl diagnose
# ... snip ...
# All httpd processes:
# COMM RUSER PPID PID STARTED
# httpd root 1 885 4:18PM
# httpd _www 885 890 4:18PM
It was not surprising that an Apache httpd
was started. Although, the baseline Apache httpd
configuration also start serviing the contents of /Library/WebServer/Documents in addition to and separate from any WebDAV shares. In particular, index.html
content is returned via either localhost
in a web browser or curl localhost
in the Terminal application.
curl localhost --verbose
# * Connected to localhost (::1) port 80 (#0)
# > GET / HTTP/1.1
# > Host: localhost
# > User-Agent: curl/7.54.0
# > Accept: */*
# >
# < HTTP/1.1 200 OK
# < Server: Apache/2.4.28 (Unix) mod_secure_transport/2.4.27
# < Content-Location: index.html.en
# <html><body><h1>It works!</h1></body></html>
Finally, stop the WebDAV services with sudo wfsctl stop
, then reboot. After reboot, httpd
is apparently still running:
# after `sudo wfsctl stop` and system reboot ...
curl localhost
# <html><body><h1>It works!</h1></body></html>
sudo wfsctl status
# disabled
sudo wfsctl diagnose
# ...
# WFS is not enabled.
# ...
# All httpd processes:
# COMM RUSER PPID PID STARTED
# httpd root 1 85 6:12PM
# httpd _www 85 414 6:13PM
Footnote:
Is it a reasonably expected behaviour that sudo wfsctl stop
does not also unregister httpd
?
Perhaps wfsctl
presumes to not interfere with other services with might be used to start the httpd
web server? (Though, in my use case, httpd
was not enabled via any other means than wfsctl
.)
Best Answer
As noted in the question,
sudo wfsctl stop
does not stop and unregister thehttpd
process. However, thehttpd
daemons are stopped and restarted. Also,httpd
remains registered to start on the next (re)boot.The
man wfsctl
mentions that the use ofhttpd-wrapper
is preferred to the use ofapachectl
andhttpd
(at least for the-t
test flag.)In general, the options shown in the
man httpd
page can be passed to the/usr/sbin/httpd-wrapper
ruby script. Most of the options work as expected.However,
sudo httpd-wrapper -k graceful-stop
behaves like a reset which restarts thehttpd
daemons and leaveshttpd
registered to start when the system boots again.Finally,
sudo apachectl graceful-stop
was found to stop and unregister thehttpd
processes.So, the following command sequence will stop both the
wfsctl
WebDAV sharing and thehttpd
daemons on the current High Sierra.See "How to set up
wfsctl
WebDAV to use with an application that uses basic authentication?" for a more complete WebDAV example.