Skip to main content

habitat_sup Resource

This page is generated from the Chef Infra Client source code.
To suggest a change, edit the habitat_sup.rb file and submit a pull request to the Chef Infra Client repository.

All Infra resources page


Use the habitat_sup resource to runs a Chef Habitat supervisor for one or more Chef Habitat services. The resource is commonly used in conjunction with habitat_service which will manage the services loaded and started within the supervisor.

New in Chef Infra Client 17.3.

Syntax

The full syntax for all of the properties that are available to the habitat_sup resource is:

habitat_sup 'name' do
  auth_token                    String
  auto_update                   true, false # default value: false
  bldr_url                      String
  event_stream_application      String
  event_stream_cert             String
  event_stream_environment      String
  event_stream_site             String
  event_stream_token            String
  event_stream_url              String
  gateway_auth_token            String
  hab_channel                   String
  health_check_interval         String, Integer
  keep_latest                   String
  launcher_version              String
  license                       String
  limit_no_files                String
  listen_ctl                    String
  listen_gossip                 String
  listen_http                   String
  org                           String # default value: "default"
  peer                          String, Array
  permanent_peer                true, false # default value: false
  ring                          String
  service_version               String
  sup_version                   String
  toml_config                   true, false # default value: false
  update_condition              String
  action                        Symbol # defaults to :run if not specified
end

where:

  • habitat_sup is the resource.
  • name is the name given to the resource block.
  • action identifies which steps Chef Infra Client will take to bring the node into the desired state.
  • auth_token, auto_update, bldr_url, event_stream_application, event_stream_cert, event_stream_environment, event_stream_site, event_stream_token, event_stream_url, gateway_auth_token, hab_channel, health_check_interval, keep_latest, launcher_version, license, limit_no_files, listen_ctl, listen_gossip, listen_http, org, peer, permanent_peer, ring, service_version, sup_version, toml_config, and update_condition are the properties available to this resource.

Actions

The habitat_sup resource has the following actions:

:nothing
This resource block doesn’t act unless notified by another resource to take action. Once notified, this resource block either runs immediately or is queued up to run at the end of a Chef Infra Client run.
:run
The run action handles installing Habitat using the habitat_install resource, ensures that the appropriate versions of the core/hab-sup and core/hab-launcher packages are installed using habitat_package, and then drops off the appropriate init system definitions and manages the service. (default)
:stop

Properties

The habitat_sup resource has the following properties:

auth_token
Ruby Type: String

Auth token for accessing a private organization on bldr. This value is templated into the appropriate service file.

auto_update
Ruby Type: true, false | Default Value: false

Passes --auto-update. This will set the Habitat supervisor to automatically update itself any time a stable version has been released.

bldr_url
Ruby Type: String

The Habitat Builder URL for the habitat_package resource, if needed.

event_stream_application
Ruby Type: String

The name of your application that will be displayed in the Chef Automate Applications Dashboard.

event_stream_cert
Ruby Type: String

With Intermediary Certificates or, Automate 2 being set to use TLS with a valid cert, you will need to provide Habitat with your certificate for communication with Automate to work. Follow these steps!.

event_stream_environment
Ruby Type: String

The application environment for the supervisor, this is for grouping in the Applications Dashboard.

event_stream_site
Ruby Type: String

Application Dashboard label for the ‘site’ of the application - can be filtered in the dashboard.

event_stream_token
Ruby Type: String

Chef Automate token for sending application event stream data.

event_stream_url
Ruby Type: String

AUTOMATE_HOSTNAME:4222 - the Chef Automate URL with port 4222 specified

Note

The port can be changed if needed.

gateway_auth_token
Ruby Type: String

Auth token for accessing the supervisor’s HTTP gateway. This value is templated into the appropriate service file.

hab_channel
Ruby Type: String

The channel to install Habitat from. Defaults to stable

health_check_interval
Ruby Type: String, Integer

The interval (seconds) on which to run health checks.

keep_latest
Ruby Type: String

Automatically cleans up old packages. If this flag is enabled, service startup will initiate an uninstall of all previous versions of the associated package. This also applies when a service is restarted due to an update. If a number is passed to this argument, that number of latest versions will be kept. The same logic applies to the Supervisor package env:HAB_KEEP_LATEST_PACKAGES=1

Note

This requires Habitat version 1.5.86+

launcher_version
Ruby Type: String

Allows you to choose which version of launcher to install.

license
Ruby Type: String
Allowed Values: "accept"

Specifies acceptance of habitat license when set to accept.

limit_no_files
Ruby Type: String

allows you to set LimitNOFILE in the systemd service when used

Note

Linux Only.

listen_ctl
Ruby Type: String

Only valid for :run action, passes --listen-ctl with the specified address and port, e.g., 0.0.0.0:9632, to the hab command.

listen_gossip
Ruby Type: String

Only valid for :run action, passes --listen-gossip with the specified address and port, e.g., 0.0.0.0:9638, to the hab command.

listen_http
Ruby Type: String

Only valid for :run action, passes --listen-http with the specified address and port, e.g., 0.0.0.0:9631, to the hab command.

org
Ruby Type: String | Default Value: default

Only valid for :run action, passes --org with the specified org name to the hab command.

peer
Ruby Type: String, Array

Only valid for :run action, passes --peer with the specified initial peer to the hab command.

permanent_peer
Ruby Type: true, false | Default Value: false

Only valid for :run action, passes --permanent-peer to the hab command.

ring
Ruby Type: String

Only valid for :run action, passes --ring with the specified ring key name to the hab command.

service_version
Ruby Type: String

Allows you to choose which version of the Windows Service to install.

sup_version
Ruby Type: String

Allows you to choose which version of supervisor you would like to install.

Note

If a version is provided, it will also install that version of habitat if not previously installed.

toml_config
Ruby Type: true, false | Default Value: false

Supports using the Supervisor toml configuration instead of passing exec parameters to the service, reference.

update_condition
Ruby Type: String

Passes --update-condition dictating when this service should updated. Defaults to latest. Options are latest or track-channel **_

Note

This requires a minimum habitat version of 1.5.71_** - latest: Runs the latest package that can be found in the configured channel and local packages. - track-channel: Always run what is at the head of a given channel. This enables service rollback where demoting a package from a channel will cause the package to rollback to an older version of the package. A ramification of enabling this condition is packages newer than the package at the head of the channel will be automatically uninstalled during a service rollback.

Common Resource Functionality

Chef resources include common properties, notifications, and resource guards.

Common Properties

The following properties are common to every resource:

compile_time

Ruby Type: true, false | Default Value: false

Control the phase during which the resource is run on the node. Set to true to run while the resource collection is being built (the compile phase). Set to false to run while Chef Infra Client is configuring the node (the converge phase).

ignore_failure

Ruby Type: true, false, :quiet | Default Value: false

Continue running a recipe if a resource fails for any reason. :quiet won’t display the full stack trace and the recipe will continue to run if a resource fails.

retries

Ruby Type: Integer | Default Value: 0

The number of attempts to catch exceptions and retry the resource.

retry_delay

Ruby Type: Integer | Default Value: 2

The delay in seconds between retry attempts.

sensitive

Ruby Type: true, false | Default Value: false

Ensure that sensitive resource data isn’t logged by Chef Infra Client.

Notifications

notifies

Ruby Type: Symbol, 'Chef::Resource[String]'

A resource may notify another resource to take action when its state changes. Specify a 'resource[name]', the :action that resource should take, and then the :timer for that action. A resource may notify more than one resource; use a notifies statement for each resource to be notified.

If the referenced resource doesn’t exist, an error is raised. In contrast, subscribes won’t fail if the source resource isn’t found.

A timer specifies the point during a Chef Infra Client run at which a notification is run. The following timers are available:

:before

Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.

:delayed

Default. Specifies that a notification should be queued up, and then executed at the end of a Chef Infra Client run.

:immediate, :immediately

Specifies that a notification should be run immediately, for each resource notified.

The syntax for notifies is:

notifies :action, 'resource[name]', :timer
subscribes

Ruby Type: Symbol, 'Chef::Resource[String]'

A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a 'resource[name]', the :action to be taken, and then the :timer for that action.

Note that subscribes doesn’t apply the specified action to the resource that it listens to - for example:

file '/etc/nginx/ssl/example.crt' do
  mode '0600'
  owner 'root'
end

service 'nginx' do
  subscribes :reload, 'file[/etc/nginx/ssl/example.crt]', :immediately
end

In this case the subscribes property reloads the nginx service whenever its certificate file, located under /etc/nginx/ssl/example.crt, is updated. subscribes doesn’t make any changes to the certificate file itself, it merely listens for a change to the file, and executes the :reload action for its resource (in this example nginx) when a change is detected.

If the other resource doesn’t exist, the subscription won’t raise an error. Contrast this with the stricter semantics of notifies, which will raise an error if the other resource doesn’t exist.

A timer specifies the point during a Chef Infra Client run at which a notification is run. The following timers are available:

:before

Specifies that the action on a notified resource should be run before processing the resource block in which the notification is located.

:delayed

Default. Specifies that a notification should be queued up, and then executed at the end of a Chef Infra Client run.

:immediate, :immediately

Specifies that a notification should be run immediately, for each resource notified.

The syntax for subscribes is:

subscribes :action, 'resource[name]', :timer

Guards

A guard property can be used to evaluate the state of a node during the execution phase of a Chef Infra Client run. Based on the results of this evaluation, a guard property is then used to tell Chef Infra Client if it should continue executing a resource. A guard property accepts either a string value or a Ruby block value:

  • A string is executed as a shell command. If the command returns 0, the guard is applied. If the command returns any other value, then the guard property isn’t applied. String guards in a powershell_script run Windows PowerShell commands and may return true in addition to 0.
  • A block is executed as Ruby code that must return either true or false. If the block returns true, the guard property is applied. If the block returns false, the guard property isn’t applied.

A guard property is useful for ensuring that a resource is idempotent by allowing that resource to test for the desired state as it’s being executed, and then if the desired state is present, for Chef Infra Client to don’thing.

Properties

The following properties can be used to define a guard that’s evaluated during the execution phase of a Chef Infra Client run:

not_if

Prevent a resource from executing when the condition returns true.

only_if

Allow a resource to execute only if the condition returns true.

Examples

The following examples demonstrate various approaches for using the habitat_sup resource in recipes:

Set up with just the defaults

habitat_sup 'default'

Update listen ports and use Supervisor toml config

habitat_sup 'test-options' do
  listen_http '0.0.0.0:9999'
  listen_gossip '0.0.0.0:9998'
  toml_config true
end

Use with an on-prem Habitat Builder. Note: Access to public builder may not be available due to your company policies

habitat_sup 'default' do
  bldr_url 'https://bldr.example.com'
end

Using update_condition

habitat_sup 'default' do
  bldr_url 'https://bldr.example.com'
  habitat_channel 'dev'
  update_condition 'track-channel'
end

Provide event_stream_ information*

habitat_sup 'default' do
  license 'accept'
  event_stream_application 'myapp'
  event_stream_environment 'production'
  event_stream_site 'MySite'
  event_stream_url 'automate.example.com:4222'
  event_stream_token 'myawesomea2clitoken='
  event_stream_cert '/hab/cache/ssl/mycert.crt'
end

Provide specific versions

habitat_sup 'default' do
  bldr_url 'https://bldr.example.com'
  sup_version '1.5.50'
  launcher_version '13458'
  service_version '0.6.0' # WINDOWS ONLY
end

Set latest version of packages to retain

habitat_sup ‘default’ do bldr_url ‘https://bldr.example.com’ sup_version ‘1.5.86’ launcher_version ‘13458’ service_version ‘0.6.0’ # WINDOWS ONLY keep_latest ‘2’ end

Edit this page on GitHub

Thank you for your feedback!

×