Skip to content

Instantly share code, notes, and snippets.

@herpiko
Forked from nunenuh/a2dissite
Last active Aug 29, 2015
Embed
What would you like to do?
#!/usr/bin/env python
import sys
import os
arg = sys.argv
arlen = len(arg)
available = '/etc/httpd/sites-available'
enabled = '/etc/httpd/sites-enabled'
if not os.path.exists(available) and not os.path.isdir(available):
if not os.path.exists(enabled) and not os.path.isdir(enabled):
print 'Initialize All Directory for virtual host'
os.makedirs(available, 0755)
print 'Initialize directory %s' % available
os.makedirs(enabled, 0755)
print 'Initialize directory %s' % enabled
print 'Please Add line "Include /etc/httpd/sites-enabled/*.conf" to /etc/httpd/conf/httpd.conf'
print 'Without these line above, virtual host cannot work as you expected!'
if not os.path.exists(available) and not os.path.isdir(available):
os.makedirs(available, 0755)
print 'Initialize directory %s' % available
if not os.path.exists(enabled) and not os.path.isdir(enabled):
os.makedirs(enabled, 0755)
print 'Initialize directory %s' % enabled
if arlen <= 1:
print "Use script: %s virtual_host.conf" % arg[0]
elif arlen == 2:
file_avail = os.path.join(available, arg[1])
file_enabled = os.path.join(enabled, arg[1])
if os.path.exists(file_enabled) and os.path.islink(file_enabled):
os.unlink(file_enabled)
print 'Site %s is now disabled' % arg[1]
print 'Please restart httpd server with command :\n service httpd restart'
else:
if os.path.exists(file_avail) and os.path.isfile(file_avail):
print 'Site %s has been already disabled' % arg[1]
else:
print 'Site %s that you want to disabled didnt exist in sites-available'
print 'Please use one of the virtual host below:'
list = os.listdir(available)
for i in range(len(list)):
print list[i]
elif arlen > 2:
print "Use script: %s virtual_host.conf" % arg[0]
#!/usr/bin/env python
import sys
import os
arg = sys.argv
arlen = len(arg)
available = '/etc/httpd/sites-available'
enabled = '/etc/httpd/sites-enabled'
if not os.path.exists(available) and not os.path.isdir(available):
if not os.path.exists(enabled) and not os.path.isdir(enabled):
print 'Initialize All Directory for virtual host'
os.makedirs(available, 0755)
print 'Initialize directory %s' % available
os.makedirs(enabled, 0755)
print 'Initialize directory %s' % enabled
print 'Please Add line "Include /etc/httpd/sites-enabled/*.conf" to /etc/httpd/conf/httpd.conf'
print 'Without these line above, virtual host cannot work as you expected!'
if not os.path.exists(available) and not os.path.isdir(available):
os.makedirs(available, 0755)
print 'Initialize directory %s' % available
if not os.path.exists(enabled) and not os.path.isdir(enabled):
os.makedirs(enabled, 0755)
print 'Initialize directory %s' % enabled
if arlen <= 1:
print "Use script: %s virtual_host.conf" % arg[0]
elif arlen == 2:
file_avail = os.path.join(available, arg[1])
file_enabled = os.path.join(enabled, arg[1])
if os.path.exists(file_avail) and os.path.isfile(file_avail):
if os.path.exists(file_enabled) and os.path.islink(file_enabled):
print 'Site %s has been already enabled' % arg[1]
else:
os.symlink(file_avail, file_enabled)
print 'Site %s is now enabled' % arg[1]
print 'Please restart httpd server with command :\n service httpd restart'
else:
print 'Site file that you want to activate is not exists'
print 'Please use one of the virtual host below:'
list = os.listdir(available)
for i in range(len(list)):
print list[i]
elif arlen > 2:
print "Use script: %s virtual_host.conf" % arg[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment