Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: parent directory for Apache #11

Closed
gerapeldoorn opened this issue Jul 11, 2011 · 6 comments
Closed

Request: parent directory for Apache #11

gerapeldoorn opened this issue Jul 11, 2011 · 6 comments

Comments

@gerapeldoorn
Copy link

Hi,

I've got several domains with more than one site on it.

On my disk, I keep them ordered like this:

/var/www/domain.com/site1
/var/www/domain.com/site2
/var/www/domain.com/site3

When I make virtualhosts with the virtualhosts manifest, it doesn't create the documentroot directory because the parent doesn't exist.

I've added this to virtualhost.rb to try and fix it:

---------------%<---------------
# creating/managing docroot parent directory
$documentroot_1up = $documentroot_real.chomp(separator='/').rpartition("/")
file { "$documentroot_1up":
owner => "${apache::params::configfile_owner}",
group => "${apache::params::configfile_group}",
mode => '775',
ensure => directory,
}
---------------%<---------------

... but I cannot mix ruby code in.

I've also found this page:
http://www.puppetlabs.com/blog/ruby-dsl/

It looks promising, but I have RedHat servers that use Puppet 0.25.5 from EPEL. I even tried making it work on Ubuntu (which does have Puppet 2.6), but I haven't got a clue where the different parts fit in.

If the apache-module could also check if the parent-directory exist then that would be great, pointers on how to get the parent directory from a string would also be very much appreciated...

Thanks,
Ger.

@alvagante
Copy link
Member

Actually the (automatic) management of parents directory with Puppet has always been a problem.
Generally because you have to define every single directory in the path. This can be fixed in a pure ruby class, but as you've said this won't work on pre 2.6.
In this case a generic virtualhost define that tries to recreate the parent dir, would fail if called twice having a duplicate recource for the parent dir, so I can't fix i upstream.
What I can say is that you should manage this a a custom way, that fits your needs and takes some assumptions.
For example have a custom apache::domain define that just creates the parent directory and is called only once (hand then have all the apache::virtualhosts defines that you need.
ThisiIs not particularly pratical but maybe can be useful to manage, besides the /var/www/domain.com dir, whatever other resource you might manage that is related to the single domain.

So you would end up with nodes (or roles) with something like:
apache::domain { "mydomain1.com": }
apache::virtualhost { "site1": documentroot => "/var/www/mydomain1.com/site1" ... }
apache::virtualhost { "site2": documentroot => "/var/www/mydomain1.com/site2" ... }

apache::domain { "mydomain2.com": }
apache::virtualhost { "site1": documentroot => "/var/www/mydomain2.com/site1" ... }
apache::virtualhost { "site2": documentroot => "/var/www/mydomain2.com/site2" ... }

Not particularly attractive, but it works.

@gerapeldoorn
Copy link
Author

Yes, that would work nicely, thanks!!

(I'm keeping you busy agian.. :) )

@saz
Copy link

saz commented Jul 11, 2011

Wouldn't a virtual resource fix the problem? The parent directory (in this case /var/www) is defined as a virtual resource and realized in apache::virtualhost.

@alvagante
Copy link
Member

Well, don't know, I suppose we have to try. The point is what happens when you realize the same virtual resource twice (as it would happen when you call the virtualhost deifne more than once). I actually never use virtual resources (only exported resources, when needed) so I don't know exactly how they behaves in these cases.

@saz
Copy link

saz commented Jul 11, 2011

Virtual resources are made for this. Think about users. Maybe you need a specific user in different modules. Puppet deals with it, as soon as it gets realized. If there is another Realize(File...) it won't get realized again.

More about here: http://docs.puppetlabs.com/guides/virtual_resources.html

@alvagante
Copy link
Member

Quite useful indeed. I suppose I'll start to use Virtual Resources more often now that I realize their usefulness in these cases (generally I used to place in specific classes resources that could be applied more than once), thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants