kornelski / cargo-deb

Make Debian packages directly from Rust/Cargo projects
https://lib.rs/cargo-deb
MIT License
432 stars 52 forks source link

Inconsistent postinst generation across multiple services #137

Open aznhe21 opened 3 months ago

aznhe21 commented 3 months ago

It seems that the order of the systemd-units changes the result of generating the postinst file.

This metadata generates postinst-systemd-dont-enable based postinst.

[package.metadata.deb]
maintainer-scripts = "debian/"
systemd-units = [
  { unit-name = "foo" },
  { unit-name = "bar", start = false, enable = false },
]
generated postinst ```sh #!/bin/sh set -e # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if deb-systemd-helper debian-installed foo.service; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask foo.service >/dev/null || true if deb-systemd-helper --quiet was-enabled foo.service; then # Create new symlinks, if any. deb-systemd-helper enable foo.service >/dev/null || true fi fi # Update the statefile to add new symlinks (if any), which need to be cleaned # up on purge. Also remove old symlinks. deb-systemd-helper update-state foo.service >/dev/null || true fi # End automatically added section # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then deb-systemd-invoke try-restart bar.service foo.service >/dev/null || true fi fi fi # End automatically added section ```

This metadata generates postinst-systemd-enable based postinst.

[package.metadata.deb]
maintainer-scripts = "debian/"
systemd-units = [
  { unit-name = "bar", start = false, enable = false },
  { unit-name = "foo" },
]
generated postinst ```sh #!/bin/sh set -e # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask foo.service >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled foo.service; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable foo.service >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state foo.service >/dev/null || true fi fi # End automatically added section # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi deb-systemd-invoke $_dh_action bar.service foo.service >/dev/null || true fi fi # End automatically added section ```
ximon18 commented 3 months ago

I created the functionality in question. I assume this is either a bug, or a feature of the original debian logic that I copied, but off the top of my head I don't know which, I'm leaning towards bug in my code. I don't know when I'll be able to look at this, I'll see if I can find some time.