bugfix for initscript creation
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 24 Jun 2010 13:20:27 +0000 (13:20 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 24 Jun 2010 13:20:27 +0000 (13:20 +0000)
sliver_vs.py
tools.py

index 554a1b3..ea0d21d 100644 (file)
@@ -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:
index e37c0d5..b6a189a 100644 (file)
--- 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