summaryrefslogtreecommitdiff
path: root/manifests/service/enabled.pp
blob: 1a71f4db0ec0af7458705e0b4e2468633e399e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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,
    }

  }
  
}