class {{.PuppetModuleName}}::install inherits {{.PuppetModuleName}} {
  if str2bool($is_canary) {
    $consul_tags = [$deploy_env, "${deploy_env}-canary"]
  } else {
    $consul_tags = [$deploy_env]
  }

  consul::service { 'deploy-target-{{.Name}}':
    consul_tags => $consul_tags,
  }

  realize(Package["bison"])
  realize(Package["flex"])
  realize(Package['libreadline-dev'])

  courier::install { '{{.Name}}':
    env     => $deploy_env,
    repo    => "{{.FullName}}",
    require => [Consul::Service['deploy-target-{{.Name}}'], Package["bison"], Package["flex"], Package['libreadline-dev']],
  }

  daemontools::supervise { '{{.Name}}':
    daemon_dir     => '/var/lib/service',
    user           => 'nobody',
    syslog         => 'local3',
    enable_cgroups => true,
    wd             => '/opt/twitch/{{.Name}}/current',
    daemon         => "bundle exec puma --preload -w ${processorcount} -p 8000 2>&1",
    predaemon      => [
      'export PATH=/home/jtv/.rbenv/bin:/home/jtv/.rbenv/shims:$PATH',
      "export RBENV_ROOT=/home/jtv/.rbenv/",
      "export RACK_ENV=${deploy_env}",
      "export ROLLBAR_TOKEN=${rollbar_token}",
      "export STATSD_HOST_PORT=localhost:8125",
    ]
  }
}