How to uninstall OS X Server 5

There was a time when OS X Server was so different that it had its own kernel, but more recently – since Lion Server in 2011 – Apple has provided it within a neat little sandboxed App Store app. In theory, all you should need to do to uninstall it is to drag that app to the Trash. In practice it is more complex than this.

Stopping services

Before doing anything on the server, ensure that all systems which use its services are disconnected from them, and configured not to rely on those services. Then open Server.app, connect to the local copy of Server, and shut down all its services except for Open Directory. In the Advanced services, open Open Directory, and if it is running, select the Open Directory Master and delete it. That should leave that last service turned off, and its data destroyed.

In Server.app, you can now make an archive of the server configuration if you wish to return to it at a later time. Then quit Server.app.

You next need to wipe the various databases left by Server. Apple provides a script for doing this, inside Server.app, in the path Server.app/Contents/ServerRoot/usr/share/devicemgr/backend/wipeDB.sh, which you can run by double-clicking.

Alternatively, open Terminal and type the command
/Applications/Server.app/Contents/ServerRoot/usr/share/devicemgr/config/wipeDB

Either way, you will next be asked to authenticate with your admin user password. Terminal should then display output like
Stopping devicemgrd...
Stopping PostgreSQL...
Restarting PostgreSQL...
Starting dmpgHelper...
Starting scep_helper...
Running migration_tool...

then at the end
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...12 completed.

Trashing files and folders

It should now be safe to put Server.app into the Trash, which will require you to authenticate.

The final task is to clean up various locations in which Server has been storing various data. First put the /Library/Server folder into the Trash (authenticating), and clean up /Library/Preferences by trashing the few items with names starting com.apple which contain server or servermgr.

You then need to remove the /var/servermgrd folder, either in Terminal, or using Finder’s Go command to open the /var folder.

While you are there, check in /var/db for a hidden file named something like .ServerSetupDone or similar: it should have gone, but if it has not, delete it.

The final step, which is optional, is to open Keychain Access, where you can remove various security certificates for Open Directory and Server.

Re-installing

If you now want to install a fresh copy of Server once again, you can drag Server.app from the Trash back into Applications. If you do not want to do so, empty the Trash and restart.

At any time in the future, you can download a fresh copy from the App Store, or copy the app back from your Time Machine backup.

Thanks to Todd Olthoff for explaining and demonstrating the basic process, on which I have based my account above.