How do i edit config files

Hey,

I need to edit some configuration files after I have installed my XWiki snap. (Link to snapcraft.yaml) I also cannot make the application read the config files from some other location.As suggested by this following post. It was recently discovered by me that you could edit files that were imported locally eg:

scripts:
   source: ./scripts/
   source-type: local
   plugin: dump
   organize:
      setenv.sh: bin/setenv.sh    
      hibernate.cfg.xml: webapps/xwiki/WEB-INF/hibernate.cfg.xml

I was able to edit hibernate.cfg.xml inside var/snap/xwiki/webapps/xwiki/WEB-INF/hibernate.cfg.xml.(The changes were executed) While changes to the other config files that were not imported locally were not executing.

is it possible to edit the config files? thanks :slight_smile:

Hello there. This is most likely due to how you have the confinement of xWiki set. If you are operating in strict confinement, your application will not be able to edit files outside the confinement of the package. You can usually sus out if the confinement is an issue by grabbing the output of journalctl -ex and looking for AppArmor denied messages.

Generally, I think you have two options for to get your config files working:

  1. The first is to use layouts. For example, I use these when I have a config file stored under a $SNAP directory, but the program prefers to look in /etc/<program>.d.
  2. The second is to use the system-files interface, but you need to get approval from the store admins for auto-connecting it. This interface will allow you to reach outside of the snap and read configuration files.

I would suggest you try the first option, using layouts, first given that you need to get explicit approval for the second one. You more than likely just need to bind map the config files xWiki needs to where xWiki “thinks” they will be.

1 Like

well, if you want to be able to also edit your config files, you typically use an install hook to copy them from $SNAP to $SNAP_DATA or $SNAP_COMMON at package install time and then use a layout to map them to the place where your app expects them (i.e. /etc/myapp/config.conf) … that way you can actually edit the files (or configure them from a configure hook via snap set/get commands)

I don’t know if it’s a bug or a feature. But somehow I was able to edit in /var/snap/xwiki/someconfigfile.xml update with the snap.

eg: if I wanted to make XWiki web.xml edit work in the snap. I would remove it from the part where it was pulled from and replace it in another part where it was imported locally

parts:
  xwiki:
    source: xyz.com
    source-type: zip
    plugin: dump
    override-build: |
       rm -r xwiki/WEB-INF/web.xml
  scripts:
    source: ./scripts/
    source-type: local
    plugin: dump
    organize:
      web.xml: webapps/xwiki/WEB-INF/web.xml
    after: [xwiki]

Now the changes done in var/snap/xwiki/web.xml are taken into account after restarting the service . Using a hook and layout would be ideal as suggested by @nuccitheboss and @ogra .

Anyways just curious about why this method works. thanks :slight_smile: