Public bug reported:

The documentation for the 'hook' scripts is somewhat ambiguous.

I tried to include 'snap set' commands from within the install hook
which just causes the hook to hang (I'm guess the set command is waiting
for the install to finish which it never will).

I would like to suggest the following doco changes for the hook scripts


-------------------- CURRENT ---------------------------------
Hooks types

“configure”

The configure hook is called upon initial snap install (after any
services contained by the snap have started), after a refresh, and
whenever the user requests a configuration change via the snap set
command. If the hook exits non-zero, the configuration will not be
applied.

snap set / snap get

The snap set and snap get commands to write or read a configuration
value inside a snap through a “configure” hook are operated the
following way:

snap set <snap name> <key>=<value>
snap get <snap name> <key>
Note that the configure hook is called without parameters. From within a hook, 
configuration values passed by the user can be retrieved with the snapctl get 
<key> command, which implies the following order of operation for a snap set 
command:

The user runs snap set some-app username=foo to change the “username” value in 
the some-app snap.
snapd runs the configure hook shipped with some-app.
The configure hook iterates over possible configuration keys (which username is 
part of) by calling snapctl get <key> and does something with them (eg. update 
a configuration file of the application).


----------------------------------- SUGGESTED - feel free to make any
edits.

Hooks types

“configure”

The configure hook is called when the snap is first installed (and after
any services contained within the snap have started), after a refresh,
and whenever the user requests a configuration change via the snap set
command.

If the hook exits non-zero, the configuration will not be applied.


snap set / snap get

The snap set and snap get commands are available to the user to write or
read configuration values for a snap. The snap set/get commands store
key/value pairs in a keystore specific to your snap.

Your hook script can read/write these values by calling 
snapctl get <key>
snapctl set <key>=<value>

When the user runs 'snap set' your “configure” hook is called to notify
it that a change has been made. If the user runs 'snap get' your
"configure" will NOT be called.

Note that the configure hook is called without parameters. This means
its up to you to check each key/value to see if any have changed. There
is no way for your configure hook to iterate over the list of keys, as
such you hook must know what key names it needs to check.

What your configure hook does when notified is completely up to you, but
often it you will want to update one of your configuration files or may
be a database value.


A typical workflow might be:

1. The user runs `snap set some-app username=foo`
2. snapd updates the snap keystore for 'some-app'. The 'username' key now has a 
value of 'foo'
3. snapd runs the configure hook shipped with some-app.
4. The configure hook iterates over the known configuration keys (which 
username is part of) by calling snapctl get <key> and does something with each 
key/value (eg. update you database connection string).

** Affects: snap (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1745066

Title:
  Snap documatation of hook changes

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/snap/+bug/1745066/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to