Restart another service in configure hook

Hi there,

Got a quick question, is it possible to restart another service in the snap’s configure hook script? I am trying to allow some settings from command line snap set SNAP_NAME settings=something. When the snap service started, the configure hook was loaded and the error message returned as systemctl: Permission denied.


you can restart any service the snap ships inside with snapctl restart $SNAP_NAME.<service name> … you can not restart any services outside of the snap (unless there is an interface that explicitly allows this but even then it is usually through a dbus call and not by giving access to the hosts systemctl command (for obvious security reasons))

1 Like

Thanks @ogra, I guess the command to set a parameter, like snap set system a=b, cannot run in configure hook for it failed in my codes. :slight_smile:

i dont think you can set system options from a snap hook but if you would it would again be snapctl set ... not snap set ... the snap binary is not accessible from inside a snap package, snapctl provides a (limited) route to the features the snap command offers …

system options need to either be set manually (or from a script or tool) outside of confinement or via an entry in a gadget.yaml in case you are on Ubuntu Core

1 Like

Thanks for the hint, and I believe it should work with snapctl set system.journal.persistent=true (I have not tried in an image yet :slight_smile: ) Is journalctl command allowed to run in configure hook? I used snap run --shell snap_name.application, then the command journalctl returned Permission Denied.

you will need the log-observe interface defined and connected for the hook , then you can execute it from the path described in the interface (i dont think it is in $PATH by default)

EDIT: oops, i’m blind, /usr/bin/journalctl is actually in there, so it should just work after connecting the interface.

wow, awesome, thanks @ogra :+1:

Thanks for this subject of discussion, it helped me too. :+1: I appreciate that!