views:

1098

answers:

7

I'm writing a shell script to do some web server configuration. I need to disable all currently active virtual hosts. a2dissite doesn't accept multiple arguments, so I can't do

a2dissite `ls /etc/apache2/sites-enabled`

Should I use find? Is it safe to manually delete the symlinks in /etc/apache2/sites-enabled?

A: 

you can edit the httpd.conf and delete the include line for the virtual hosts (at the bottom of the file)

Mote
well, this is being done by a shell script, and there's no assurance what the structure of the httpd.conf file is
Christian Oudard
he can use regex. include is preety much the same. he could pass the dir of the vhosts as an argument and based on that he can build the regex
Mote
neither is there an assurance that all vhosts are defined in config files linked from the sites-enabled dir.
hop
That'd interfere with the ability to quickly activate some of those vhosts in the future, though.
ceejayoz
A: 

You can just delete the symlinks, or move the entire directory away. There is no special database or other metadata besides those links.

hop
+2  A: 

Is your script Debian only? If so, you can safely delete all the symlinks in sites-enabled, that will work as long as all sites have been written correctly, in the sites-available directory.

For example:

 find /etc/apache2/sites-enabled/ -type l -exec rm -i "{}" \;

will protect you against someone who has actually written a file instead of a symlink in that directory.

(remove the -i from rm for an automatic script, of course)

Vinko Vrsalovic
+1  A: 

I never use 'a2dissite ' and always delete and create the links in /etc/apache2/sites-enabled manually so yes, I'd say it's pretty safe.

Darren Greaves
A: 

Apparently, you can just install the latest Ubuntu ;)

leppie
+1  A: 

After a little more research, I found out that a2dissite is just a shell script, and it basically just calls rm. So, like other responses, I agree that it is safe to do

rm /etc/apache2/sites-enabled/*
Christian Oudard
thanks for wasting our time
hop
A: 

Another option would be to remove the read permissions on the directory (or files on it) - if Apache can't open the files, it should ignore them, IIRC.

warren