Snap directory "translation" rules?

Hello

I am having a bit of trouble getting my head around the way snap “abstracts” or interacts with the system it gets installed on.

I will use here Grafana, to demonstrate what I am talking about. The basic problem is that none of the typical Grafana directories or ways of starting / stopping / restarting the service apply in Snap.

I am on Ubuntu 20.

The typical location for Grafana’s configuration is /etc/grafana. There is a defaults.ini file there. Within snap, it is placed in /snap/grafana/36/conf. (Found it with find)

The typical way of interacting with Grafana’s server is via something like sudo systemctl ... etc. Obviously, this is made possible by the installation process (typically involving apt). Within snap, the server itself is placed in /snap/grafana/36/bin and…kind of limps along, because any attempts to run it directly end with “read only file system” (to an extent, this is understandable). In Ubuntu, grafana does not even come up as a package (so that it can be installed in the usual way).

And so, the question here is: Is there a rule of thumb by which a specific piece of software is treated once it transitions to snap? Is there a way by which to perform a translation between the typical directories and the directories within snap? Or, more generally, how we are supposed to treat it when it operates “as-is” and when it operates “via snap”? Finally, what is “36”?

All the best

The basic problem is that none of the typical Grafana directories or ways of starting / stopping / restarting the service apply in Snap.

Snap is a compressed file that is mounted in file system under /snap/<name>/<revision> directory. These files are read only. There are 2 other directories snap uses for writable content under /var/snap/<name>/<revision> for services and /home/<user>/snap/<name>/<revision> for apps. All this is by design so snaps can be isolated (only see its own files) from the rest of the system for security reasons.

Service management is simple and in background uses systemctl. Usually you don’t have to do anything because service is started as soon as snap is intalled.

snap [start|stop|restart|logs] grafana
systemctl [start|stop|restart] snap-grafana-36.service

The typical location for Grafana’s configuration is /etc/grafana.

Because files in /snap/<name>/<revision> are read only configuration files need to be somewhere else. For example this grafana uses config file located at /var/snap/grafana/36/conf/grafana.ini.

Finally, what is “36”?

Revision number incremented by 1 each time new version of snap is released for a platform.

Hopefully this clears few things for you.

one thing to take into accuont here when using these paths is that there is always a symlink pointing to the current revision so that:

/var/snap/grafana/36/

becomes:

/var/snap/grafana/current/

which is the “user friendly” variant of the writable disk space a snap has available

1 Like

@ogra, @predr Thank you very much for your replies, this has been very helpful overall for me, not only for Grafana.

1 Like