-
Notifications
You must be signed in to change notification settings - Fork 50
Add debhelper dh_installsystemd style support for systemd unit installation. #135
Conversation
I originally wrote this as a separate debhelper crate but wasn't sure that was warranted. I see in the configure me issue that a separate crate was considered. |
@kornelski: I imagine you are probably just busy, but if there is something I can do to progress this please let me know. |
This PR might interest you as it implements Debian debhelper (link) dh_installsystemd (link) logic for maintainer script augmentation/generation. I initially wrote it as a separate crate but as the only user I was aware of at the time was cargo deb that seemed overkill, but if there are other crates that want that logic it could be extracted to a crate. |
Thanks for heads up! I redesigned my projects quite a bit since I wrote it. I want to stay close to Debian policy and Using anything else than I'm now developing a separate packaging helper with those goals in mind. |
I considered making this new behaviour the default, i.e. that |
let mut file = if !outfile.exists() { | ||
File::create(&outfile).unwrap() | ||
} else { | ||
OpenOptions::new().append(true).open(&outfile).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo-deb
keeps other generated assets in memory, without needing to use a temp directory.
Writing stuff to and from file system looks cumbersome. Maybe it'd be simpler to have the scripts as String
in memory and just append lines to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that and agree with you. I didn't try that yet as I wanted first to get the debhelper dh_systemdinstall functionality working as it does in the original Perl implementation, then ensure I have tests passing that verify the working behaviour, then change the implementation to be in-memory based. I am happy to try updating it to work in-memory instead of with a temp folder.
Thanks! |
Thank you. Could you follow it up with a change to use in-memory objects instead of file rewrites and appends? |
Yes, I was just working on that :-) |
This PR contains a Rust implementation of the Debian debhelper dh_installsystemd functionality which augments or generates maintainer scripts such that when
systemd_units
is configured, shell script fragments "for enabling, disabling, starting, stopping and restarting systemd unit files" (quoting man 1 dh_installsystemd) will replace the#DEBHELPER#
token in the provided maintainer scripts (or provide the entire script if missing).The README.md has now been updated on how to use this functionality.
Note: I wasn't aware of the discussion in #106 when I wrote this.
There are no tests included in this PR yet. I have some tests I started writing but they are out of date for the code as it is now. I thought it best to first get some feedback and no doubt the code can be improved with review.
I am using this to improve the .deb archives I have created as part of the NLnet Labs Krill project. In that project I have 5 variants and prior to this PR require almost identical asset blocks in each variant in order to select different systemd unit files by target O/S version, and hand coded the maintainer scripts.
With this PR I fix issues in my maintainer scripts by adding systemd unit management shell script fragments exactly how Debian suggests it should be done and also reduce duplication in my Cargo.toml as the variant is used to select the right unit file and add it as an asset automatically.
By default systemd unit files are looked for in the maintainer scripts directory. This can be overriden by providing a units directory to the
systemd_units
TOML (inline) table. Here's my currentsystemd_units
configuration:The enable, start, etc options match the options that can be passed to
dh_installsystemd
.Example output when run with
-v
:Feedback very appreciated!