deb-systemd-helper crashes while removing packages with unusual (but legal) Alias in unit config

Bug #1439793 reported by Oleg Strikov
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
init-system-helpers (Ubuntu)
Fix Released
Medium
Martin Pitt

Bug Description

While working on mysql-5.6 package we met unusual (maybe even partially incorrect) Alias option in systemd unit config:
Alias=mysql.service
It is unusual because mysql.service is the original name of the service which can be found inside /lib/systemd/system/<...> This Alias option doesn't make any sense (mysql service will be accessible as mysql.service even without this alias) and my assumption is that it was created because the author was not sure if it's okay not to have any aliases at all or you need at least one. Anyhow this seems to be legal to do that (i was not able to find any documents which state that this is incorrect) even if it's something useless.

Installation went well and the following alias symlink has been created:
/etc/systemd/system/mysq.service --> /lib/systemd/system/mysql.service
Service was accessible via systemctl and everything was fine.

When you try to remove/purge the package you get the following error:
/usr/bin/deb-systemd-helper: error: unable to link /etc/systemd/system/mysql.service to /dev/null: File exists
This happens because deb-systemd-helper tries to 'mask' service the following way:

sub mask_service {
    my ($scriptname, $service_path) = @_;

    my $mask_link = '/etc/systemd/system/' . basename($service_path);

    if (-e $mask_link) {
        # If the link already exists, don’t do anything.
        return if -l $mask_link && readlink($mask_link) eq '/dev/null';

        debug "$mask_link already exists, not masking.";
        return;
    }

    make_path(dirname($mask_link));
    symlink('/dev/null', $mask_link) or
        error("unable to link $mask_link to /dev/null: $!");
<...>
}

Check for '-e $mask_link' FAILS because symlink's TARGET (/lib/systemd/system/mysql.service) doesn't exists while doing postrm and '-e' FOLLOWS symlinks. That's why we go to symlink(...) call directly which fails because symlink already exists.

WORKAROUND: If apt-get remove/purge crashes with the error mentioned above you need to manually remove symlink inside /etc/systemd/system (/etc/systemd/system/mysql.service in our case) and rerun apt-get remove/purge.

I'm not sure if we want to fix that.
On one hand, this situation is pretty rare.
On other hand though, such Alias=<original-name> situation is somewhat legal and we may want to handle it correctly.

This issue with Alias= has been fixed (by removing this useless Alias) in mysql-5.6 so that's not a blocker for us.

Tags: systemd-boot
description: updated
Robie Basak (racb)
tags: added: systemd-boot
Revision history for this message
Martin Pitt (pitti) wrote :

Simple reproducer:

$ cat /lib/systemd/system/selfalias.service
[Unit]
Description=alias to self

[Service]
ExecStart=/bin/true

[Install]
WantedBy=multi-user.target
Alias=selfalias.service

$ sudo DPKG_MAINTSCRIPT_PACKAGE=1 deb-systemd-helper enable selfalias.service
$ sudo mv /lib/systemd/system/selfalias.service{,.removed}
$ sudo _DEB_SYSTEMD_HELPER_DEBUG=1 DPKG_MAINTSCRIPT_PACKAGE=1 deb-systemd-helper mask selfalias.service

Changed in init-system-helpers (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → Martin Pitt (pitti)
Martin Pitt (pitti)
Changed in init-system-helpers (Ubuntu):
status: Triaged → In Progress
Revision history for this message
Martin Pitt (pitti) wrote :

I added a couple of test cases for existing functionality, and now added a test and a fix for this bug:

  http://anonscm.debian.org/cgit/collab-maint/init-system-helpers.git/commit/?id=19802a7555904

Changed in init-system-helpers (Ubuntu):
status: In Progress → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package init-system-helpers - 1.22ubuntu9

---------------
init-system-helpers (1.22ubuntu9) vivid; urgency=medium

  Cherry-pick tests and a bug fix from Debian git:
  * t/001-deb-systemd-helper.t: Verify that the commands exit successfully.
  * t/001-deb-systemd-helper.t: Add tests for Alias= handling.
  * t/001-deb-systemd-helper.t: Add tests for Alias and mask handling with
    uninstalled .service file (as in package postrm scripts).
  * deb-systemd-helper: Ignore Also= and Alias= referring to itself, and avoid
    mask symlink creation errors on systems where units with those have
    already been installed. Add corresponding test to
    001-deb-systemd-helper.t. (LP: #1439793)
 -- Martin Pitt <email address hidden> Thu, 09 Apr 2015 13:10:17 +0200

Changed in init-system-helpers (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.