Go to main content

Managing System Services in Oracle® Solaris 11.4

Exit Print View

Updated: Febuary 2019
 
 

How to Modify an Environment Variable for a Service Process Environment

This procedure shows how to set a value for an environment variable in the environment where processes started by the service will run.

The example in this procedure shows how to modify cron environment variables to help with debugging.

  1. Verify that the service is running.

    The following output shows that the cron service is online and a cron process is running.

    $ svcs -p cron
    STATE          STIME    FMRI
    online         10:24:05 svc:/system/cron:default
                   10:24:05     1089 cron
  2. Set environment variables.

    The setenv subcommand sets an environment variable for the environment where a process started by a service or service instance will run.

    Use the following command to check the current values of the environment variables you want to set:

    $ pargs -e `pgrep -f /usr/sbin/cron`

    The environment variables that are set in this example do not have any current values.

    The following commands set the UMEM_DEBUG and LD_PRELOAD environment variables for the /usr/sbin/cron process started by the svc:/system/cron:default service instance:

    $ svccfg -s system/cron:default setenv UMEM_DEBUG default
    $ svccfg -s system/cron:default setenv LD_PRELOAD libumem.so
  3. Refresh and restart the service.

    Changing an environment variable value requires a restart as well as a refresh to take effect.

    $ svcadm refresh system/cron:default
    $ svcadm restart system/cron:default
  4. Verify that the change has been made.

    The following output shows that the service has been restarted, the process has a new process ID, and the two environment variables are set for that process environment.

    $ svcs -p cron
    STATE          STIME    FMRI
    online          9:24:39 svc:/system/cron:default
                    9:24:39     5601 cron
    $ svcprop -g method -p environment system/cron:default
    start/environment astring LD_PRELOAD=libumem.so UMEM_DEBUG=default
    $ pargs -e `pgrep -f /usr/sbin/cron`
    5601: /usr/sbin/cron
    envp[0]: LOGNAME=root
    envp[1]: LD_PRELOAD=libumem.so
    envp[2]: PATH=/usr/sbin:/usr/bin
    envp[3]: SMF_FMRI=svc:/system/cron:default
    envp[4]: SMF_METHOD=start
    envp[5]: SMF_RESTARTER=svc:/system/svc/restarter:default
    envp[6]: SMF_ZONENAME=global
    envp[7]: UMEM_DEBUG=default

See Also

The unsetenv subcommand unsets an environment variable for a process started by a service or service instance.