From 91077a5b37a3a3eec3c05e1d67b6a68efa75063a Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 24 Jun 2010 13:20:27 +0000 Subject: [PATCH] bugfix for initscript creation --- sliver_vs.py | 6 +++++- tools.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sliver_vs.py b/sliver_vs.py index 554a1b3..ea0d21d 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -159,7 +159,11 @@ class Sliver_VS(accounts.Account, vserver.VServer): def refresh_slice_vinit(self): body=self.initscript sliver_initscript="/vservers/%s/etc/rc.d/init.d/vinit.slice"%self.name - tools.replace_file_with_string(sliver_initscript,body,remove_if_empty=True,chmod=0755) + if tools.replace_file_with_string(sliver_initscript,body,remove_if_empty=True,chmod=0755): + if body: + logger.log("vsliver_vs: %s: Installed new initscript in %s"%(self.name,sliver_initscript)) + else: + logger.log("vsliver_vs: %s: Removed obsolete initscript %s"%(self.name,sliver_initscript)) def start(self, delay=0): if self.rspec['enabled'] <= 0: diff --git a/tools.py b/tools.py index e37c0d5..b6a189a 100644 --- a/tools.py +++ b/tools.py @@ -133,7 +133,8 @@ def replace_file_with_string (target, new_contents, chmod=None, remove_if_empty= if current==new_contents: # if turns out to be an empty string, and remove_if_empty is set, # then make sure to trash the file if it exists - if remove_if_empty and os.path.isfile(target): + if remove_if_empty and not new_contents and os.path.isfile(target): + logger.verbose("tools.replace_file_with_string: removing file %s"%target) try: os.unlink(target) finally: return True return False -- 2.43.0