apache/scripts/delete_php.py

50 lines
1.2 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)
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 php apache configuration of virtualhost..')
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)
print('Deleted the php apache configuration of virtualhost..')
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 virtualhost successfully..')