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
1=== modified file 'twindb.py'
2--- twindb.py 2015-04-10 17:38:22 +0000
3+++ twindb.py 2015-04-12 22:47:52 +0000
4@@ -1964,21 +1964,14 @@
5 return False
6 else:
7 # It's some other process, not a twindb agent
8- return True
9+ remove_pid()
10 except IOError as err:
11- logger.error("Can't read from file /proc/%d/cmdline:%s " % (pid, err))
12- return False
13+ remove_pid()
14 else:
15- try:
16- os.remove(pid_file)
17- # It's a stale pid file
18- return True
19- except IOError as err:
20- logger.error("Can't remove file %s: %s" % (pid_file, err))
21- return False
22- else:
23- # pid file doesn't exist
24- return True
25+ remove_pid()
26+
27+ # pid file doesn't exist
28+ return True
29
30
31 def read_pid():
32@@ -2051,12 +2044,14 @@
33 logger.info("Pid file %s does not exist. Probably twindb agent isn't running" % pid_file)
34 sys.exit(0)
35 pid = None
36+
37 try:
38- f = open(pid_file, 'r')
39- pid = int(f.readline())
40- os.kill(pid, signal.SIGTERM)
41- wait_pid(pid, 300)
42- f.close()
43+ pid = read_pid()
44+
45+ if pid_exists(pid):
46+ os.kill(pid, signal.SIGTERM)
47+ wait_pid(pid, 300)
48+
49 remove_pid()
50 except OSError as err:
51 logger.error("Couldn't kill process %d" % pid)
52@@ -2064,6 +2059,7 @@
53 except IOError as err:
54 logger.error("Couldn't read from %s" % pid_file)
55 exit_on_error(err)
56+
57 logger.info("TwinDB agent successfully shut down")
58 sys.exit(0)
59
60@@ -2076,10 +2072,6 @@
61 global job_id
62 logger.info("Starting TwinDB agent")
63
64- if check_pid():
65- write_pid()
66- else:
67- exit_on_error("Another instance of TwinDB agent is running. Exiting")
68 try:
69 while True:
70 read_config()
71@@ -2263,6 +2255,13 @@
72 check_period = 1
73
74 if action == "start":
75+ # Create the PID if it does not already exist
76+ # If the PID already exists then we bail out
77+ if check_pid():
78+ write_pid()
79+ else:
80+ exit_on_error("Another instance of TwinDB agent is running. Exiting")
81+
82 while True:
83 # It'll keep checking until the agent is registered
84 # Then it starts

Subscribers

People subscribed via source and target branches