summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Nicolodi <daniele@grinta.net>2018-06-12 20:41:03 -0600
committerDaniele Nicolodi <daniele@grinta.net>2018-06-16 11:19:14 -0600
commita1afd1bc4808235b39db9d2a7e1cffd8d86743e7 (patch)
tree7c3da869f57b24887adaa9d99ebee8c789271334
parentefd04acfacb2df6455f1b389d6f7092dba18ff52 (diff)
downloaddebhelper-a1afd1bc4808235b39db9d2a7e1cffd8d86743e7.tar.gz
dh_installsystemd: Refactor
Make code easier to grock by splitting operation into three phases. The number of binary packages should be small. Iterating three times through their names should not impact performances.
-rwxr-xr-xdh_installsystemd79
1 files changed, 48 insertions, 31 deletions
diff --git a/dh_installsystemd b/dh_installsystemd
index 44ce6ebb..308cde41 100755
--- a/dh_installsystemd
+++ b/dh_installsystemd
@@ -206,26 +206,60 @@ my %installed_files;
my %snippet_options = ('snippet-order' => 'service');
+
+# Install package maintainer supplied unit files
foreach my $package (@{$dh{DOPACKAGES}}) {
my $tmpdir = tmpdir($package);
- my (@installed_units, @start_units, @enable_units, %aliases, @tmpfiles);
- # Figure out what filename to install it as.
- my $script;
- if (defined $dh{NAME}) {
- $script=$dh{NAME};
- }
- else {
- $script=$package;
+ # Intall all unit files in the debian/ directory with names in the
+ # form $package.(service|target|socket|path|timer|mount|tmpfile)
+ # and their templated versison when relevant.
+
+ # This can be modified with the --name option to look for unit
+ # files with names in the form $package.$name.(service|...) and
+ # $name.(service|target|socket|path|timer|mount|tmpfile) and their
+ # templated version when relevant.
+ my $name = $dh{NAME} // $package;
+
+ for my $type (qw(service target socket path timer)) {
+ install_unit($package, $name, $type, "$tmpdir/lib/systemd/system");
+ install_unit("${package}@", "${name}@", $type, "$tmpdir/lib/systemd/system");
}
- for my $service_type (qw(service target socket path timer)) {
- install_unit($package, $script, $service_type, "$tmpdir/lib/systemd/system");
- install_unit("${package}@", "${script}@", $service_type, "$tmpdir/lib/systemd/system");
+ install_unit($package, $name, 'mount', "$tmpdir/lib/systemd/system");
+ install_unit($package, $name, 'tmpfile', "$tmpdir/usr/lib/tmpfiles.d", 'conf');
+}
+
+
+# Add postinst code blocks to handle tmpfiles
+foreach my $package (@{$dh{DOPACKAGES}}) {
+ my $tmpdir = tmpdir($package);
+ my @tmpfiles;
+
+ if (-d $tmpdir) {
+ my @dirs = grep { -d } map { "${tmpdir}/$_" } qw(usr/lib/tmpfiles.d etc/tmpfiles.d);
+ find({
+ wanted => sub {
+ my $name = $File::Find::name;
+ return unless -f $name;
+ push(@tmpfiles, basename($name));
+ },
+ no_chdir => 1,
+ }, @dirs) if @dirs;
+
+ if (@tmpfiles) {
+ autoscript($package, 'postinst', 'postinst-init-tmpfiles', { 'TMPFILES' => join(' ', sort @tmpfiles) });
+ }
}
+}
- install_unit($package, $script, 'mount', "$tmpdir/lib/systemd/system");
- install_unit($package, $script, 'tmpfile', "$tmpdir/usr/lib/tmpfiles.d", 'conf');
+
+# Add postinst, prerm, and postrm code blocks to handle activation,
+# deactivation, start and stopping of services when the package is
+# installed, upgraded or removed.
+foreach my $package (@{$dh{DOPACKAGES}}) {
+ my $tmpdir = tmpdir($package);
+ my (@installed_units, @start_units, @enable_units, %aliases);
my $oldcwd = getcwd();
find({
@@ -323,23 +357,6 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
}
}
- # Include postinst-init-tmpfiles if the package ships any files
- # in /usr/lib/tmpfiles.d or /etc/tmpfiles.d
- if (-d $tmpdir) {
- my @dirs = grep { -d } map { "${tmpdir}/$_" } qw(usr/lib/tmpfiles.d etc/tmpfiles.d);
- find({
- wanted => sub {
- my $name = $File::Find::name;
- return unless -f $name;
- push(@tmpfiles, basename($name));
- },
- no_chdir => 1,
- }, @dirs) if @dirs;
- if (@tmpfiles > 0) {
- autoscript($package, 'postinst', 'postinst-init-tmpfiles', { 'TMPFILES' => join(' ', sort @tmpfiles) });
- }
- }
-
if (@enable_units) {
for my $unit (sort @enable_units) {
my $base = q{'} . basename($unit) . q{'};
@@ -354,7 +371,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
my $enableunitargs = join(' ', sort map { q{'} . basename($_) . q{'} } @enable_units);
autoscript($package, 'postrm', 'postrm-systemd', {'UNITFILES' => $enableunitargs });
}
-
+
if (@start_units) {
# The $package and $sed parameters are always the same.
# This wrapper function makes the following logic easier to read.