summaryrefslogtreecommitdiff
path: root/manifests
diff options
context:
space:
mode:
authorMarkus Strauss <Markus@ITstrauss.eu>2011-10-27 20:34:29 -0400
committerMarkus Strauss <Markus@ITstrauss.eu>2011-10-27 20:34:29 -0400
commit8bd3fba55a717bae459ead2b03bc7ccdd9f2a82e (patch)
tree3926de63459638b055852d0b97eb7540ddac426a /manifests
downloadpuppet-runit-8bd3fba55a717bae459ead2b03bc7ccdd9f2a82e.tar.gz
puppet-runit-8bd3fba55a717bae459ead2b03bc7ccdd9f2a82e.tar.bz2
Initial commit
Diffstat (limited to 'manifests')
-rw-r--r--manifests/directory.pp7
-rw-r--r--manifests/init.pp18
-rw-r--r--manifests/service.pp52
-rw-r--r--manifests/service/enabled.pp30
-rw-r--r--manifests/service/env.pp22
5 files changed, 129 insertions, 0 deletions
diff --git a/manifests/directory.pp b/manifests/directory.pp
new file mode 100644
index 0000000..45e3401
--- /dev/null
+++ b/manifests/directory.pp
@@ -0,0 +1,7 @@
+define runit::directory( $ensure = directory ) {
+
+ if !defined( File[$name] ) {
+ file{ $name: ensure => $ensure }
+ }
+
+}
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..95e8253
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,18 @@
+class runit( $ensure = present ) {
+
+ package { runit: ensure => $ensure }
+
+ if $ensure == present {
+
+ file {
+ '/etc/sv':
+ ensure => directory,
+ ;
+ '/etc/service':
+ ensure => directory,
+ ;
+ }
+
+ }
+
+}
diff --git a/manifests/service.pp b/manifests/service.pp
new file mode 100644
index 0000000..56433fd
--- /dev/null
+++ b/manifests/service.pp
@@ -0,0 +1,52 @@
+define runit::service (
+ $user = root, # the service's user name
+ $group = root, # the service's group name
+ $enable = true, # shall the service be linked to /etc/service
+ $ensure = present, # shall the service be present in /etc/sv
+ $logger = false, # shall we setup an logging service
+ # either one of these must be given:
+ $source = undef, # either source or content must be defined;
+ $content = undef # this will be the run script /etc/sv/$name/run
+) {
+
+ # resource defaults
+ File { owner => root, group => root, mode => 644 }
+
+ $svbase = "/etc/sv/${name}"
+
+ # creating the logging sub-service, if requested
+ if $logger == true {
+ runit::service{ "${name}/log":
+ user => $user, group => $group, enable => false, ensure => $ensure, logger => false,
+ content => template('runit/logger_run.erb'),
+ }
+ }
+
+ # the main service stuff
+ file {
+ "${svbase}":
+ ensure => $ensure ? {
+ present => directory,
+ default => absent,
+ },
+ purge => true,
+ ;
+ "${svbase}/run":
+ content => $content,
+ source => $source,
+ ensure => $ensure,
+ mode => 755,
+ ;
+ }
+
+ # eventually enabling the service
+ if $ensure == present and $enable == true {
+ $_ensure_enabled = present
+ } else {
+ $_ensure_enabled = absent
+ }
+
+ debug( "Service ${name}: ${_ensure_enabled}" )
+
+ runit::service::enabled { $name: ensure => $_ensure_enabled }
+}
diff --git a/manifests/service/enabled.pp b/manifests/service/enabled.pp
new file mode 100644
index 0000000..1a71f4d
--- /dev/null
+++ b/manifests/service/enabled.pp
@@ -0,0 +1,30 @@
+define runit::service::enabled( $ensure = present ) {
+
+ # enabling the service by creating a symlink in /etc/service
+ file { "/etc/service/${name}":
+ target => "/etc/sv/${name}",
+ ensure => $ensure ? {
+ present => link,
+ default => absent,
+ },
+ }
+
+ if $ensure == present {
+
+ # subscribe to any run file changes
+ File["/etc/sv/${name}/run"] ~> Runit::Service::Enabled[$name]
+
+ # we also require notification from all environment variables
+ Runit::Service::Env <| service == $name |> {
+ notify +> Runit::Service::Enabled[$name]
+ }
+
+ exec { "sv restart ${name}":
+ subscribe => File["/etc/service/${name}"],
+ command => "/usr/bin/sv -w 60 restart /etc/sv/${name}",
+ refreshonly => true,
+ }
+
+ }
+
+}
diff --git a/manifests/service/env.pp b/manifests/service/env.pp
new file mode 100644
index 0000000..3e22d7a
--- /dev/null
+++ b/manifests/service/env.pp
@@ -0,0 +1,22 @@
+# the env $name must be unique
+define runit::service::env( $service, $value, $ensure = present ) {
+
+ $envdir = "/etc/sv/${service}/env"
+
+ # create this directory if at least one environment variable is defined
+ if !defined( File["/etc/sv/${service}/env"] ) {
+ file{ "/etc/sv/${service}/env":
+ ensure => directory,
+ # all unmanaged envs. will be removed
+ recurse => true,
+ purge => true,
+ }
+ }
+
+ # runit::directory { $envdir: }
+ file { "${envdir}/${name}":
+ ensure => $ensure,
+ content => "${value}\n",
+ }
+
+}