I have a virtual hosting server, where users can create a subdomain and then the server reload apache every 10 min. with a cronjob. But i would like to get apache to reload everytime a user is created, so they don't have to wait too long for the subdomain to activate. Have read much about apache2::reload, but can't see how it works, so i would be great if someone know a trick how to create subdomains and activate them on the fly. Here is a site i found, think is does it, or something like that. http://craigmanley.com/weblogs/mods/2006/03/20/installed-mod_perl2-package-for-apache20/
In ISPConfig we use the following solution: whenever a user creates a new web site, a file with a defined name is created (can be empty). I the background there's a script running with root privileges that checks every 10 seconds if this file is existing, and if it is, the configuration is rewritten and Apache restarted.
Okay, that great. But now my problem is that im no shark to perl, and my current script is perl and on a cronjob. Could you guide me to making to run in the background and what to add ? Also i could post my current perl script so you can see what i have and what to change in it?
Okay, i will try to post it, and hope that someone knows that to change and not to change. Script starts: #!/usr/bin/perl -w # print ("Content-type: text/html\n\n"); use Mysql; use DBI; use warnings; $start = 0; $dbh=DBI->connect('dbi:mysql:x:x','x','x') || die "Error opening database: $DBI::errstr\n"; $sth=$dbh->prepare("SELECT * from users_dom WHERE new='1';") || die "Prepare failed: $DBI::errstr\n"; $sth->execute() || die "Couldn't execute query: $DBI::errstr\n"; print "Writing File\n<br>"; $dbh=DBI->connect('dbi:mysql:x:x','x','x') || die "Error opening database: $DBI::errstr\n"; $sth=$dbh->prepare("SELECT * from users_dom WHERE new='1';") || die "Prepare failed: $DBI::errstr\n"; $sth->execute() || die "Couldn't execute query: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { open(OUTFILE, " >/var/www/apache/xdomain/$row[2].conf"); print OUTFILE "# -------------- Wiese Vhost Script --------------\n\n"; print OUTFILE "<VirtualHost *>\n"; print OUTFILE "DocumentRoot \"$row[6]/\"\n"; print OUTFILE "ServerName $row[1].$row[2]\n"; print OUTFILE "ServerAlias $row[2] $row[1].$row[2] www.$row[1].$row[2]\n"; print OUTFILE "ErrorLog /var/www/logs/xdomains/$row[3].error.log\n"; print OUTFILE "CustomLog /var/www/logs/xdomains/$row[3].access.log combined\n"; print OUTFILE "php_admin_flag engine ON\n"; print OUTFILE "php_admin_flag safe_mode Off\n"; print OUTFILE "<Directory />\n"; print OUTFILE "AllowOverride all\n"; print OUTFILE "Options SymLinksIfOwnerMatch\n"; print OUTFILE "</Directory>\n"; print OUTFILE "</VirtualHost>\n"; print OUTFILE "\n"; close(OUTFILE); $start++; } sleep 1; print "Writing File - Done.\n<br>"; $sth3=$dbh->prepare("UPDATE users_dom SET new='0' WHERE new='1';") || die "Prepare failed: $DBI::errstr\n"; $sth3->execute() || die "Couldn't execute query: $DBI::errstr\n"; $dbh=DBI->connect('dbi:mysql:x:x','x','x') || die "Error opening database: $DBI::errstr\n"; $sth=$dbh->prepare("SELECT * from users_dom WHERE del='1';") || die "Prepare failed: $DBI::errstr\n"; $sth->execute() || die "Couldn't execute query: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { open (FH, "rm /var/www/apache/xdomain/$row[2].conf|"); while(<FH>){ print; } $sth3=$dbh->prepare("DELETE FROM users_dom WHERE id='$row[0]' Limit 1;") || die "Prepare failed: $DBI::errstr\n"; $sth3->execute() || die "Couldn't execute query: $DBI::errstr\n"; ++$start; } if($start > 0){ open (FH, "sudo /etc/init.d/apache2 reload|"); while(<FH>){ print; } }
I think i will try and make at background script in PHP and see if it works, it's much easier that perl and have more experience in Php with shell.. Well Falko, thank you again for the help.