Less known Solaris features: synchronous svcadm

Sometimes small options are really useful. When you enable a service, for example the Apache HTTPD, you enter svcadm enable apache22. This command immediately return. There is no direct feedback at the command return, if the service has started. So you often see people doing something like that:

root@kusanagi:~# svcs -a| grep "apache22"
disabled       22:16:52 svc:/network/http:apache22
root@kusanagi:~# svcadm enable apache22
root@kusanagi:~# svcs -a| grep "apache22"
offline\*       22:17:20 svc:/network/http:apache22
root@kusanagi:~# svcs -a| grep "apache22"
offline\*       22:17:20 svc:/network/http:apache22
root@kusanagi:~# svcs -a| grep "apache22"
offline\*       22:17:20 svc:/network/http:apache22
root@kusanagi:~# svcs -a| grep "apache22"
offline\*       22:17:20 svc:/network/http:apache22
root@kusanagi:~# svcs -a| grep "apache22"
online         22:17:31 svc:/network/http:apache22

ust before you ask … i included a sleep 10 at the right place in the method script of the http:apache22 service to delay the startup in order to demonstrate the command. The service goes from disabled to offline(the state where a service is enabled but the startup hasn’t completed) and is flagged as a service in transition to a different state (like online) by the \*. However you can change this behaviour. When you use the -s the svcadm enable command just returns when the state transition has completed. So for example when the service got from offline to online. The svcadm command with the -s option will return as well when it determined that it can’t do the desired state transition and needs admin intervention. In our example we would use svcadm enable -s apache22. As we artificially delayed the startup of the Apache, the svcadm command should run at least 10 seconds. Let’s check this:

# ptime svcadm enable -s  apache22

real       11.137908105
user        0.012195633
sys         0.018084807

This synchronous mode works with svcadm enable as well as with svcadm disable even in Solaris 10. In Solaris 11.2 the synchronous mode was introduced to all svcadm subcommands including the mechanism to define a timeout after which the svcadm command return with an error code that the state transition hasn’t completed with the timeout. However it’s just the waiting for the state transition that is timouted, the service itself proceeds with it’s bring up.