cPanel restarts apache after it adds a virtualhost, you will notice that because if you abort it and it doesn't add the group for example then apache will not be running.
When I mass added domains I just used cat to add it to the end of the file, for example this is what I done,
setup.sh
Code:
cat >>/etc/httpd/conf/domains.conf <<EOM
<VirtualHost *:80>
ServerAdmin [EMAIL="sysadmin@admingeekz.com"]sysadmin@admingeekz.com[/EMAIL]
ServerName server.admingeekz.com
ServerName $1
ServerAlias *.$1
DocumentRoot /home/httpd/domains/$1
</VirtualHost>
EOM
Then,
chmod 700 setup.sh
./setup.sh google.com
That will setup google.com based on the assumption that,
- You use /etc/httpd/conf/domains.conf (I simply included this in the main httpd.conf)
- You want your domain path to be /home/httpd/domains/domainhere
Since we just use these as parking domains this is a perfect setup. We generally do it to add the dns zone aswell which uses this
Code:
#!/bin/bash
if [ ! -d "/home/httpd/domains/$1" ]
then
mkdir /home/httpd/domains/$1
cat >>/etc/httpd/conf/domains.conf <<EOM
<VirtualHost *:80>
ServerAdmin [EMAIL="sysadmin@admingeekz.com"]sysadmin@admingeekz.com[/EMAIL]
ServerName server.admingeekz.com
ServerName $1
ServerAlias *.$1
DocumentRoot /home/httpd/domains/$1
</VirtualHost>
EOM
cat >>/etc/named.conf <<EOM
zone "$1" {
type master;
file "/var/named/$1.db";
};
EOM
cp -f /etc/template.named /etc/buffernamed
replace "cdomain.com" "$1" -- /etc/buffernamed
mv /etc/buffernamed /var/named/$1.db
chown named:named /var/named/$1.db
chown -R node:node /home/httpd/domains/$1
/etc/init.d/named reload
/etc/init.d/httpd reload
echo "Added $1 has been setup"
else
echo "$1 is already setup"
fi
Note this reloads apache and named (dns) and chowns it to the user and group node (we use this as a central ftp to all the domains rather than thousands of different logins). It does one fault check which is only to see if the directory exists (it creates it otherwise). If you are mass adding domains you should comment out the 2 reload lines simply because it will slow it down it will take around 10 minutes to add 2000 domains if you reload each time where as if you comment it out and then loop and then reload once all are added it will be around 20 seconds.
An example to setup lots of domains would be to create a file say
domains.txt and then for loop such as
Code:
for i in `cat domains`;do ./setup.sh $i;done
Hope this helps.
-Scott