Add One-shot Install/Uninstall Hook

Bug #1661126 reported by Matt Middleton
50
This bug affects 9 people
Affects Status Importance Assigned to Milestone
snapd
Fix Released
Undecided
Paweł Stołowski

Bug Description

It would be nice to have a hook that is executed once on install / uninstall ( and possibly upgrade ) and that is guaranteed to run before any daemons are launched. This would allow for configs, databases, etc to be properly configured for daemons that require it. I'm currently snapping a daemon that I'm unable to modify and would benefit very much from this addition and I assume this would also benefit people that need to snap daemons that are not rewritten exclusively for the snap environment as well as 'classic mode' daemons that need to setup other parts of the system, users, etc..

Revision history for this message
Mark Shuttleworth (sabdfl) wrote : Re: [Bug 1661126] [NEW] Add One-shot Install/Uninstall Hook

Yes, I've run into this challenge making snaps too.

The only question in my mind, though, is whether you don't actually want
to run a sanity check of config etc on every launch, anyway, to deal
with cases of corruption. What I did was sanity check config and restore
if needed (or recreate from a template) when the daemon is being
launched. That would slow down launch slightly but provide a very high
level of certainty on every launch.

Mark

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in snapd (Ubuntu):
status: New → Confirmed
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

I'd like this as well. The only way to do things like this today is to wrap the services that require configs (or databases, whatever) in a script and make that script the daemon. It'd be great if that was an optional step (e.g. if I wanted to verify a config before launching it, as Mark mentioned) and the heavy lifting of generating things needed in order to run was handled in a dedicated place. Having wrappers for all my daemons makes my snap difficult to navigate and maintain.

Revision history for this message
Kyle Fazzari (kyrofa) wrote :

@Matt, I'd like to hear about your use-case for an uninstall hook. I typically think of this as a "clean up behind yourself" hook, but since when removing a snap the snap itself and all its writable areas are blown away, I don't have a clear picture for how an uninstall hook would be useful.

Revision history for this message
Matt Middleton (mmiddleton) wrote : Re: [Bug 1661126] Re: Add One-shot Install/Uninstall Hook

@Kyle - currently I'm making a snap for a daemon I cannot modify that runs in classic confinement and specifically requires a user to be added to the system. In the short term, it may also be necessary to add udev rules, systemctl configs, network manager dispatch scripts, etc. This may be abusing the very nice encapsulating aspect of snaps but that seems to be implied by classic confinement and I think is likely that people porting legacy software to snap distribution may face similar challenges.

> On 3/02/2017, at 5:46 AM, Kyle Fazzari <email address hidden> wrote:
>
> @Matt, I'd like to hear about your use-case for an uninstall hook. I
> typically think of this as a "clean up behind yourself" hook, but since
> when removing a snap the snap itself and all its writable areas are
> blown away, I don't have a clear picture for how an uninstall hook would
> be useful.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1661126
>
> Title:
> Add One-shot Install/Uninstall Hook
>
> Status in snapd package in Ubuntu:
> Confirmed
>
> Bug description:
> It would be nice to have a hook that is executed once on install /
> uninstall ( and possibly upgrade ) and that is guaranteed to run
> before any daemons are launched. This would allow for configs,
> databases, etc to be properly configured for daemons that require it.
> I'm currently snapping a daemon that I'm unable to modify and would
> benefit very much from this addition and I assume this would also
> benefit people that need to snap daemons that are not rewritten
> exclusively for the snap environment as well as 'classic mode' daemons
> that need to setup other parts of the system, users, etc..
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1661126/+subscriptions

________________________________

Wynright Corporation Disclaimer - The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, copying, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you believe you have received this email in error (whether inadvertently addressed to you, or if forwarded to you by a recipient), please contact the sender and delete this material from your computer.

Kyle Fazzari (kyrofa)
affects: snapd (Ubuntu) → snapd
Revision history for this message
Kyle Fazzari (kyrofa) wrote :

@Matt that seems like a valid use-case to me, thanks!

Revision history for this message
Brian Murray (brian-murray) wrote :

My use-case for an uninstall hook is modifying items in "/proc/sys" back to their original state e.g. apport would modify "/proc/sys/kernel/core_pattern".

tags: added: conjure
Revision history for this message
James Jesudason (jamesj) wrote :

The install hook would be useful in a snap that I'm working on that includes postgresql embedded in the snap. That has an additional challenge as the database initialization needs to be done as a non-root user, so having a hooks that run as the logged-in user and the root user (since daemons run as root) would be useful.

Revision history for this message
Nish Aravamudan (nacc) wrote :

Just an FYI as an also interested party, the install/uninstall hook landed upstream: https://github.com/snapcore/snapd/pull/3498. I have no idea how to figure out if this is in any releases.

Revision history for this message
Boris Rybalkin (ribalkin) wrote :

To me it is half done as only fixes config generation on install (https://github.com/snapcore/snapd/blob/master/overlord/snapstate/snapstate.go#L173), but how about upgrade when I bring fixes with config templates? Should there be an upgrade hook as well?

My simple version of it contains pre-startup hook which runs always on install or upgrade (https://github.com/syncloud/snapd/blob/master/overlord/snapstate/snapstate.go#L171)

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Refresh (upgrade) hook is also in the review queue, we just try to keep changes minimal and land them separetly.

Zygmunt Krynicki (zyga)
Changed in snapd:
assignee: nobody → Paweł Stołowski (stolowski)
Revision history for this message
Michael Vogt (mvo) wrote :
Changed in snapd:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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