summaryrefslogtreecommitdiff
path: root/dh_runit
blob: fa1976362330e389a6de4dd11eace42f2afc005d (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w

=head1 NAME

dh_runit - install/enable runit runscripts

=cut

use strict;
use Debian::Debhelper::Dh_Lib;
use File::Find;
use File::stat;
use feature 'signatures';
no warnings 'experimental::signatures';

=head1 SYNOPSIS

B<dh_runit> [S<I<debhelper options>>]

=head1 DESCRIPTION

B<dh_runit> is a debhelper program that is responsible for
installing and enabling I<runit> runscripts. If file named
F<debian/I<package>.runit> exists, then different actions
are performed, depending on its format.

For runit, every unit of supervision, simply speaking program, is
represented by directory under F</etc/sv>, containing at least F<run>
executable file. Every enabled program is represented by symbolic link
under F</etc/services> pointing to some directory under F</etc/sv>.

F<debian/I<package>.runit> is a list of lines, where
every line is either starts with hash symbol and considered comment,
or contains two or three space-separated words.

  # In this case file is installed as 'run' script. Directory name under
  # /etc/sv is derived from file basename
  enable path/to/file/to/be/installed/as/run/script

  # Same, but install directory as whole. It is your responsibility
  # to ensure is contains everything required.
  enable path/to/directory

  # Same as above, but do not create symlink under /etc/service
  disable path/to/directory

  # Also, you can explicitly specify name of directory under /etc/sv
  enable path/to/directory my-preferred-name

=cut

sub ensure_executable($directory) {
    for my $f ('run', 'finish', 'log/run', 'log/finish') {
        my $file = "$directory/$f";
        doit('chmod', '+x', $file) if (-e $file);
    }
}

sub runit_autoscript($pkg, $script, $sed) {
    autoscript($pkg, $script, "$script-runit", $sed);
}

init();

PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
    next if is_udeb($pkg);

    my $tmp = tmpdir($pkg);
    my $sv_dir = "$tmp/etc/sv";
    my $runit = pkgfile($pkg, 'runit');
    next unless $runit;

    runit_autoscript($pkg, 'preinst', '');
    install_dir($sv_dir);

    for my $words (filedoublearray($runit)) {
        (my $enable, my $path, my $name) = @{$words};
        $name = $name || basename($path);

        error("can't read `$path'") unless -r $path;

        if ( -f $path) {
            install_dir("$sv_dir/$name");
            install_prog($path, "$sv_dir/$name/run");
        } elsif ( -d $path) {
            doit('cp', '-r', $path, "$sv_dir/$name");
            # Unfortunately, dh_fixperms does not handle executable bit here.
            ensure_executable("$sv_dir/$name");
        }
        make_symlink("/etc/sv/$name/supervise",
                     "/var/lib/runit/supervise/$name", $tmp);

        if ($enable eq 'enable' && !$dh{NO_ENABLE}) {
            runit_autoscript($pkg, 'postinst', "s/#NAME#/$name/");
        }
        runit_autoscript($pkg, 'prerm',  "s/#NAME#/$name/");
        runit_autoscript($pkg, 'postrm', "s/#NAME#/$name/");
    }
    addsubstvar($pkg, 'misc:Depends', 'runit', '>= 2.1.2-4');
}

# PROMISE: DH NOOP WITHOUT runit