How to unregister “httpd” after “wfsctl stop”

high sierrahttpwebdav

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 the httpd process. However, the httpd daemons are stopped and restarted. Also, httpd remains registered to start on the next (re)boot.

sudo wfsctl diagnose
# All httpd processes:
# COMM   RUSER   PPID   PID STARTED
# httpd  root       1   325  8:46PM
# httpd  _www     325   331  8:46PM
sudo wfsctl stop
sudo wfsctl diagnose
# All httpd processes:
# COMM    RUSER  PPID   PID STARTED
# httpd   root      1   399 10:19PM
# httpd   _www    399   403 10:19PM

The man wfsctl mentions that the use of httpd-wrapper is preferred to the use of apachectl and httpd (at least for the -t test flag.)

The Apache config file for WebDAV File Sharing is parameterized, and the httpd server is managed by the httpd-wrapper utility, which passes parameters to httpd. This is normally transparent, but note that to check the Apache config file syntax, do not use apachectl configtest or httpd -t. Instead, use httpd-wrapper -t.

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 the httpd daemons and leaves httpd registered to start when the system boots again.

Finally, sudo apachectl graceful-stop was found to stop and unregister the httpd processes.

So, the following command sequence will stop both the wfsctl WebDAV sharing and the httpd daemons on the current High Sierra.

sudo wfsctl stop
# Unloaded and removed: org.apache.httpd.webdavfilesharing.username-275.49176.plist
sudo apachectl graceful-stop
# verify
sudo wfsctl diagnose

See "How to set up wfsctl WebDAV to use with an application that uses basic authentication?" for a more complete WebDAV example.