Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using a cron job to reload my httpd service after a subdomain is created. I have the problem that when the reload happens the page that registers the user throws a server error.

I was wondering if I could go around this by having another cron task.

So my logic would be:

httpd reload after a .conf file is created then take the user back to the DocumentRoot of the main page.

So in usage it would be:

a user registers, then is automatically taken back to domain.com

share|improve this question
    
You seem to be conflating two processes (user registration - happening in a web page, and apache restarts - happening via cron). The latter cannot influence the former without a lot of deep hackery. You're probably better off figuring out why you're throwing server errors and fixing that problem instead... –  voretaq7 Sep 9 '11 at 15:00
    
well i know why i ge the server error. The register page cannot finish its execution because the httpd reloads. –  s2xi Sep 9 '11 at 21:56

3 Answers 3

up vote 0 down vote accepted

Do a graceful restart on the apache, that will allow childs to finish the current request before reloading the config.

share|improve this answer
    
So this means if a user registers and creates the .conf file via the registration script that invokes the cron job to reload apache; the register script can finishes doing everything it needs to before apache gets reloaded? –  s2xi Apr 11 '12 at 6:10
    
exactly, it will allow the child to 'finish the process its doing now and leaves a note "please restart when you´re done"' - the normal restart would be a "kill everything now" (as you mentioned in "The register page cannot finish its execution") –  Tabakhase Apr 11 '12 at 15:07

"load a php page..."

Does that mean you are trying to invoke this via HTTP?

That's a bad idea to begin with - it means that you've potentially exposed functionality which could be accessed by someone not intended to have access to it.

to reload my httpd service

So it's running with root privileges? That's a really bad idea.

From your description, you seem to be trying to provide a facility for users to create their own domains. It would be much more preferable to use a wildcard vhost definition, then use mod_rewrite to map the dynamically mapped path to a new directory.

But failing that the best way to do this would be to implement it as a setuid root script on the server (with authentication built-in as well as authentication on the web page) and call this from the web page.

....and if the process is started by a web request, then why use cron in the middle? Certainly you'll get privilege seperation if the cron job job is NOT accessing the php script via HTTP, but you're making things much harder than they need to be and introducing delays / load on the server you don't need.

share|improve this answer
    
I have a cron job using incrontab that reloads my httpd service when a user registers. I have 2 servers mounted to my website server that house the user so depending on what user they are their DocumentRoot won't be the same. That's the only thing that stopped me from using a wildcard vhost definitely. –  s2xi Sep 9 '11 at 12:49

This is the wrong way to solve this problem.

The right way involves using some kind of software "router". I don't actually mean an IP router, I mean an URL rewriting type router.

So your application listens to anything on *.domain.com, and then hands it off to the right user's application instead of that tedious apache reloading nonsense.

I did something similar in Nginx recently.

server_name *.domain.com
if ($host ~* "(.*)?\.?domain\.com"){
                set $a $1;
                rewrite ^/?$ /sites/$a/index.html last;
}

Basically, for any subdomain under domain.com, it gets mapped to $DOCROOT/sites/$subdomain/index.html

As a result, to add a new subdomain, all I need to do is create a directory under sites/"subdomain", and it's instantly accessible.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.