Using both SNAP_COMMON and SNAP_USER_COMMON

Hello there,

I’d appreciate comments on a change I’ve made to a snap I look after:

Will Cooke very kindly made some big improvements to the snap for me to add in user writable configuration to be stored in $SNAP_USER_COMMON, with a default config file being used if no user specific config exists - handled through launcher.sh. This works just fine when run by a user with “snap run mosquitto”. The application in question is primarily intended as a daemon, and so will be run by systemd. In that case, the config location was /root/snap/… which seems wrong.

I’ve modified the launcher script so that if the running user is root, then $SNAP_COMMON is used as the config location, else $SNAP_USER_COMMON is used. This allows both system use and per user use with different configuration. It works in my testing and makes sense to me, but I wanted to get some other opinions on whether this was a good/insane way of approaching the problem.

Thanks,

Roger

That snap doesn’t have any user-facing commands, just a daemon. As such I’d expect it to only look at SNAP_COMMON — a user calling the daemon via snap run would, in my mind, be doing something rather advanced and would not typically expect the daemon to suddenly lift its configuration from a different place.

If a user calling the binary is something frequent, I’d suggest exposing it as a separate app, possibly with a separate wrapper (but it doesn’t have to be — the wrapper can check what it’s called as to decide whether to use one directory or the other.

On the other hand, there’s nothing intrinsically wrong with what you’re doing, so if that’s what your users expect go for it!

I had similar reservations about the configuration location changing in an unexpected fashion. What I don’t want to do is to force a single configuration for the entire system. It’s perfectly reasonable to expect someone to want to run multiple versions of the application with different configuration files and what I’ve done is one way to achieve that. How frequent it is - I don’t know.

I’ll have a think about exposing it as a separate app, that’s an interesting idea thanks.