← Back to team overview

touch-packages team mailing list archive

[Bug 1439793] Re: deb-systemd-helper crashes while removing packages with unusual (but legal) Alias in unit config

 

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

** Changed in: init-system-helpers (Ubuntu)
   Importance: Undecided => Medium

** Changed in: init-system-helpers (Ubuntu)
     Assignee: (unassigned) => Martin Pitt (pitti)

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to init-system-helpers in
Ubuntu.
https://bugs.launchpad.net/bugs/1439793

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

Status in init-system-helpers package in Ubuntu:
  Triaged

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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/init-system-helpers/+bug/1439793/+subscriptions


References