stream浪鸡与蛋:与uid = apache用户共享文件夹

My Vagrant框是从一个基本的Linux(科学的Linux)构build的,在configuration(使用shell脚本)期间,Apache被安装。

我最近将stream浪文件(v2)更改为:

config.vm.synced_folder "public", "/var/www/sites.d/example.com", :owner => "apache", :group => "apache" 

如果该框已经设置好并重新启动,那么效果很好。

现在,经过一个vagrant destroy && vagrant up我得到的错误:

 mount -t vboxsf -o uid=`id -u apache`,gid=`id -g apache` /var/www/sites.d/example.com /var/www/sites.d/example.com id: apache: User does not exist 

这是清楚的 – 在最初的运行,apache尚未安装。

一个丑陋的解决方法当然是做synced_folder注释掉的基本configuration,注释它,然后重新启动。

有没有干净的伎俩来解决这个问题? 特别是以一种vagrant up的方式运行,即使箱子是新的。

Ryan Sechrest已经广泛地处理了这个问题 。

提出的解决scheme之一是:

将目录的权限设置为777,将文件设置为666

 config.vm.synced_folder "/Users/ryansechrest/Projects/Sites", "/var/www/domains", mount_options: ["dmode=777", "fmode=666"] 

如果你可以修正uid / gid值,你可以在mount命令中使用这些值 – 它们不必与现有的用户/组

我以后用puppet使用固定(匹配)的uid / gid值创build的用户来做这件事

 config.vm.synced_folder "foo", "/var/www/foo", id: "foo", :mount_options => ["uid=510,gid=510"] 

这就是我所做的:

 config.vm.synced_folder "./MyApp", "/opt/MyApp", owner: 10002, group: 1007, create: true config.vm.provision :shell do |shell| shell.inline = "groupadd -g 1007 myapp; useradd -c 'MyApp User' -d /opt/MyApp -g myapp -m -u 10002 myapp;" end 

而不是使用用户名和组(作为文本)使用uid和gid。 然后用这些ID创build组和用户。 这是因为这个错误实际上是:

 mount -t vboxsf -o uid=`id -u myapp`,gid=`getent group myapp | cut -d: -f3` opt_MyApp /opt/MyApp ... id: myapp: No such user 

id命令无法识别用户。 所以,切换到UID和GID的命令ID将不会被stream浪使用。

这种方法唯一的警告是用户主目录(/ opt / MyApp)已经存在,但我可以忍受,或者你可以改变useradd命令忽略主目录(如果已经存在)。

在此之前,我使用的解决方法是:

 vagrant up; vagrant provision; vagrant reload 

但是,既不干净也不好。

我如何解决这个问题,我首先configuration共享Vagrantfile没有用户或组的信息。 然后在configuration阶段,我卸载共享并重新安装正确的用户和组信息。 例如:

 exec { 'umount /share/location': command => 'umount /share/location'; } -> exec { 'mount /share/location': command => 'mount -t vboxsf -o uid=`id -u apache`,gid=`id -g apache` /share/name /share/location' 

您可以从virtualbox中检查共享名称,也可以通过运行带有debugging标志和非工作设置的configuration(它会打印出实际的挂载命令)。 我知道这是有点解决方法,可能无法在任何情况下工作,但它为我工作。

Interesting Posts