We recently ran into a tricky situation with a custom SMF service we maintain on our Joyent SmartOS hosts. The namespace for the service instance (defined in upstream code) had changed, which meant that as our Chef automation upgraded the service instances to the latest code, we ended up with a lot of duplicate service instances that each had a unique namespace.
After wrestling with the best way to batch delete/reinstall the service (using Chef's knife cli), we found a way to improve our old process.
Normally, we would delete services with something like svccfg delete <service_name>, but this doesn't work well if you need to delete a number of services, especially if they have similar namespaces. Further, we found that running this in a loop against the output of svcs -a -H | grep <service_name> wasn't effective because service configurations could linger even after the service instance had been deleted.
Digging into man svccfg, we came up with a way to enumerate services and service configurations more cleanly with svccfg:
for service in $(svccfg list | grep nad); do sudo svcadm disable -s $service done for instance in $(svccfg list | grep nad); do sudo svccfg delete $instance done