summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Bogatov <KAction@gnu.org>2016-06-09 18:50:22 +0300
committerDmitry Bogatov <KAction@gnu.org>2016-06-09 18:50:22 +0300
commitfc35408ab60287a4e978ba93e61c2ded44342e7d (patch)
tree2d96b90cc3a03e1daeefb9d540046c6ae5efb634
parent9002e984d29480a3287506c73d82f247b0dbacea (diff)
Improve handling of maintainer scripts
* checking for /etc/service symlink is moved into preinst * runscripts are enabled in postinst * runscripts are disables in prerm * supervise directory is purged on 'postrm purge'
-rw-r--r--debian/dh-runit.install2
-rwxr-xr-xdh_runit10
-rw-r--r--postinst-runit19
-rw-r--r--postrm-runit12
-rw-r--r--preinst-runit19
-rw-r--r--prerm-runit3
6 files changed, 43 insertions, 22 deletions
diff --git a/debian/dh-runit.install b/debian/dh-runit.install
index faa7e8b..5b296b5 100644
--- a/debian/dh-runit.install
+++ b/debian/dh-runit.install
@@ -1,4 +1,6 @@
1dh_runit /usr/bin 1dh_runit /usr/bin
2preinst-runit /usr/share/debhelper/autoscripts
2postinst-runit /usr/share/debhelper/autoscripts 3postinst-runit /usr/share/debhelper/autoscripts
3prerm-runit /usr/share/debhelper/autoscripts 4prerm-runit /usr/share/debhelper/autoscripts
5postrm-runit /usr/share/debhelper/autoscripts
4runit.pm /usr/share/perl5/Debian/Debhelper/Sequence 6runit.pm /usr/share/perl5/Debian/Debhelper/Sequence
diff --git a/dh_runit b/dh_runit
index 16af671..13caec5 100755
--- a/dh_runit
+++ b/dh_runit
@@ -72,6 +72,10 @@ sub ensure_executable($directory) {
72 } 72 }
73} 73}
74 74
75sub runit_autoscript($pkg, $script, $sed) {
76 autoscript($pkg, $script, "$script-runit", $sed);
77}
78
75init(option => { 'no-enable' => \$dh{NO_ENABLE} }); 79init(option => { 'no-enable' => \$dh{NO_ENABLE} });
76 80
77PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) { 81PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
@@ -82,6 +86,7 @@ PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
82 my $runit = pkgfile($pkg, 'runit'); 86 my $runit = pkgfile($pkg, 'runit');
83 next unless $runit; 87 next unless $runit;
84 88
89 runit_autoscript($pkg, 'preinst', '');
85 install_dir($sv_dir); 90 install_dir($sv_dir);
86 91
87 for my $words (filedoublearray($runit)) { 92 for my $words (filedoublearray($runit)) {
@@ -102,9 +107,10 @@ PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) {
102 "/var/lib/runit/supervise/$name", $tmp); 107 "/var/lib/runit/supervise/$name", $tmp);
103 108
104 if ($enable eq 'enable' && !$dh{NO_ENABLE}) { 109 if ($enable eq 'enable' && !$dh{NO_ENABLE}) {
105 autoscript($pkg, 'postinst', 'postinst-runit', "s/#NAME#/$name/"); 110 runit_autoscript($pkg, 'postinst', "s/#NAME#/$name/");
106 } 111 }
107 autoscript($pkg, 'prerm', 'prerm-runit', "s/#NAME#/$name/"); 112 runit_autoscript($pkg, 'prerm', "s/#NAME#/$name/");
113 runit_autoscript($pkg, 'postrm', "s/#NAME#/$name/");
108 } 114 }
109 addsubstvar($pkg, 'misc:Depends', 'runit', '>= 2.1.2-4'); 115 addsubstvar($pkg, 'misc:Depends', 'runit', '>= 2.1.2-4');
110} 116}
diff --git a/postinst-runit b/postinst-runit
index 7c21f0e..1955857 100644
--- a/postinst-runit
+++ b/postinst-runit
@@ -1,20 +1,3 @@
1SV_ABS_DIR=/var/lib/runit/service
2SV_DIR=/etc/service 1SV_DIR=/etc/service
3mkdir -p "$SV_ABS_DIR"
4if [ ! -e "$SV_DIR" ] ; then
5 ln -s "$SV_ABS_DIR" "$SV_DIR"
6fi
7
8if [ "$(readlink -f "$SV_DIR")" != "$SV_ABS_DIR" ] ; then
9 cat <<EOF
10Service directory '$SV_DIR' exists, but is not symbolic link
11to '$SV_ABS_DIR'. It probably means that it was created by
12hand or versions of runit below 2.1.2-4.
13
14In either case, please remove service directory yourself and
15restart installation.
16EOF
17 exit 1
18fi
19ln -sf '/etc/sv/#NAME#' "$SV_DIR/" 2ln -sf '/etc/sv/#NAME#' "$SV_DIR/"
20mkdir -p /var/lib/runit/supervise/#NAME# 3mkdir -p '/var/lib/runit/supervise/#NAME#'
diff --git a/postrm-runit b/postrm-runit
new file mode 100644
index 0000000..9556830
--- /dev/null
+++ b/postrm-runit
@@ -0,0 +1,12 @@
1#!/bin/sh # just to convince emacs that it is shell script
2
3if [ "$1" = 'purge' ] ; then
4 # If runscript was never invoked, these files would not exist,
5 # so we use -f option of rm(1).
6 for file in control lock ok pid stat status ; do
7 rm -f "/var/lib/runit/supervise/#NAME#/$file"
8 done
9 # It should exist and be empty now. If it is not, either user touched it,
10 # or there is a BUG in dh-runit!
11 rmdir "/var/lib/runit/supervise/#NAME#"
12fi
diff --git a/preinst-runit b/preinst-runit
new file mode 100644
index 0000000..eaccc4a
--- /dev/null
+++ b/preinst-runit
@@ -0,0 +1,19 @@
1#!/bin/sh # -*- shell-script -*-
2SV_ABS_DIR=/var/lib/runit/service
3SV_DIR=/etc/service
4mkdir -p "$SV_ABS_DIR"
5if [ ! -e "$SV_DIR" ] ; then
6 ln -s "$SV_ABS_DIR" "$SV_DIR"
7fi
8
9if [ "$(readlink -f "$SV_DIR")" != "$SV_ABS_DIR" ] ; then
10 cat <<EOF
11Service directory '$SV_DIR' exists, but is not symbolic link
12to '$SV_ABS_DIR'. It probably means that it was created by
13hand or versions of runit below 2.1.2-4.
14
15In either case, please remove service directory yourself and
16restart installation.
17EOF
18 exit 1
19fi
diff --git a/prerm-runit b/prerm-runit
index b23abeb..08aae6b 100644
--- a/prerm-runit
+++ b/prerm-runit
@@ -1,2 +1 @@
1rm -f /etc/service/#NAME# rm -f '/etc/service/#NAME#'
2rm -fr /var/lib/runit/supervise/#NAME#/*