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)
- RHEL 6+
- Ubuntu 14.04+
- Debian 7+
- Habitat version: 0.55.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)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)channel
: The release channel to install from (defaults tostable
)create_user
: Creates thehab
system user (defaults totrue
)
Nameless installation
hab_install
Instalaltion specifying a bldr URL
hab_install 'install habitat' do
bldr_url 'http://localhost'
end
Install the specified Habitat package. Requires that Habitat is installed
install
: installs the specified packageupgrade
: aliased to install
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
)
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
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:start
: runshab service start
to start the specified application service:stop
: runshab service stop
to stop the specified application service
Some properties are only valid for start
or load
actions. See the description of each option for indication which action(s) the property is used. This is because the underlying hab sup
commands have different options available in their context.
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 supervisorpermanent_peer
: Only valid for:start
action, passes--permanent-peer
to the hab commandlisten_gossip
: Only valid for:start
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:start
action, passes--listen-http
with the specified address and port, e.g.,0.0.0.0:9631
, to the hab commandorg
: Only valid for:start
action, passes--org
with the specified org name to the hab commandpeer
: Only valid for:start
action, passes--peer
with the specified initial peer to the hab commandring
: Only valid for:start
action, passes--ring
with the specified ring key name to the hab commandstrategy
: Only valid for:start
or:load
actions, passes--strategy
with the specified update strategy to the hab commandtopology
: Only valid for:start
or:load
actions, passes--topology
with the specified service topology to the hab commandbldr_url
: Only valid for:start
or:load
actions, passes--url
with the specified Builder URL to the hab command. For local repos, use 'local'.bind
: Only valid for:start
or:load
actions, passes--bind
with the specified services to bind to the hab commandservice_group
: Only valid for:start
or:load
actions, passes--group
with the specified service group to the hab commandconfig_from
: Only valid for:start
action, passes--config-from
with the specified directory to the hab commandoverride_name
: Advanced Use Valid for all actions, passes--override-name
with the specified name to the hab command; used for running services in multiple supervisorschannel
: Only valid for:start
or:load
actions, passes--channel
with the specified channel 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 core/hab-sup
package is installed using hab_package
, and then drops off the appropriate init system definitions and manages the service.
run
: starts thehab-sup
service
permanent_peer
: Only valid for:start
action, passes--permanent-peer
to the hab commandlisten_gossip
: Only valid for:start
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:start
action, passes--listen-http
with the specified address and port, e.g.,0.0.0.0:9631
, to the hab commandorg
: Only valid for:start
action, passes--org
with the specified org name to the hab commandpeer
: Only valid for:start
action, passes--peer
with the specified initial peer to the hab commandring
: Only valid for:start
action, passes--ring
with the specified ring key name to the hab commandhab_channel
: The channel to install Habitat from. Defaults to stableoverride_name
: Advanced Use Valid for all actions, passes--override-name
with the specified name to the hab command; used for running services in multiple supervisors
# set up with just the defaults
hab_sup 'default'
# run with an override name, requires changing listen_http and
# listen_gossip if a default supervisor is running
hab_sup 'test-options' do
override_name 'myapps'
listen_http '0.0.0.0:9999'
listen_gossip '0.0.0.0:9998'
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 } }
org
: (optional) passes the--org
option with the specified org name to the hab config command.peer
: (optional) passes the--peer
option with the specified peer to the hab config command.ring
: (optional) passes the--ring
option with the specified ring key name to the hab config command.api_host
: Hostname for the habitat api in order to look up the existing configuration. Defaults to127.0.0.1
.api_port
: Port number for the habitat api. Defaults to9631
.
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
This cookbook is maintained by Chef's Community Cookbook Engineering team along with the following maintainers:
- Joshua Timberman [email protected]
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.