Service Management Facility
The Service Management Facility (SMF) is the way to start and stop servers (web, database, email, and so on) and provides two distinct advantages:
It monitors services and restarts them automatically if they stop running.
It understands the dependencies between services. For example, SMF will not attempt to start your webserver if your network is down.
Basic SMF commands
SMF consists of three command line utilities:
svcs: allows you to examine the state of your services and determine what went wrong.
svcadm: enable, disable, and restart a service.
svccfg: load manifest files (XML) that maintain configurations for each service.
Examining service status with svcs
The svcs command displays information about the state of your services. This typically means whether or not they are running and any problems encountered when attempting to start them. In general, services will fall into three different states:
online: the service is enabled and functioning normally
offline: the service is stopped and disabled
maintenance: the service has encountered a problem and is on hold until the problem is addressed by an administrator.
Running the svcs
command with the -a
argument displays a list of all online and offline services. By default svcs prints out:
status: the current state of the service.
stime: when the service entered the current state.
FMRI: the name of the service.
Starting and stopping services using svcadm
The svcadm
command is used to enable, disable, restart, or refresh services. For example, this command enables the MySQL service.
# svcadm enable mariadb
Using svcs
, you can verify that the service is enabled:
# svcs mariadb
STATE STIME FMRI
online 10:35:02 svc:/database/mariadb:default
You use disable
to stop services. For example, this stops the MySQL service:
# svcadm disable mariadb
You use restart
to refresh a service. For example, after making a configuration change, you can refresh an enabled service like this:
Some daemons do not respond to the restart
command. If that is the case, you will need to disable and re-enable the service.
Counducting service maintenance using svcadm clear
If a service enters maintenance mode or becomes disabled, you will need to perform some maintenance before SMF can restart the service. This means resolving any conflicts that prevent the service from running then using svcadm clear
to clear the service state. When using svcadm clear
, you need to specify the service FMRI.
This command does nothing to fix a service, it just signals that the service is ready to resume. Before you can clear a service state, you need to ensure that you resolve the conflict that caused the service to go into maintenance mode.
Verifying a service is in maintenance mode
SMF will place a service in maintenance mode when the service encounters something that causes it to crash. This usually indicates an error with the service but can also occur if your SmartMachine is running out of resources (RAM or disk space).
To verify if a service is in maintenance mode run this command:
This will show all running and disabled services. If a service is in maintenance mode, you will see something similar to this:
Review the log to root-cause why the service was in maintenance mode.
Take the service out of maintenance mode:
Verifying a service is disabled
To verify if a service is disabled:
If the service is disabled, you will see something similar to this:
Enabling a service
Enable the service:
Verify the service is enabled:
If successful, you should see something similar to this:
The term "online" is the service state and indicates that the service is running.
Examining service contracts using svcs -p
SMF maintains a contract with every running service it manages. The contract keeps track of what processes are running for any given service. Using the -p
option, you can determine all the processes that belong to a service. In the following example, the MySQL daemon is process number 28794.
The following example demonstrates how SMF restarts a service when it stops unexpectedly:
Even though the MySQL daemon was unexpectedly terminated, it was automatically restarted by SMF. Notice that the STIME shows that the MySQL service is back online.
Configuring services using svccfg
The svccfg
command allows you to import, export, and modify service configurations. You specify entities to manipulate by using the -s
option with an FMRI. The following example will set an environment variable for the specified FMRI with the value you specify.
You can invoke svccfg
directly with individual subcommands or by specifying a script file. If you make any changes to a service using this command, you need to restart the service for the changes to take effect.