Automating OS X Server with the serverctl command

Apple has been building new options like serverctl to automate server setups again

apple logo mac
Credit: flickr/Hakan Dahlstrom

OS X Server provides a solid contribution to many environments. Services such as the Software Update service, Profile Manager, the Caching service, and many others provide a unique benefit and increase the viability of Mac and iOS deployment. 

Once upon a time, we had tools like AutoServerSetup, a file that could be deployed to automate server setups. Ever since OS X Server became an app that you deploy on a Mac Mini, it's become increasingly difficult to deploy en masse. But while deploying OS X Server can seem like a pretty manual process, Apple has quietly been building new options and features behind the scenes. One of these new options is serverctl, located in /Applications/Server.app/Contents/ServerRoot/usr/sbin/. The serverctl command is pretty simple to use. To get started, run it with the list verb:

serverctl list

The output shows the services that are enabled in an enabledServices section and those that are disabled in a disabledServices section, as follows:

{
    disabledServices =     (
    "com.apple.AccountsConfigService",
        "com.apple.afctl",
        "com.apple.AssetCache",
        "com.apple.authserver",
        "com.apple.collabd.preview",
        "com.apple.collabd.quicklook",
        "com.apple.ftpserver",
        "com.apple.list_server_mgr",
        "com.apple.mail_exclusion",
        "com.apple.mail_periodic_tasks",
        "com.apple.ppp.l2tp",
        "com.apple.ppp.pptp",
        "com.apple.push_notify",
        "com.apple.Rooms",
        "com.apple.salearn",
        "com.apple.saupdate",
        "com.apple.server.filesharing",
        "com.apple.server.netboot",
        "com.apple.server.opendirectory",
        "com.apple.serverdocs.postgres",
        "com.apple.serverdocs.quicklook",
        "com.apple.serverdocs.sdd",
        "com.apple.serverdocs.sdhd",
        "com.apple.serverdocs.sdmd",
        "com.apple.servermgrd.listener",
        "com.apple.swupdate.host",
        "com.apple.swupdate.sync",
        "org.amavis.amavisd",
        "org.amavis.amavisd_cleanup",
        "org.calendarserver.calendarserver",
        "org.clamav.clamd",
        "org.clamav.freshclam",
        "org.dovecot.dovecotd",
        "org.dovecot.fts.update",
        "org.freeradius.radiusd",
        "org.jabber.jabberd",
        "org.jabber.proxy65",
        "org.postfix.master.active"
    );
    enabledServices =     (
        "com.apple.apspd",
        "com.apple.collabd.expire",
        "com.apple.collabd.notifications",
        "com.apple.collabd",
        "com.apple.DeviceManagement.devicemgrd",
        "com.apple.DeviceManagement.dmrunnerd",
        "com.apple.DeviceManagement.php-fpm",
        "com.apple.DeviceManagement.postgres",
        "com.apple.DeviceManagement.SCEPHelper",
        "com.apple.disks.smart.status",
        "com.apple.server.alertsd",
        "com.apple.server.eventsd",
        "com.apple.server.httpd",
        "com.apple.server.v2.stats",
        "com.apple.ServerEventAgent",
        "com.apple.servermetricsd.daemon",
        "com.apple.servermetricsd.sample",
        "com.apple.servermgrd.backend",
        "org.calendarserver.agent",
        "org.calendarserver.archive",
        "org.calendarserver.relocate",
        "org.isc.named",
        "org.postfix.master.passive",
        "com.apple.servermgrd.accounts",
        "com.apple.servermgrd.addressbook",
        "com.apple.servermgrd.afp",
        "com.apple.servermgrd.alerts",
        "com.apple.servermgrd.bonjour",
        "com.apple.servermgrd.caching",
        "com.apple.servermgrd.calendar",
        "com.apple.servermgrd.certs",
        "com.apple.servermgrd.collabd",
        "com.apple.servermgrd.config",
        "com.apple.servermgrd.devicemgr",
        "com.apple.servermgrd.dhcp",
        "com.apple.servermgrd.dirserv",
        "com.apple.servermgrd.dns",
        "com.apple.servermgrd.documents",
        "com.apple.servermgrd.filebrowser",
        "com.apple.servermgrd.firewall",
        "com.apple.servermgrd.ftp",
        "com.apple.servermgrd.history",
        "com.apple.servermgrd.info",
        "com.apple.servermgrd.jabber",
        "com.apple.servermgrd.mail",
        "com.apple.servermgrd.netboot",
        "com.apple.servermgrd.network",
        "com.apple.servermgrd.nfs",
        "com.apple.servermgrd.radius",
        "com.apple.servermgrd.san",
        "com.apple.servermgrd.sharing",
        "com.apple.servermgrd.signaler",
        "com.apple.servermgrd.smb",
        "com.apple.servermgrd.status",
        "com.apple.servermgrd.swupdate",
        "com.apple.servermgrd.timemachine",
        "com.apple.servermgrd.vpn",
        "com.apple.servermgrd.web",
        "com.apple.servermgrd.wiki",
        "com.apple.servermgrd.xcode"
    );
}

The serverctl command can then be used to start services. For example, the most common service is the Caching service, started using the enable verb, followed by service and then the name of the service being started. The caching service is com.apple.AssetCache, so the command to start the service is:

serverctl enable service=com.apple.AssetCache

Run serverctl along with the list verb again to see that the com.apple.AssetCache service has started:

{
    disabledServices =     (
        "com.apple.AccountsConfigService",
        "com.apple.afctl",
        "com.apple.authserver",
        "com.apple.collabd.preview",
        "com.apple.collabd.quicklook",
        "com.apple.ftpserver",
        "com.apple.list_server_mgr",
        "com.apple.mail_exclusion",
        "com.apple.mail_periodic_tasks",
        "com.apple.ppp.l2tp",
        "com.apple.ppp.pptp",
        "com.apple.push_notify",
        "com.apple.Rooms",
        "com.apple.salearn",
        "com.apple.saupdate",
        "com.apple.server.filesharing",
        "com.apple.server.netboot",
        "com.apple.server.opendirectory",
        "com.apple.serverdocs.postgres",
        "com.apple.serverdocs.quicklook",
        "com.apple.serverdocs.sdd",
        "com.apple.serverdocs.sdhd",
        "com.apple.serverdocs.sdmd",
        "com.apple.servermgrd.listener",
        "com.apple.swupdate.host",
        "com.apple.swupdate.sync",
        "org.amavis.amavisd",
        "org.amavis.amavisd_cleanup",
        "org.calendarserver.calendarserver",
        "org.clamav.clamd",
        "org.clamav.freshclam",
        "org.dovecot.dovecotd",
        "org.dovecot.fts.update",
        "org.freeradius.radiusd",
        "org.jabber.jabberd",
        "org.jabber.proxy65",
        "org.postfix.master.active",
        "com.apple.servermgrd.xcode"
    );
    enabledServices =     (
        "com.apple.apspd",
        "com.apple.AssetCache",
        "com.apple.collabd.expire",
        "com.apple.collabd.notifications",
        "com.apple.collabd",
        "com.apple.DeviceManagement.devicemgrd",
        "com.apple.DeviceManagement.dmrunnerd",
        "com.apple.DeviceManagement.php-fpm",
        "com.apple.DeviceManagement.postgres",
        "com.apple.DeviceManagement.SCEPHelper",
        "com.apple.disks.smart.status",
        "com.apple.server.alertsd",
        "com.apple.server.eventsd",
        "com.apple.server.httpd",
        "com.apple.server.v2.stats",
        "com.apple.ServerEventAgent",
        "com.apple.servermetricsd.daemon",
        "com.apple.servermetricsd.sample",
        "com.apple.servermgrd.backend",
        "org.calendarserver.agent",
        "org.calendarserver.archive",
        "org.calendarserver.relocate",
        "org.isc.named",
        "org.postfix.master.passive",
        "com.apple.servermgrd.accounts",
        "com.apple.servermgrd.addressbook",
        "com.apple.servermgrd.afp",
        "com.apple.servermgrd.alerts",
        "com.apple.servermgrd.bonjour",
        "com.apple.servermgrd.caching",
        "com.apple.servermgrd.calendar",
        "com.apple.servermgrd.certs",
        "com.apple.servermgrd.collabd",
        "com.apple.servermgrd.config",
        "com.apple.servermgrd.devicemgr",
        "com.apple.servermgrd.dhcp",
        "com.apple.servermgrd.dirserv",
        "com.apple.servermgrd.dns",
        "com.apple.servermgrd.documents",
        "com.apple.servermgrd.filebrowser",
        "com.apple.servermgrd.firewall",
        "com.apple.servermgrd.ftp",
        "com.apple.servermgrd.history",
        "com.apple.servermgrd.info",
        "com.apple.servermgrd.jabber",
        "com.apple.servermgrd.mail",
        "com.apple.servermgrd.netboot",
        "com.apple.servermgrd.network",
        "com.apple.servermgrd.nfs",
        "com.apple.servermgrd.radius",
        "com.apple.servermgrd.san",
        "com.apple.servermgrd.sharing",
        "com.apple.servermgrd.signaler",
        "com.apple.servermgrd.smb",
        "com.apple.servermgrd.status",
        "com.apple.servermgrd.swupdate",
        "com.apple.servermgrd.timemachine",
        "com.apple.servermgrd.vpn",
        "com.apple.servermgrd.web",
        "com.apple.servermgrd.wiki"
    );
}

You can also disable the service using the serverctl command and swapping out the enable verb with the disable verb, as follows:

serverctl disable service=com.apple.AssetCache

Longtime OS X server administrators will note that you can still use the serveradmin command to configure settings. Run the command along with the settings verb and caching for the service name to see the configurable options:

serveradmin settings caching

The results show the configurable options for the caching service:

caching:ReservedVolumeSpace = 25000000000
caching:CacheLimit = 0
caching:ServerRoot = "/Library/Server"
caching:ServerGUID = "6AB229AF-37B9-42C0-951B-B5AE47E33E35"
caching:DataPath = "/Volumes/El Capitan Server/Library/Server/Caching/Data"
caching:LocalSubnetsOnly = yes
caching:Port = 0

You can then feed these back into the serveradmin command using the settings verb, the full path of the options and the new va'ue you’d like to configure. An example for using the serveradmin command would also be to configure the cache location for /Volumes/ServerData/Library/Server/Caching/Data:

serveradmin settings caching:DataPath = 
"/Volumes/ServerData/Library/Server/Caching/Data"

Run the serveradmin command with the settings verb and the service name to then see that the new setting was applied. To wrap commands in a miniature script that will stop the service, configure the location setting, and then start the service a'ain you’d use the following command:

serverctl disable service=com.apple.AssetCache
mkdir -p "/Volumes/Client/Library/Server/Caching/Data”
serveradmin settings caching:DataPath = 
"/Volumes/ServerData/Library/Server/Caching/Data" serverctl enable service=com.apple.AssetCache

In summary, you can still mass deploy a lot with OS X Server environments. Sometimes, you need to put a tad bit more work into doing s'. But it’s still a really cool solution, with a lot of options for a savvy systems administrator.

In the past 15 years, Charles S. Edge, Jr, has performed countless large-scale deployments of OS X, OS X Server and iOS. As a leader in the Apple community, Charles has written a dozen books on iOS, OS X and OS X Server. He has also spoken at a number of conferences about the Apple platform, but is mostly just proud to have worked hand-in-hand with many of the greatest contributors to the Apple community and taken some small part in the growth and success of that community.

This article is published as part of the IDG Contributor Network. Want to Join?

To comment on this article and other InfoWorld content, visit InfoWorld's LinkedIn page, Facebook page and Twitter stream.
Related:
From CIO: 8 Free Online Courses to Grow Your Tech Skills
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.