SystemD Unit file customization for a snap

Stuart Bishop stuart.bishop at
Thu Jan 12 04:33:01 UTC 2017

On 12 January 2017 at 02:31, Charles Butler <charles.butler at>

> Greetings,
> I'm working on an update to the etcd snap so we can make the Kubernetes
> etcd2 -> etcd3 migration simple, transactional, and hopefully more bullet
> proof in iterations to come. I've got a question regarding the SystemD
> Daemon unitfile.
> You can declare to snapcraft, that a bin should be treated as a daemon
> with very straightforward syntax
> apps:
>   etcd:
>     command: bin/etcd
>     plugs:
>         - network
>     daemon: simple
>     restart-condition: on-abnormal
> This was -almost magical-. I have need of customizing this output unit
> file based on conditions coming from Juju, such as TLS certificate paths
> will need to be passed as ENV, as well as peer connection strings.
> I can template this in Juju and overwrite the systemd unit file, but I
> feel like this will be a continual issue as the snap upgrades, I can only
> presume the systemd unit file is upgraded along the way. Please correct me
> if my assumption is incorrect here. Is there a way I can declare ENV or
> template the systemd file with the snap?

You don't have much control over the generated systemd service file. Its an
open issue. So while you could have your snap accept configuration options,
the snap can't rewrite its own systemd service file (or it could escape its
containment). What you would need to do is write a wrapper for bin/etcd
that sets the environment variables (pulled from snap configuration, or
from a .ini file or similar stored in $SNAP_DATA or $SNAP_COMMON) before
os.exec'ing the real bin/etcd

Since you are driving this from a charm though, you don't need it. systemd
supports '.d' style directories, allowing you to extend a .service file
owned by some other process. This is how the snap layer adds support for
downloading snaps via proxies, so see for an

Stuart Bishop <stuart.bishop at>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Snapcraft mailing list