Is There Anyway To Use Erb Templates Not Stored In Cookbook
runit Cookbook
Installs runit and provides the runit_service
service resource for managing processes (services) under runit.
This cookbook does not employ runit to supplant system init, nor are in that location plans to do so.
For more information most runit:
- http://smarden.org/runit/
NOTE: The v.0 release of this cookbook requires the ChefSpec which shipped in the afterward versions of ChefDK iii. If you use this cookbook along with ChefSpec in your environment then y'all will need to upgrade to the latest version of ChefDK / Workstation to prevent spec failures.
Requirements
Platforms
- Debian/Ubuntu
- RHEL and derivatives
Chef
- Chef xiv.0+
Cookbooks
- packagecloud (for RHEL)
- yum-epel (for RHEL)
Attributes
-
node['runit']['prefer_local_yum']
- Iftrue
, assumes that arunit
package is bachelor on an already configured local yum repository. By default, the recipe installs therunit
package from a Package Cloud repository (see below). This is fix to the value ofnode['runit']['use_package_from_yum']
for backwards compatibility, but otherwise defaults tofalse
.
Recipes
default
The default recipe installs runit and starts runsvdir
to supervise the services in runit's service directory (eastward.k., /etc/service
).
On RHEL-family systems, it will install the runit RPM using Ian Meyer'south Packet Deject repository for runit. This replaces the previous functionality where the RPM was build using his runit RPM SPEC. Notwithstanding, if the attribute node['runit']['prefer_local_yum']
is gear up to true
, the packagecloud repository creation volition be skipped and information technology is assumed that a runit
package is available on an otherwise configured (exterior this cookbook) local repository.
On Debian family systems, the runit packages are maintained past the runit author, Gerrit Pape, and the recipe will use that for installation.
Resources
This cookbook has a resources, runit_service
, for managing services nether runit.
Actions
- enable - enables the service, creating the required run scripts and symlinks. This is the default activity.
- starting time - starts the service with
sv start
- stop - stops the service with
sv stop
- disable - stops the service with
sv downwardly
and removes the service symlink - create - create the service directory, but don't enable the service with symlink
- restart - restarts the service with
sv restart
- reload - reloads the service with
sv forcefulness-reload
- reload_log - reloads the service's log service
- in one case - starts the service with
sv once
. - hup - sends the
HUP
signal to the service withsv hup
- cont - sends the
CONT
betoken to the service - term - sends the
TERM
bespeak to the service - impale - sends the
Kill
point to the service - up - starts the service with
sv up
- down - downs the service with
sv downwardly
- usr1 - sends the
USR1
point to the service withsv 1
- usr2 - sends the
USR2
signal to the service withsv 2
Service direction actions are taken with runit'south "sv
" program.
Read the sv(eight)
human being page for more than information on the sv
programme.
Properties
The first three backdrop, sv_dir
, service_dir
, and sv_bin
will endeavor to employ the legacy node attributes, and fall back to hardcoded default values that match the settings used on Debian platform systems.
Many of these backdrop are simply used in the :enable
action.
- sv_dir - The base "service directory" for the services managed by the resources. By default, this will attempt to utilize the
node['runit']['sv_dir']
attribute, and falls back to/etc/sv
. - service_dir - The directory where services are symlinked to exist supervised past
runsvdir
. By default, this will endeavour to use thenode['runit']['service_dir']
attribute, and falls back to/etc/service
. - lsb_init_dir - The directory where an LSB-compliant init script interface volition exist created. By default, this volition attempt to utilise the
node['runit']['lsb_init_dir']
attribute, and falls dorsum to/etc/init.d
. - sv_bin - The path to the
sv
program binary. This volition attempt to use thenode['runit']['sv_bin']
attribute, and falls dorsum to/usr/bin/sv
. - service_name - Name attribute. The proper name of the service. This volition exist used in the directory of the managed service in the
sv_dir
andservice_dir
. - sv_timeout - Override the default
sv
timeout of vii seconds. - sv_verbose - Whether to enable
sv
verbose mode. Default isfalse
. - sv_templates - If truthful, the
:enable
action will create the service directory with the advisable templates. Default istruthful
. Gear up this tofake
if the service has a package that provides its own service directory. Meet Usage examples. - options - DEPRECATED - Options passed as variables to templates, for compatibility with legacy runit service definition. Default is an empty hash.
- env - A hash of environment variables with their values every bit content used in the service's
env
directory. Default is an empty hash. When this hash is non-empty, the contents of the runit service'senv
directory will be managed by Chef in order to conform to the declared state. - log - Whether to start the service'south logger with svlogd, requires a template
sv-service_name-log-run.erb
to configure the log'south run script. Default is true. - default_logger - Whether a default
log/run
script should be prepare upwardly. If truthful, the default content of the run script will utilisesvlogd
to write logs to/var/log/service_name
. Default is false. - log_dir - The directory where the
svlogd
log service will run. Used whendefault_logger
istrue
. Default is/var/log/service_name
- log_flags - The flags to laissez passer to the
svlogd
command. Used whendefault_logger
istrue
. Default is-tt
- log_size - The maximum size a log file tin can grow to before it is automatically rotated. Run across svlogd(8) for the default value.
- log_num - The maximum number of log files that will be retained later rotation. See svlogd(8) for the default value.
- log_min - The minimum number of log files that will be retained after rotation (if svlogd cannot create a new file and the minimum has not been reached, information technology volition cake). Default is no minimum.
- log_timeout - The maximum historic period a log file can get to before it is automatically rotated, whether it has reached
log_size
or non. Default is no timeout. - log_processor - A string containing a path to a program that rotated log files will be fed through. Come across the PROCESSOR department of svlogd(8) for details. Default is no processor.
- log_socket - An cord containing an IP:port pair identifying a UDP socket that log lines will exist copied to. Default is none.
- log_prefix - A string that will be prepended to each line as it is logged. Default is no prefix.
- log_config_append - A string containing optional additional lines to add to the log service configuration. See svlogd(eight) for more details.
- cookbook - A cookbook where templates are located instead of where the resources is used. Applies for all the templates in the
enable
action. - bank check - whether the service has a check script, requires a template
sv-service_name-check.erb
- finish - whether the service has a finish script, requires a template
sv-service_name-terminate.erb
- control - An array of signals to customize control of the service, encounter runsv homo folio on how to employ this. This requires that each template be created with the name
sv-service_name-point.erb
. - supervisor_owner - the user that should exist allowed to control this service, meet runsv faq
- supervisor_group - the group that should be allowed to control this service, encounter runsv faq
- owner - user that should ain the templates created to enable the service
- group - group that should ain the templates created to enable the service
- run_template_name - alternate filename of the run run script to use replacing
service_name
. - log_template_name - alternate filename of the log run script to employ replacing
service_name
. - check_script_template_name - alternate filename of the check script to utilise, replacing
service_name
. - finish_script_template_name - alternating filename of the cease script to use, replacing
service_name
. - control_template_names - a hash of control signals (see control higher up) and their alternate template name(s) replacing
service_name
. - status_command - The command used to bank check the status of the service to see if information technology is enabled/running (if it's running, information technology's enabled). This hardcodes the location of the sv program to
/usr/bin/sv
due to the aforementioned cookbook load guild. - restart_on_update - Whether the service should be restarted when the run script is updated. Defaults to
true
. Set toimitation
if the service shouldn't be restarted when the run script is updated. - start_down - Set the default state of the runit service to 'downward' by creating
<sv_dir>/down
file. Defaults tofalse
. Services usingstart_down
will not be notified to restart when their run script is updated. - delete_downfile - Delete previously created
<sv_dir>/downward
file
Unlike previous versions of the cookbook using the runit_service
definition, the runit_service
resource can be notified. See Usage examples below.
Usage
To get runit installed on supported platforms, employ recipe[runit]
. Once it is installed, utilize the runit_service
resource to set up upwardly services to exist managed by runit.
In order to use the runit_service
resources in your cookbook(s), each service managed will also need to take sv-service_name-run.erb
and sv-service_name-log-run.erb
templates created. If the log
property is simulated, the log run script isn't created. If the log
belongings is truthful, and default_logger
is too true, the log run script will be created with the default content:
#!/bin/sh exec svlogd -tt /var/log/service_name
Examples
These are example use cases of the runit_service
resource described in a higher place. There are others in the runit_test
cookbook that is included in the git repository.
Default Example
This case uses all the defaults in the :enable
action to set upwardly the service.
We'll set upward chef-client
to run as a service under runit, such as is done in the chef-client
cookbook. This example will be more simple than in that cookbook. First, create the required run template, chef-client/templates/default/sv-chef-client-run.erb
.
#!/bin/sh exec two>&1 exec /usr/bin/env chef-client -i 1800 -s 30
Then create the required log/run template, chef-client/templates/default/sv-chef-client-log-run.erb
.
#!/bin/sh exec svlogd -tt ./principal
Note This will crusade output of the running procedure to go to /etc/sv/chef-client/log/primary/current
. Some people may not like this, see the following example. This is preserved for compatibility reasons.
Finally, set the service in the recipe with:
runit_service "chef-client"
Default Logger Example
To utilize a default logger with svlogd which volition log to /var/log/chef-client/electric current
, instead, apply the default_logger
option.
runit_service "chef-customer" practise default_logger true terminate
No Log Service
If there isn't an appendant log service, set log
to false, and the log/run script won't be created.
runit_service "no-svlog" do log imitation end
Check Script
To create a service that has a bank check script in its service directory, gear up the cheque
belongings to true
, and create a sv-checker-check.erb
template.
runit_service "checker" do bank check true end
This will create /etc/sv/checker/bank check
.
Finish Script
To create a service that has a finish script in its service directory, ready the finish
property to true
, and create a sv-finisher-cease.erb
template.
runit_service "finisher" practice terminate truthful terminate
This will create /etc/sv/finisher/finish
.
Alternate service directory
If the service directory for the managed service isn't the sv_dir
(/etc/sv
), then specify it:
runit_service "custom_service" exercise sv_dir "/etc/custom_service/runit" stop
No Service Directory
If the service to manage has a packet that provides its service directory, such every bit git-daemon
on Debian systems, set sv_templates
to fake.
package "git-daemon-run" runit_service "git-daemon" do sv_templates faux end
This will create the service symlink in /etc/service
, but it will not manage whatsoever templates in the service directory.
User Controlled Services
To fix services controlled by a non-privileged user, we follow the recommended configuration in the runit documentation (Is information technology possible to let a user other than root to control a service?).
Suppose the user'southward name is floyd, and floyd wants to run floyds-app. Assuming that the floyd user and grouping are already managed with Chef, create a runsvdir-floyd
runit_service.
runit_service "runsvdir-floyd"
Create the sv-runsvdir-floyd-log-run.erb
template, or add log fake
. Besides create the sv-runsvdir-floyd-run.erb
with the following content:
#!/bin/sh exec 2>&one exec chpst -ufloyd runsvdir /home/floyd/service
Side by side, create the runit_service
resource for floyd's app:
runit_service "floyds-app" exercise sv_dir "/abode/floyd/sv" service_dir "/abode/floyd/service" owner "floyd" group "floyd" cease
And at present floyd can manage the service with sv:
$ id uid=thousand(floyd) gid=1001(floyd) groups=1001(floyd) $ sv stop /home/floyd/service/floyds-app/ ok: downwards: /home/floyd/service/floyds-app/: 0s, usually upwards $ sv start /dwelling/floyd/service/floyds-app/ ok: run: /dwelling house/floyd/service/floyds-app/: (pid 5287) 0s $ sv status /home/floyd/service/floyds-app/ run: /domicile/floyd/service/floyds-app/: (pid 5287) 13s; run: log: (pid 4691) 726s
Options
Next, allow's ready memcached under runit with some additional options using the options
holding. First, the memcached/templates/default/sv-memcached-run.erb
template:
#!/bin/sh exec 2>&1 exec chpst -u <%= @options[:user] %> /usr/bin/memcached -v -yard <%= @options[:memory] %> -p <%= @options[:port] %>
Notation that the script uses chpst
(which comes with runit) to fix the user choice, and then starts memcached on the specified retentivity and port (see beneath).
The log/run template, memcached/templates/default/sv-memcached-log-run.erb
:
#!/bin/sh exec svlogd -tt ./main
Finally, the runit_service
in our recipe:
runit_service "memcached" do options ( { :memory => node [ :memcached ] [ :memory ] , :port => node [ :memcached ] [ :port ] , :user => node [ :memcached ] [ :user ] } . merge ( params ) ) end
This is where the user, port and retention options used in the run template are used.
Notifying Runit Services
In previous versions of this cookbook where the definition was used, it created a service
resource that could be notified. With the runit_service
resource, recipes need to use the full resource proper name.
For case:
runit_service "my-service" template "/etc/my-service.conf" do notifies :restart , "runit_service[my-service]" end
Because the resource implements deportment for diverse commands that sv
can send to the service, any of those actions could be used for notification. For case, chef-client
supports triggering a Chef run with a USR1 signal.
template "/tmp/chef-notifier" do notifies :usr1 , "runit_service[chef-client]" terminate
For older implementations of services that used runit_service
as a definition, but may support alternate service styles, use a conditional, such as based on an aspect:
service_to_notify = case node [ 'nginx' ] [ 'init_style' ] when "runit" "runit_service[nginx]" else "service[nginx]" end template "/etc/nginx/nginx.conf" do notifies :restart , service_to_notify end
More than Examples
For more examples, see the runit_test
cookbook'southward service
recipe in the git repository.
Development
You may use test kitchen with either the vagrant or docker drivers to run integration tests.
Annotation: When using the docker driver delight ensure that the container you are using has a working init system, equally runit expects to be started by init. In some cases, systemd may need to be run in privileged mode.
For instance, for ubuntu with upstart:
driver_config: image: ubuntu-upstart:14.04 run_command: /sbin/init
For redhat derivatives:
driver_config: paradigm: dockerhub/image-with-systemd run_command: /usr/sbin/init privileged: true
License & Authors
- Author:: Adam Jacob adam@chef.io
- Author:: Joshua Timberman joshua@chef.io
- Author:: Sean OMeara sean@sean.io
Copyright:: 2008-2019, Chef Software, Inc Licensed nether the Apache License, Version 2.0 (the "License"); y'all may not apply this file except in compliance with the License. You may obtain a re-create of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable police force or agreed to in writing, software distributed under the License is distributed on an "As IS" Footing, WITHOUT WARRANTIES OR Conditions OF ANY KIND, either express or unsaid. Run across the License for the specific language governing permissions and limitations under the License.
Source: https://github.com/chef-cookbooks/runit
Posted by: cristevich1945.blogspot.com
0 Response to "Is There Anyway To Use Erb Templates Not Stored In Cookbook"
Post a Comment