summaryrefslogtreecommitdiff
path: root/dh_runit
diff options
context:
space:
mode:
authorDmitry Bogatov <KAction@gnu.org>2016-06-04 16:22:47 +0300
committerDmitry Bogatov <KAction@gnu.org>2016-06-04 16:22:47 +0300
commitdc74a67ae5e1e13b8fb815236dd8efdfce962ba0 (patch)
treec8a1a1425f1e412f310eca651b303d6c3092fd39 /dh_runit
Initial commit
Diffstat (limited to 'dh_runit')
-rwxr-xr-xdh_runit96
1 files changed, 96 insertions, 0 deletions
diff --git a/dh_runit b/dh_runit
new file mode 100755
index 0000000..dec7c5a
--- /dev/null
+++ b/dh_runit
@@ -0,0 +1,96 @@
1#!/usr/bin/perl -w
2
3=head1 NAME
4
5dh_runit - install/enable runit runscripts
6
7=cut
8
9use strict;
10use Debian::Debhelper::Dh_Lib;
11use File::Find;
12use Path::Tiny;
13use File::stat;
14
15=head1 SYNOPSIS
16
17B<dh_runit> [S<I<debhelper options>>] [B<--no-enable>]
18
19=head1 DESCRIPTION
20
21B<dh_runit> is a debhelper program that is responsible for
22installing and enabling I<runit> runscripts. If file named
23F<debian/I<package>.runit> exists, then different actions
24are performed, depending on its format.
25
26For runit, every unit of supervision, simply speaking program, is
27represented by directory under F</etc/sv>, containing at least F<run>
28executable file. Every enabled program is represented by symbolic link
29under F</etc/services> pointing to some directory under F</etc/sv>.
30
31If F<debian/I<package>.runit> is not executable, but contains shebang
32(#!) in first line, it is installed as F</etc/sv/I<package>/run> and
33enabled.
34
35Alternatively, F<debian/I<package>.runit> is a list of lines, where
36every line is either starts with hash symbol and considered comment,
37or contains two or three space-separated words.
38
39 # In this case file is installed as 'run' script. Directory name under
40 # /etc/sv is derived from file basename
41 enable path/to/file/to/be/installed/as/run/script
42
43 # Same, but install directory as whole. It is your responsibility
44 # to ensure is contains everything required.
45 enable path/to/directory
46
47 # Same as above, but do not create symlink under /etc/service
48 disable path/to/directory
49
50 # Also, you can explicitly specify name of directory under /etc/sv
51 enable path/to/directory my-preferred-name
52
53=head1 OPTIONS
54
55=over 4
56
57=item B<--no-enable>
58
59Do not enable any runscripts. Useful, when F<debian/I<package>.runit>
60is the only runscript, in which case you have no other ways to
61specify, that it should not be enabled.
62
63=back
64
65=cut
66
67init(option => { 'no-enable' => \$dh{NO_ENABLE} });
68
69PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
70 next if is_udeb($pkg);
71
72 my $tmp = tmpdir($pkg);
73 my $sv_dir = "$tmp/etc/sv";
74 my $runit = pkgfile($pkg, 'runit');
75 next unless $runit;
76
77 doit('install', '-d', $sv_dir);
78
79 for my $line (path($runit)->lines) {
80 next if ($line =~ /^#/); # skip comments
81 next if ($line =~ /^\s*$/); # skip empty lines
82 (my $enable, my $path, my $name) = split /\s/, $line;
83 $name = $name || basename($path);
84
85 error("can't read `$path'") unless -r $path;
86
87 if ( -f $path) {
88 doit('install', 'd', '-m755', $path, "$sv_dir/$name/run");
89 } elsif ( -d $path) {
90 doit('cp', '-r', $path, "$sv_dir/$name");
91 }
92 if ($enable -eq 'enable' && !$DH{NO_ENABLE}) {
93 }
94 }
95}
96