#!/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 [S>] =head1 DESCRIPTION B is a debhelper program that is responsible for installing and enabling I runscripts. If file named F.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, containing at least F executable file. Every enabled program is represented by symbolic link under F pointing to some directory under F. F.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); install_dir("/var/lib/runit/supervise/$name"); 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