Use symlinks instead of copying file
This commit is contained in:
@@ -1235,6 +1235,10 @@ def removeNginxConf(self, domain):
|
|||||||
|
|
||||||
|
|
||||||
def removeAcmeConf(self, domain):
|
def removeAcmeConf(self, domain):
|
||||||
|
sslconf = ("/var/www/{0}/conf/nginx/ssl.conf"
|
||||||
|
.format(domain))
|
||||||
|
sslforce = ("/etc/nginx/conf.d/force-ssl-{0}.conf"
|
||||||
|
.format(domain))
|
||||||
if os.path.isdir('/etc/letsencrypt/renewal/{0}_ecc'
|
if os.path.isdir('/etc/letsencrypt/renewal/{0}_ecc'
|
||||||
.format(domain)):
|
.format(domain)):
|
||||||
Log.info(self, "Removing Acme configuration")
|
Log.info(self, "Removing Acme configuration")
|
||||||
@@ -1250,18 +1254,23 @@ def removeAcmeConf(self, domain):
|
|||||||
Log.debug(self, "{0}".format(e))
|
Log.debug(self, "{0}".format(e))
|
||||||
Log.error(self, "Cert removal failed")
|
Log.error(self, "Cert removal failed")
|
||||||
|
|
||||||
WOFileUtils.rm(self, '/etc/letsencrypt/renewal/{0}_ecc'
|
WOFileUtils.rm(self, '{0}/{1}_ecc'
|
||||||
.format(domain))
|
.format(WOVariables.wo_ssl_archive, domain))
|
||||||
WOFileUtils.rm(self, '/etc/letsencrypt/live/{0}'
|
WOFileUtils.rm(self, '{0}/{1}'
|
||||||
.format(domain))
|
.format(WOVariables.wo_ssl_live, domain))
|
||||||
WOFileUtils.rm(self, '/var/www/{0}/conf/nginx/ssl.conf'
|
WOFileUtils.rm(self, '{0}'.format(sslconf))
|
||||||
.format(domain))
|
WOFileUtils.rm(self, '{0}.disabled'.format(sslconf))
|
||||||
WOFileUtils.rm(self, '/var/www/{0}/conf/nginx/ssl.conf.disabled'
|
WOFileUtils.rm(self, '{0}'.format(sslforce))
|
||||||
.format(domain))
|
WOFileUtils.rm(self, '{0}.disabled'
|
||||||
WOFileUtils.rm(self, '/etc/nginx/conf.d/force-ssl-{0}.conf'
|
.format(sslforce))
|
||||||
.format(domain))
|
|
||||||
WOFileUtils.rm(self, '/etc/nginx/conf.d/force-ssl-{0}.conf.disabled'
|
# find all broken symlinks
|
||||||
.format(domain))
|
symlinks = WOFileUtils.findBrokenSymlink(self, "/var/www")
|
||||||
|
for symlink in symlinks:
|
||||||
|
if os.path.islink('{0}'.format(sslconf)):
|
||||||
|
# remove broken symlinks
|
||||||
|
WOFileUtils.remove_symlink(self, symlink)
|
||||||
|
|
||||||
if WOFileUtils.grepcheck(self, '/var/www/22222/conf/nginx/ssl.conf',
|
if WOFileUtils.grepcheck(self, '/var/www/22222/conf/nginx/ssl.conf',
|
||||||
'{0}'.format(domain)):
|
'{0}'.format(domain)):
|
||||||
Log.info(self, "Setting back default certificate for WordOps backend")
|
Log.info(self, "Setting back default certificate for WordOps backend")
|
||||||
@@ -1496,18 +1505,14 @@ def copyWildcardCert(self, wo_domain_name, wo_root_domain):
|
|||||||
if os.path.isfile("/var/www/{0}/conf/nginx/ssl.conf"
|
if os.path.isfile("/var/www/{0}/conf/nginx/ssl.conf"
|
||||||
.format(wo_root_domain)):
|
.format(wo_root_domain)):
|
||||||
try:
|
try:
|
||||||
WOFileUtils.copyfile(self, "/var/www/{0}/conf/nginx/ssl.conf"
|
WOFileUtils.create_symlink(self, "/var/www/{0}/conf/nginx/ssl.conf"
|
||||||
.format(wo_root_domain),
|
.format(wo_root_domain),
|
||||||
"/var/www/{0}/conf/nginx/ssl.conf"
|
"/var/www/{0}/conf/nginx/ssl.conf"
|
||||||
.format(wo_domain_name))
|
.format(wo_domain_name))
|
||||||
cert_link = open('/var/lib/wo/linked.csv', encoding='utf-8',
|
|
||||||
mode='a')
|
|
||||||
cert_link.write('{0}|{1}\n'.format(wo_root_domain,
|
|
||||||
wo_domain_name))
|
|
||||||
cert_link.close()
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
Log.debug(self, str(e))
|
Log.debug(self, str(e))
|
||||||
Log.debug(self, "Error occured while copying ssl cert")
|
Log.debug(self, "Error occured while "
|
||||||
|
"creating symlink for ssl cert")
|
||||||
|
|
||||||
# letsencrypt cert renewal
|
# letsencrypt cert renewal
|
||||||
|
|
||||||
|
|||||||
@@ -279,3 +279,33 @@ class WOFileUtils():
|
|||||||
Log.debug(self, "{0}".format(e))
|
Log.debug(self, "{0}".format(e))
|
||||||
Log.error(self, "Unable to remove file : {0} "
|
Log.error(self, "Unable to remove file : {0} "
|
||||||
.format(path))
|
.format(path))
|
||||||
|
|
||||||
|
def findBrokenSymlink(self, sympath):
|
||||||
|
"""
|
||||||
|
Find symlinks
|
||||||
|
"""
|
||||||
|
links = []
|
||||||
|
broken = []
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(sympath):
|
||||||
|
if root.startswith('./.git'):
|
||||||
|
# Ignore the .git directory.
|
||||||
|
continue
|
||||||
|
for filename in files:
|
||||||
|
path = os.path.join(root, filename)
|
||||||
|
if os.path.islink(path):
|
||||||
|
target_path = os.readlink(path)
|
||||||
|
# Resolve relative symlinks
|
||||||
|
if not os.path.isabs(target_path):
|
||||||
|
target_path = os.path.join(os.path.dirname(path),
|
||||||
|
target_path)
|
||||||
|
if not os.path.exists(target_path):
|
||||||
|
links.append(path)
|
||||||
|
broken.append(path)
|
||||||
|
else:
|
||||||
|
links.append(path)
|
||||||
|
else:
|
||||||
|
# If it's not a symlink we're not interested.
|
||||||
|
continue
|
||||||
|
|
||||||
|
return broken
|
||||||
|
|||||||
Reference in New Issue
Block a user