set environment variables in smf manifests

If you are in the need to set an environment variable for an smf service, you are looking for envvar. It get’s set in the service scope or in the exec_method scope. Here is a small example, how it’s used.

<exec_method type="method" name="start" exec="/bin/bash">
  <method_context>
    <method_environment>
      <envvar name="FOO" value="bar" />
    </method_environment>
  </method_context>
</exec_method>

This example sets the environment variable FOO to bar. This is espacially useful, when you have to modify PATH or LD_LIBRARY_PATH. Just don’t forget, that you did it.