summaryrefslogtreecommitdiff
path: root/dh_runit
diff options
context:
space:
mode:
Diffstat (limited to 'dh_runit')
-rwxr-xr-xdh_runit38
1 files changed, 27 insertions, 11 deletions
diff --git a/dh_runit b/dh_runit
index 3f45866..9147607 100755
--- a/dh_runit
+++ b/dh_runit
@@ -7,9 +7,33 @@ use Debian::Debhelper::Dh_Lib;
7use File::Find; 7use File::Find;
8use File::Path qw(make_path); 8use File::Path qw(make_path);
9use File::stat; 9use File::stat;
10use Text::Hogan::Compiler;
11use File::Slurp qw(read_file write_file);
10use feature 'signatures'; 12use feature 'signatures';
11no warnings 'experimental'; 13no warnings 'experimental';
12 14
15# Render mustache template {name} from data directory into {dest},
16# substituting {values} hash. If {perm} argument is provided, it is used
17# set permissions of {dest}. Intermediate directories to ${dest} are
18# created as needed.
19#
20# Data directory is specified by {DH_RUNIT_DATADIR} environment
21# variable, and defaults to /usr/share/dh-runit/data.
22sub template_from_data_directory {
23 my ($name, $dest, $values, $perm) = @_;
24 my $datadir = $ENV{DH_RUNIT_DATADIR} || "/usr/share/dh-runit/data";
25 my $template = read_file("${datadir}/${name}");
26 my $compiler = Text::Hogan::Compiler->new;
27 my $output = $compiler->compile($template)->render($values);
28
29 make_path(dirname($dest));
30 write_file($dest, $output);
31
32 if (defined $perm) {
33 chmod $perm, $dest;
34 }
35}
36
13sub parse_options($opts) { 37sub parse_options($opts) {
14 my $conf = { enable => 1, since => '0.0-0' }; 38 my $conf = { enable => 1, since => '0.0-0' };
15 for my $opt (split(/,/, $opts)) { 39 for my $opt (split(/,/, $opts)) {
@@ -98,17 +122,9 @@ PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
98 install_dir("$sv_dir/$name/log"); 122 install_dir("$sv_dir/$name/log");
99 install_dir($tmp . $logdir); 123 install_dir($tmp . $logdir);
100 124
101 my $run_log = "$sv_dir/$name/log/run"; 125 template_from_data_directory('logscript', "$sv_dir/$name/log/run",
102 open(RUN_LOG, ">$run_log") || die $!; 126 { logdir => $logdir }, 0755);
103 print RUN_LOG << "HERE"; 127
104#!/bin/sh
105chown -R runit-log:adm '$logdir'
106chmod 750 '$logdir'
107chmod u+rw,g+r,o-rwx '$logdir'/*
108exec chpst -u runit-log svlogd -tt '$logdir'
109HERE
110 close(RUN_LOG);
111 chmod(0755, $run_log);
112 make_symlink("/etc/sv/$name/log/supervise", 128 make_symlink("/etc/sv/$name/log/supervise",
113 "/var/lib/runit/log/supervise/$name", $tmp); 129 "/var/lib/runit/log/supervise/$name", $tmp);
114 install_dir("$tmp/var/lib/runit/log/supervise/$name"); 130 install_dir("$tmp/var/lib/runit/log/supervise/$name");