Go to main content

Managing System Services in Oracle® Solaris 11.4

Exit Print View

Updated: Febuary 2019

Setting Property Values

The following commands set property values:

svccfg setprop

Changes the value of a property.

svccfg addpropvalue

Adds a value to a multi-value property.

svccfg setenv

Changes the value of an environment variable for a service process execution environment.

Remember to use the svccfg refresh command or svcadm refresh command to commit configuration changes into the running snapshot.

Example 26  Setting a Simple Value

In the simplest use of setprop, specify a pg/name for the selected service or instance, where pg is the name of the property group and name is the name of the property, and specify the new value after an equals symbol. If the property already exists or is templated, you do not need to specify the property type.

$ svccfg -s pkg/server:s11 setprop pkg/port=81
Example 27  Setting a Value that Contains Embedded Spaces

Use double quotation marks to set a value that contains embedded spaces. Depending on your shell, you might need to enclose the double-quoted string in single quotation marks.

$ svccfg -s pkg/mirror setprop config/crontab_period = "00 3 25 * *"
$ svccfg -s pkg/mirror setprop config/crontab_period = '"00 3 25 * *"'

Use quotation marks to set a value that contains double quotation marks or backslash characters, and use a backslash character to escape any double quotation marks or backslash characters.

Example 28  Setting a Value that Is a Set of Values

Use parentheses to specify a set of values as a single value. Depending on your shell, you might need to escape the parentheses.

$ svccfg -s dns/client setprop config/nameserver = (
$ svccfg -s dns/client setprop config/nameserver = \(\)
$ svccfg -s dns/client listprop config/nameserver
config/nameserver net_address

Use the describe subcommand to find the number of values allowed in the set of values.

$ svccfg -s dns/client describe -v config/nameserver
config/nameserver net_address
    type: net_address
    required: false
    The IP address of a DNS nameserver to be used by the resolver.
    visibility: readwrite
    minimum number of values: 1
    maximum number of values: 3
Example 29  Setting a Property Whose Name Contains Special Characters

Naming Property Groups and Properties in Developing System Services in Oracle Solaris 11.4 provides a list of reserved characters that can be used in property group and property names. These reserved characters appear encoded in FMRIs:

$ svccfg -s enchars_example:default
svc:/site/enchars_example:default> listprop config
config                     application
config/%25%20increase      count       10
config/maximum%20%23       count       9
config/start%3Aend         count       10
config/students%2Fteachers count       20

To set these properties, you can copy the encoded names:

svc:/site/enchars_example:default> setprop config/students%2Fteachers=21
svc:/site/enchars_example:default> listprop config/students%2Fteachers
config/students%2Fteachers count       21

Another way to set these properties is to use the -G and -P options:

svc:/site/enchars_example:default> setprop -G config -P students/teachers 20
svc:/site/enchars_example:default> listprop -G config -P students/teachers
config/students%2Fteachers count       20

Use quotation marks for property group names or property names that contain spaces:

svc:/site/enchars_example:default> setprop -G config -P "% increase" 12
svc:/site/enchars_example:default> listprop -G config -P "% increase"
config/%25%20increase count       12

The editprop tool automatically uses the -G and -P options:

$ svccfg -s enchars_example:default editprop
$ setprop -G "config" -P "% increase" -T count 10
$ setprop -G "config" -P "maximum #" -T count 9
$ setprop -G "config" -P "start:end" -T count 10
$ setprop -G "config" -P "students/teachers" -T count 20
Example 30  Setting the Value of a Property in a Nested Property Group

To set the value of a property in a property group that is the child of another property group, specify the full ancestry of the property.

In the following example, http and https are child property groups of the config property group, and ssl is a child property group of the https property group:

$ svccfg -s npg_example listprop config
config                    application
config/port               count       80
config/http               application
config/http/port          count       80
config/https              application
config/https/port         count       443
config/https/ssl          application
config/https/ssl/certfile astring     cert.crt
config/https/ssl/keyfile  astring     key.crt

To specify different values for properties of nested property groups, specify the full FMRI of the property or use multiple -G options. The following example changes the values of the certificate and key files for the default instance:

$ svccfg -s npg_example:default
svc:/site/npg_example:default> setprop config/https/ssl/certfile=cert-1.pem
svc:/site/npg_example:default> setprop -G config -G https -G ssl -P keyfile key-1.pem
svc:/site/npg_example:default> listprop config/https/ssl
config/https/ssl          application
config/https/ssl/certfile astring     cert-1.pem
config/https/ssl/keyfile  astring     key-1.pem
Example 31  Adding a Value

Use the addpropvalue subcommand to add the given value to the specified property of the selected service or service instance. The new value is appended to the end of the existing list of property values for the property.

$ svcprop -p keymap/layout keymap:default
$ svccfg -s keymap:default addpropvalue keymap/layout UK-English
$ svccfg -s keymap:default listprop keymap/layout
keymap/layout astring     "US-English" "UK-English"

In the previous setprop example, all values in the set of values must be specified at once. If only one value is specified, that value becomes the new set of one value. In this addpropvalue example, the added values are distinct. To access these added values, you must use the libscf function scf_iter_property_values() to iterate over the values. While listprop lists both values, describe lists only the first value and reports that the maximum allowed number of values for this property is one.

$ svccfg -s keymap:default describe -v keymap/layout
keymap/layout astring     US-English
    type: astring
    required: true
    The keyboard layout
    visibility: readwrite
    minimum number of values: 1
    maximum number of values: 1
  value: US-English