Support for snapctl stop/start/restart services

@ondra That’s planned and in fact most of the work has landed already with the implementation of snap start/stop/restart.

@pstolowski Do you want to push forward the implementation of the snapctl side? Should be relatively quick since most of the internal details have been nailed already.

@niemeyer I’m happy to take it, but from the conversations we had on IRC earlier this morning it seemed that @chipaca is going to implement exactly this for snapctl side. John, can you clarify?

@pstolowski Right, exactly. As I said above it was already planned and most of the work has landed. @chipaca has quite a few things on his plate, so the point was that if you want to push it forward sooner, that sounds reasonable too.

Naturally, talk to him so we don’t have the same thing done twice. :slight_smile:

yes, it sounded like @chipaca could take care of this

just to add, we chatted on IRC and @pstolowski is taking this

Correct, just convenient way to control own daemons

This is currently in progress. a PR should be up for a review soon.

1 Like


I believe that “snaps” have a promising future as a clear and easy way of packaging. Unfortunately, at my workstation (Ubuntu 16.04) few snaps work because my user belongs to Active Directory and snaps are unable to communicate with the SSSD service.

That is discussed in the thread below i think…

After more testing with this, I realise to take full advantage of this feature, can we add also enable and disable options? I’ve came across snap, with optional service, which should be run based on configuration. Rather that start stop it from service based on settings, configure hook would be ablate to enable/disable it based on settings? Also can I even call snapctl stop from service itself, or this is only permitted from configure hook? As with this restriction I’d not be even able to stop service in easy way. Unless calling snapctl set stopme=now and stopping service from configure hook :slight_smile:

@ondra The service-related commands in snapctl work from any place inside the snap, not just the configure hook. You can also enable/disable by using the options –enable and –disable for the start and stop commands, respectively.

1 Like

@niemeyer sweet, that should should address the use case.
I will look more into –enable and –disable for the start and stop commands. it definitely looks like something I want to use more

Are there any examples of start/stop/restart daemons by the daemon?

just use systemctl to restart your daemon service named as per /etc/systemd/system


$ sudo systemctl restart snap.my_snap_name.command.service

Dunno what you mean by “by the daemon” but best way is to control services from configure hook
Here is one example wekan

If you want to control this from another service, you can call snapctl set = which will trigger configure hook where you can start/stop/restart/enable/disable daemons…

@ondra I presume when you say ‘from another service’ it means another service from with in the same snap right ? If that is the case , if there a way to control the start/stop/restart of a service of one snap from another snap ? Thanks.

So you will need to use content interface to create connection between snaps here so snapctl is executed in context of snap running those services. It’d break confinement if one can control services of different snap.

Of course ideal solution here would be interface allowing one snap altering configuration settings of another snap
Sort of light content share… restricted only to configuration settings/
Then you can just implement configure hook in receiving snap and snapctl set in client snap

@pstolowski do you know is there is something like this in works or in backlog?

Thanks, Could you elaborate this " snapctl is executed in context of snap running those services" this seems to be something I am exploring. I have a content interface between two of my snaps to share data already, so will I be able to control the consumer snap (with plugs defined) from my producer snap (with slots defined) with snapctl command ? To give a more precise explanation, here is what I am trying to do.

To restart SNAP-1 (Consumer) I can set a variable and config hook stops/starts the service depending on the value being set.

value=$(snapctl get mysnap-disable)
if [ "$value" = "true" ]; then
        snapctl stop --disable ${SNAP_NAME}.myser 2>&1 || true
        snapctl start --enable ${SNAP_NAME}.myser 2>&1 || true
        snapctl restart ${SNAP_NAME}.myser 2>&1 || true

And So I am trying to find a way to set this variable mysnap-disable from my producer snap (SNAP-2). Let me know if this is something that is feasible ?

At the moment we unfortunately don’t have interface for this, so I have opened forum post to discuss this in more generic way, feel free to contribute there:

configure hook code looks good, unfortunately I have not clean solution how to overcome this limitation