DilOS platformService Management Facility

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:

# svcadm restart mariadb

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:

# svcs -a

This will show all running and disabled services. If a service is in maintenance mode, you will see something similar to this:

maintenence 10:35:34 svc:/database/mariadb:default

Review the log to root-cause why the service was in maintenance mode.

# more $(svcs -L service_name)

Take the service out of maintenance mode:

# svcadm clear service_name

Verifying a service is disabled

To verify if a service is disabled:

# svcs -a

If the service is disabled, you will see something similar to this:

disabled 10:36:10 svc:/database/mariadb:default

Enabling a service

Enable the service:

# svcadm enable service_name

Verify the service is enabled:

# svcs service_name

If successful, you should see something similar to this:

online 10:36:25 svc:/database/mariadb:default

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.

STATE STIME FMRI online 10:38:59 svc:/database/mariadb:default 10:38:59 28659 mysqld_safe 10:38:59 mysqld 10:38:59 28795 logger

The following example demonstrates how SMF restarts a service when it stops unexpectedly:

# kill -9 28794 # svcs -p mariadb STATE STIME FMRI online* 12:43:31 svc:/database/mariadb:default 12:38:59 28659 mysqld_safe 12:43:31 28981 mysqld 12:43:31 28982 logger # mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.3.27-MariaDB-0+deb10u1+dilos1 DilOS 3 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> \q Bye

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.

# svccfg -s FMRI setenv ENV_VARIABLE value

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.