This cookbook provides resources for working with Habitat. It is intended that these resources will be included in core Chef at some point in the future, so it is important to note:
- APIs are subject to change
- Habitat is a rapidly changing product, and this cookbook may change rapidly as well
(this is a pre-1.0 version, after all)
Habitat requires acceptance of a license before any habitat commands can be run. To accept the Habitat license using this cookbook, the license
parameter can be set to accept
for either the hab_install
or hab_sup
resources as shown in the below examples:
hab_install 'install habitat' do
license 'accept'
end
hab_sup 'default' do
license 'accept'
end
PLEASE NOTE: Without performing one of the above license acceptance steps, all other resources in the habitat cookbook will fail with an error prompting that the license must be accepted.
- RHEL 6+
- Ubuntu 14.04+
- Debian 7+
- Windows 2016
- Habitat version: 0.88.0
This cookbook is developed lockstep with the latest release of Habitat to ensure compatibility, going forward from 0.33.0 of the cookbook and 0.33.2 of Habitat itself. When new versions of Habitat are released, the version should be updated in these files:
README.md
: note required version in this fileresources/install.rb
: set the default to the new versiontest/integration/install/default_spec.rb
: to match the version from the resource
Additionally, new versions must be tested that all behavior in the cookbook still works, otherwise the cookbook must be updated to match the behavior in the new version of Habitat.
Users who wish to install a specific version of Habitat should use an older (0.28 or earlier) release of this cookbook, but note that is unsupported and they are advised to upgrade ASAP.
- Chef 12.20.3+
- None
Installs Habitat on the system using the install script.
install
: Installs Habitat. Does nothing if thehab
binary is found in the default location for the system (/bin/hab
on Linux,/usr/local/bin/hab
on macOS,C:/habitat/hab.exe
on Windows)upgrade
: Installs the latest version of Habitat, does not check if the binary exists
install_url
: URL to the install script, default is from the habitat repobldr_url
: Optional URL to an alternate Builder (defaults to the public Builder)create_user
: Creates thehab
system user (defaults totrue
)tmp_dir
: Sets TMPDIR environment variable for location to place temp files. (required if/tmp
and/var/tmp
are mountednoexec
)license
: Specifies acceptance of habitat license when set toaccept
(defaults to empty string).
Nameless installation
hab_install
Instalaltion specifying a bldr URL
hab_install 'install habitat' do
bldr_url 'http://localhost'
end
Install the specified Habitat package from builder. Requires that Habitat is installed
install
: installs the specified packageupgrade
: installs the specified package. If a newer version is available in the configured channel, upgrades to that version
package_name
: A Habitat package name, must include the origin and package name separated by/
, for example,core/redis
version
: A Habitat version which contains the version and optionally a release separated by/
, for example,3.2.3
or3.2.3/20160920131015
bldr_url
: The habitat builder url where packages will be downloaded from (defaults to public habitat builder)channel
: The release channel to install from (defaults tostable
)auth_token
: Auth token for installing a package from a private organization on builderbinlink
: If habitat should attempt to binlink the package. Acceptable values:true
,false
,:force
. Will faill on binlinking if set totrue
and binary or binlink exists.options
: Pass any additional parameters to the habitat install command.
While it is valid to pass the version and release with a Habitat package as a fully qualified package identifier when using the hab
CLI, they must be specified using the version
property when using this resource. See the examples below.
hab_package 'core/redis'
hab_package 'core/redis' do
version '3.2.3'
channel 'unstable'
end
hab_package 'core/redis' do
version '3.2.3/20160920131015'
end
hab_package 'core/nginx' do
binlink :force
end
hab_package 'core/nginx' do
options '--binlink'
end
Manages a Habitat application service using hab sup
/hab service
. This requires that core/hab-sup
be running as a service. See the hab_sup
resource documentation below for more information about how to set that up with this cookbook.
Note: Applications may run as a specific user. Often with Habitat, the default is hab
, or root
. If the application requires another user, then it should be created with Chef's user
resource.
:load
: (default action) runshab service load
to load and start the specified application service:unload
: runshab service unload
to unload and stop the specified application service:reload
: runs the:unload
and then:load
actions:start
: runshab service start
to start the specified application service:stop
: runshab service stop
to stop the specified application service:restart
: runs the:stop
and then:start
actions
The remote_sup property is valid for all actions.
remote_sup
: Address to a remote Supervisor's Control Gateway [default: 127.0.0.1:9632]remote_sup_http
: Address for remote supervisor http port. Used to pull existing configuration data. If this is invalid, config will be applied on every Chef run.gateway_auth_token
: Auth token for accessing the remote supervisor's http port.
The follow properties are valid for the load
action.
service_name
: name property, the name of the service, must be in the form oforigin/name
loaded
: state property indicating whether the service is loaded in the supervisorrunning
: state property indicating whether the service is running in the supervisorstrategy
: Passes--strategy
with the specified update strategy to the hab commandtopology
: Passes--topology
with the specified service topology to the hab commandbldr_url
: Passes--url
with the specified Builder URL to the hab command.channel
: Passes--channel
with the specified channel to the hab commandbind
: Passes--bind
with the specified services to bind to the hab command. If an array of multiple service binds are specified then a--bind
flag is added for each.binding_mode
: Passes--binding-mode
with the specified binding mode. Defaults to:strict
. Options are:strict
or:relaxed
service_group
: Passes--group
with the specified service group to the hab command
# install and load nginx
hab_package 'core/nginx'
hab_service 'core/nginx'
hab_service 'core/nginx unload' do
service_name 'core/nginx'
action :unload
end
# pass the strategy and topology options to hab service commands (load by default)
hab_service 'core/redis' do
strategy 'rolling'
topology 'standalone'
end
If the service has it's own user specified that is not the hab
user, don't create the hab
user on install, and instead create the application user with Chef's user
resource
hab_install 'install habitat' do
create_user false
end
user 'acme-apps' do
system true
end
hab_service 'acme/apps'
Runs a Habitat Supervisor for one or more Habitat Services. It is used in conjunction with hab_service
which will manage the services loaded and started within the supervisor.
The run
action handles installing Habitat using the hab_install
resource, ensures that the appropriate versions of the core/hab-sup
and core/hab-launcher
packages are installed using hab_package
, and then drops off the appropriate init system definitions and manages the service.
run
: starts thehab-sup
service
bldr_url
: The Builder URL for thehab_package
resource, if neededpermanent_peer
: Only valid for:run
action, passes--permanent-peer
to the hab commandlisten_ctl
: Only valid for:run
action, passes--listen-ctl
with the specified address and port, e.g.,0.0.0.0:9632
, to the hab commandlisten_gossip
: Only valid for:run
action, passes--listen-gossip
with the specified address and port, e.g.,0.0.0.0:9638
, to the hab commandlisten_http
: Only valid for:run
action, passes--listen-http
with the specified address and port, e.g.,0.0.0.0:9631
, to the hab commandorg
: Only valid for:run
action, passes--org
with the specified org name to the hab commandpeer
: Only valid for:run
action, passes--peer
with the specified initial peer to the hab commandring
: Only valid for:run
action, passes--ring
with the specified ring key name to the hab commandhab_channel
: The channel to install Habitat from. Defaults to stableauth_token
: Auth token for accessing a private organization on bldr. This value is templated into the appropriate service file.gateway_auth_token
: Auth token for accessing the supervisor's HTTP gateway. This value is templated into the appropriate service file.license
: Specifies acceptance of habitat license when set toaccept
(defaults to empty string).health_check_interval
: The interval (seconds) on which to run health checks (defaults to 30).
# set up with just the defaults
hab_sup 'default'
hab_sup 'test-options' do
listen_http '0.0.0.0:9999'
listen_gossip '0.0.0.0:9998'
end
# Use with an on-prem Builder
# Access to public builder may not be available
hab_sup 'default' do
bldr_url 'https://bldr.private.net'
end
Applies a given configuration to a habitat service using hab config apply
.
apply
: (default action) apply the given configuration
service_group
: The service group to apply the configuration to, for example,nginx.default
config
: The configuration to apply as a ruby hash, for example,{ worker_count: 2, http: { keepalive_timeout: 120 } }
remote_sup
: Address to a remote Supervisor's Control Gateway [default: 127.0.0.1:9632]remote_sup_http
: Address for remote supervisor http port. Used to pull existing configuration data. If this is invalid, config will be applied on every Chef run.gateway_auth_token
: Auth token for accessing the remote supervisor's http port.user
: Name of user key to use for encryption. Passes--user
tohab config apply
The version number of the configuration is automatically generated and will be the current timestamp in seconds since 1970-01-01 00:00:00 UTC.
hab_config 'nginx.default' do
config({
worker_count: 2,
http: {
keepalive_timeout: 120
}
})
end
Templates a user.toml for the specified service. This is written to /hab/user/<service_name>/config/user.toml
. User.toml can be used to set configuration overriding the default.toml for a given package as an alternative to applying service group level configuration.
create
: (default action) Create the user.toml from the specified config.delete
: Delete the user.toml
service_name
: The service group to apply the configuration to, for example,nginx.default
config
: Only valid for:create
action. The configuration to apply as a ruby hash, for example,{ worker_count: 2, http: { keepalive_timeout: 120 } }
hab_user_toml 'nginx' do
config({
worker_count: 2,
http: {
keepalive_timeout: 120
}
})
end
This cookbook is maintained by the following maintainers:
- Jon Cowie jcowie@chef.io
The goal of the Community Cookbook Engineering team is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our team documentation. To learn more about contributing to cookbooks like this see our contributing documentation, or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the Chef Community Slack
Copyright: 2016-2018, Chef Software, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.