Merge lp:~ovais-tariq/twindb-agent/bug-1409358 into lp:twindb-agent

Proposed by Ovais Tariq
Status: Merged
Approved by: Aleksandr Kuzminsky
Approved revision: 20
Merged at revision: 20
Proposed branch: lp:~ovais-tariq/twindb-agent/bug-1409358
Merge into: lp:twindb-agent
Diff against target: 84 lines (+21/-22)
1 file modified
twindb.py (+21/-22)
To merge this branch: bzr merge lp:~ovais-tariq/twindb-agent/bug-1409358
Reviewer Review Type Date Requested Status
Aleksandr Kuzminsky Approve
Review via email: mp+255921@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aleksandr Kuzminsky (akuzminsky) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'twindb.py'
--- twindb.py 2015-04-10 17:38:22 +0000
+++ twindb.py 2015-04-12 22:47:52 +0000
@@ -1964,21 +1964,14 @@
1964 return False1964 return False
1965 else:1965 else:
1966 # It's some other process, not a twindb agent1966 # It's some other process, not a twindb agent
1967 return True1967 remove_pid()
1968 except IOError as err:1968 except IOError as err:
1969 logger.error("Can't read from file /proc/%d/cmdline:%s " % (pid, err))1969 remove_pid()
1970 return False
1971 else:1970 else:
1972 try:1971 remove_pid()
1973 os.remove(pid_file)1972
1974 # It's a stale pid file1973 # pid file doesn't exist
1975 return True1974 return True
1976 except IOError as err:
1977 logger.error("Can't remove file %s: %s" % (pid_file, err))
1978 return False
1979 else:
1980 # pid file doesn't exist
1981 return True
19821975
19831976
1984def read_pid():1977def read_pid():
@@ -2051,12 +2044,14 @@
2051 logger.info("Pid file %s does not exist. Probably twindb agent isn't running" % pid_file)2044 logger.info("Pid file %s does not exist. Probably twindb agent isn't running" % pid_file)
2052 sys.exit(0)2045 sys.exit(0)
2053 pid = None2046 pid = None
2047
2054 try:2048 try:
2055 f = open(pid_file, 'r')2049 pid = read_pid()
2056 pid = int(f.readline())2050
2057 os.kill(pid, signal.SIGTERM)2051 if pid_exists(pid):
2058 wait_pid(pid, 300)2052 os.kill(pid, signal.SIGTERM)
2059 f.close()2053 wait_pid(pid, 300)
2054
2060 remove_pid()2055 remove_pid()
2061 except OSError as err:2056 except OSError as err:
2062 logger.error("Couldn't kill process %d" % pid)2057 logger.error("Couldn't kill process %d" % pid)
@@ -2064,6 +2059,7 @@
2064 except IOError as err:2059 except IOError as err:
2065 logger.error("Couldn't read from %s" % pid_file)2060 logger.error("Couldn't read from %s" % pid_file)
2066 exit_on_error(err)2061 exit_on_error(err)
2062
2067 logger.info("TwinDB agent successfully shut down")2063 logger.info("TwinDB agent successfully shut down")
2068 sys.exit(0)2064 sys.exit(0)
20692065
@@ -2076,10 +2072,6 @@
2076 global job_id2072 global job_id
2077 logger.info("Starting TwinDB agent")2073 logger.info("Starting TwinDB agent")
20782074
2079 if check_pid():
2080 write_pid()
2081 else:
2082 exit_on_error("Another instance of TwinDB agent is running. Exiting")
2083 try:2075 try:
2084 while True:2076 while True:
2085 read_config()2077 read_config()
@@ -2263,6 +2255,13 @@
2263 check_period = 12255 check_period = 1
22642256
2265 if action == "start":2257 if action == "start":
2258 # Create the PID if it does not already exist
2259 # If the PID already exists then we bail out
2260 if check_pid():
2261 write_pid()
2262 else:
2263 exit_on_error("Another instance of TwinDB agent is running. Exiting")
2264
2266 while True:2265 while True:
2267 # It'll keep checking until the agent is registered2266 # It'll keep checking until the agent is registered
2268 # Then it starts2267 # Then it starts

Subscribers

People subscribed via source and target branches