#!/usr/bin/execlineb -P

# Debian ships /usr/lib/tmpfiles.d/puppetserver.conf with
#   d /var/run/puppetlabs/puppetserver 0755 puppet puppet -
# s6 has no tmpfiles.d handling, and run-script-daemon only creates
# /run/$(basename $DAEMON) = /run/puppetserver, which is not the path
# puppetserver uses. On puppet-1.crb2 the directory is missing altogether
# (dpkg -V puppetserver: "missing /var/run/puppetlabs"), which is exactly the
# kind of gap that only shows on a fresh installation.
if { mkdir -p /run/puppetlabs/puppetserver }
if { chown puppet:puppet /run/puppetlabs/puppetserver }
if { chmod 0755 /run/puppetlabs/puppetserver }
# E3: readiness is reported by data/check (status page on 8140 says "running"),
# not by the process start. -w 2000 -n 150: every 2 s, up to 5 minutes -- the
# first start with CA generation and JRuby pool takes considerably longer than
# a restart. After that the service stays "up, not ready", and s6-rc/svctl
# report that instead of a false success.
s6-notifyoncheck -d -w 2000 -n 150 --
run-script-daemon puppetserver
