apache/scripts/webapps/delete_app_apache.py

76 lines
2.3 KiB
Python

#!/usr/bin/python3 -u
import argparse
import os
#from pastafariutils.unix import add_user, del_user
from pathlib import Path
from subprocess import call, DEVNULL
import json
import time
import shutil
import pwd
import distro
import subprocess
import re
import sys
parser=argparse.ArgumentParser(prog='delete_wordpress.py', description='A tool for delete wordpress')
parser.add_argument('--domain', help='Domain to delete', required=True)
parser.add_argument('--webapp', help='Webapp config to delete', required=True)
args=parser.parse_args()
apache_cmd='apache2'
apachectl='apache2ctl'
linux_distro=distro.id()
if linux_distro!='debian' and linux_distro!='ubuntu':
apache_cmd='httpd'
apachectl='apachectl'
print('Deleting the apache configuration of webapp..')
# /etc/httpd/vhosts.d/php/prueba.cuchulu.com-php.conf
"""
apache_php='/etc/{}/vhosts.d/php/{}-php.conf'.format(apache_cmd, args.domain)
if os.path.isfile(apache_php):
if subprocess.call("sudo rm %s" % (apache_php), shell=True) > 0:
print('Error: cannot delete php config %s' % apache_php)
sys.exit(1)
"""
# /etc/httpd/vhosts.d/extra/prueba.cuchulu.com-wordpress.conf
apache_webapp='/etc/{}/vhosts.d/extra/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
apache_sub0_webapp='/etc/{}/vhosts.d/extra/proxy/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
apache_sub1_webapp='/etc/{}/vhosts.d/extra/proxyphp/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
if os.path.isfile(apache_webapp):
if subprocess.call("sudo rm %s" % (apache_webapp), shell=True) > 0:
print('Error: cannot delete webapp config %s' % apache_webapp)
sys.exit(1)
if os.path.isfile(apache_sub0_webapp):
if subprocess.call("sudo rm %s" % (apache_sub0_webapp), shell=True) > 0:
print('Error: cannot delete webapp config %s' % apache_sub0_webapp)
sys.exit(1)
if os.path.isfile(apache_sub1_webapp):
if subprocess.call("sudo rm %s" % (apache_sub1_webapp), shell=True) > 0:
print('Error: cannot delete webapp config %s' % apache_sub1_webapp)
sys.exit(1)
if subprocess.call("sudo systemctl restart %s" % (apache_cmd), shell=True) > 0:
print('Error: cannot restart Apache server')
sys.exit(1)
print('Deleted the apache configuration of webapp successfully..')