From 83052f9e24f51d0efc172c8fceea3e18fd0c1548 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Thu, 23 Jul 2009 17:23:06 +0100
Subject: [PATCH] Remove <DAEMON>_PID constants

The <DAEMON>_PID constants were created to reference a daemon pid file,
but actually contain a daemon's name, because the various functions that
work with pidfiles abstract the filename from the daemon name
themselves. Removing the constants and using the actual daemon name
constants in their place.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 daemons/ganeti-masterd | 4 ++--
 daemons/ganeti-noded   | 4 ++--
 daemons/ganeti-rapi    | 4 ++--
 daemons/ganeti-watcher | 9 ++++-----
 lib/backend.py         | 4 ++--
 lib/constants.py       | 5 -----
 6 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/daemons/ganeti-masterd b/daemons/ganeti-masterd
index dd59d8366..0775d05c0 100755
--- a/daemons/ganeti-masterd
+++ b/daemons/ganeti-masterd
@@ -514,7 +514,7 @@ def main():
   if options.fork:
     utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name])
 
-  utils.WritePidFile(constants.MASTERD_PID)
+  utils.WritePidFile(daemon_name)
   try:
     utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name],
                        debug=options.debug,
@@ -539,7 +539,7 @@ def main():
     finally:
       rpc.Shutdown()
   finally:
-    utils.RemovePidFile(constants.MASTERD_PID)
+    utils.RemovePidFile(daemon_name)
     utils.RemoveFile(constants.MASTER_SOCKET)
 
 
diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index edbc35c15..90b72f0a2 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -785,7 +785,7 @@ def main():
   if options.fork:
     utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name])
 
-  utils.WritePidFile(constants.NODED_PID)
+  utils.WritePidFile(daemon_name)
   try:
     utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name],
                        debug=options.debug,
@@ -808,7 +808,7 @@ def main():
     finally:
       server.Stop()
   finally:
-    utils.RemovePidFile(constants.NODED_PID)
+    utils.RemovePidFile(daemon_name)
 
 
 if __name__ == '__main__':
diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi
index 16ddb9ddb..4564ef301 100755
--- a/daemons/ganeti-rapi
+++ b/daemons/ganeti-rapi
@@ -250,7 +250,7 @@ def main():
   utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], debug=options.debug,
                      stderr_logging=not options.fork)
 
-  utils.WritePidFile(constants.RAPI_PID)
+  utils.WritePidFile(daemon_name)
   try:
     mainloop = daemon.Mainloop()
     server = RemoteApiHttpServer(mainloop, options.bind_address, port,
@@ -263,7 +263,7 @@ def main():
     finally:
       server.Stop()
   finally:
-    utils.RemovePidFile(constants.RAPI_PID)
+    utils.RemovePidFile(daemon_name)
 
 
 if __name__ == '__main__':
diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher
index 2749de63f..1a3ed1c00 100755
--- a/daemons/ganeti-watcher
+++ b/daemons/ganeti-watcher
@@ -478,9 +478,8 @@ def main():
 
   update_file = False
   try:
-    # on master or not, try to start the node dameon (use _PID but is
-    # the same as daemon name)
-    EnsureDaemon(constants.NODED_PID)
+    # on master or not, try to start the node dameon
+    EnsureDaemon(constants.NODED)
 
     notepad = WatcherState()
     try:
@@ -500,8 +499,8 @@ def main():
         # else retry the connection
         client = cli.GetClient()
 
-      # we are on master now (use _PID but is the same as daemon name)
-      EnsureDaemon(constants.RAPI_PID)
+      # we are on master now
+      EnsureDaemon(constants.RAPI)
 
       try:
         watcher = Watcher(options, notepad)
diff --git a/lib/backend.py b/lib/backend.py
index 15f6ed442..966f601a7 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -298,7 +298,7 @@ def StopMaster(stop_daemons):
 
   if stop_daemons:
     # stop/kill the rapi and the master daemon
-    for daemon in constants.RAPI_PID, constants.MASTERD_PID:
+    for daemon in constants.RAPI, constants.MASTERD:
       utils.KillProcess(utils.ReadPidFile(utils.DaemonPidFileName(daemon)))
 
 
@@ -2280,7 +2280,7 @@ def DemoteFromMC():
   master, myself = ssconf.GetMasterAndMyself()
   if master == myself:
     _Fail("ssconf status shows I'm the master node, will not demote")
-  pid_file = utils.DaemonPidFileName(constants.MASTERD_PID)
+  pid_file = utils.DaemonPidFileName(constants.MASTERD)
   if utils.IsProcessAlive(utils.ReadPidFile(pid_file)):
     _Fail("The master daemon is running, will not demote")
   try:
diff --git a/lib/constants.py b/lib/constants.py
index 90aa0e955..028265c12 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -109,11 +109,6 @@ SYSCONFDIR = _autoconf.SYSCONFDIR
 
 MASTER_SOCKET = SOCKET_DIR + "/ganeti-master"
 
-# PID files
-MASTERD_PID = "ganeti-masterd"
-NODED_PID = "ganeti-noded"
-RAPI_PID = "ganeti-rapi"
-
 NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
 
 NODED = "ganeti-noded"
-- 
GitLab