vagga icon indicating copy to clipboard operation
vagga copied to clipboard

Writeable filesystem option

Open kismet010 opened this issue 11 years ago • 4 comments

There's some use cases where a program needs to write to, i.e., /etc In my case, after installing apache and copying a virtualhost I need to restart the service, but it fails trying to write to /var/logs. How can we achieve this?

BTW, thanks a lot for making this :)

kismet010 avatar Sep 03 '15 21:09 kismet010

There are currently three options:

  1. Tmpfs mount, that's what I'm using for logs most of the time, because it cleans up on restart:

    containers:
      apache:
        setup:
         ...
        - !EnsureDir /var/logs
        volumes:
            /var/logs: !Tmpfs { size: 1Mi } 
    
  2. Bind directory from project dir (you need to create tmp/logs directory under you workdir manually):

    volumes:
        /var/logs: !BindRW /work/tmp/logs 
    
  3. The write-mode: transient-hard-link-copy in command definition. It's mostly used for building packages. It's probably not what you want, just list here for completeness.

http://vagga.readthedocs.org/en/latest/volumes.html

tailhook avatar Sep 03 '15 21:09 tailhook

I've tried all three options: 1 & 2. For empty dirs like /var/logs is ok, but not for /etc or /var. There are a lot of programs which needs to rewrite its config in /etc. Or in my case, 'service apache2 restart' needs to write to /var/run. 3. It needs to be done while building the container, not as a separate command.

kismet010 avatar Sep 03 '15 22:09 kismet010

  1. It needs to be done while building the container, not as a separate command.

I'm not sure what you mean? It's primary usage is to build package. So I use one ubuntu container for building application and to run it and to build docs, etc. The commands should be fast. And transient-hard-link-copy is slow. But when I want to do a release, I use the same container with transient-hard-link-copy option and checkinstall to build package (a second startup time is not too bad in this case)

Also see the warning in the documentation for this option.

1 & 2. For empty dirs like /var/logs is ok, but not for /etc or /var. There are a lot of programs which needs to rewrite its config in /etc. Or in my case, 'service apache2 restart' needs to write to /var/run.

Well, I don't know why you need to write to /etc, it's usually bad idea. The /var/run folder is usually tmpfs on real systems anyway, so you just need to mount tmpfs there (or it usually a symlink to /run so mount tmpfs to /run)

So anyway there are two ways to get pre-filled writable folder:

  1. Create a separate command to pre-fill folder for !BindRW, i.e. vagga init command which run "mysql_install_db" and vagga run which runs mysql. This means "init" command should be run only once
  2. Use a hack with a command as part of build process !Sh "rm -rf /work/tmp/mysql; mkdir -p /work/tmp/mysql; cp -R /var/lib/mysql /work/tmp/mysql". It works, but should be used as last resort

Note that (2) will overwrite the data whatever image is rebuilt (and it happen without any confirmation, say when you do "git pull" and someone else changed vagga.yaml), but you can put more complex logic in the script if you want. And (1) requires sometimes run "mysql_upgrade" manually to upgrade local database when version changed.

For my cases vagga init is usually sufficient.

tailhook avatar Sep 04 '15 08:09 tailhook

Was this helpful? Should issue be closed now?

tailhook avatar Sep 07 '15 22:09 tailhook