How to customize systemd service created by snapd?

If you’re just hitting the soft limit rather than hard, it might be better for your app to raise its own limit. You could try something similar to what dbus-daemon does:

https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/dbus/dbus-sysdeps-util-unix.c#L425

If you are running into problems with a hard limit or don’t control the snap’s source, you might be best off adding a drop-in file to augment the service file snapd wrote out. You’re correct that editing the service file produced by snapd is likely to be undone next time the snap upgrades.

If the service is called snap.snapname.servicename.service, create a directory /etc/systemd/system/snap.snapname.servicename.service.d, and create a file in that directory named set-file-limit.conf` with content like:

[Service]
LimitNOFILE=...

This allows you to override the limit in a way that will survive upgrades, and won’t leave a zombie unit behind if you uninstall the snap.

1 Like