Skip to content

Fix start duplicate supervisord will remove exists pidfile #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ def __init__(self):
self.signal_receiver = SignalReceiver()
self.poller = poller.Poller(self)

self._pidfile_wrote = False

def version(self, dummy):
"""Print version to stdout and exit(0).
"""
Expand Down Expand Up @@ -1151,6 +1153,7 @@ def write_pidfile(self):
except (IOError, OSError):
self.logger.critical('could not write pidfile %s' % self.pidfile)
else:
self._pidfile_wrote = True
self.logger.info('supervisord started with pid %s' % pid)

def cleanup(self):
Expand All @@ -1159,7 +1162,9 @@ def cleanup(self):
if self.unlink_socketfiles:
socketname = config['file']
self._try_unlink(socketname)
self._try_unlink(self.pidfile)

if self._pidfile_wrote:
self._try_unlink(self.pidfile)

def _try_unlink(self, path):
try:
Expand Down
21 changes: 21 additions & 0 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,25 @@ def test_options_afinet_no_port(self):
self.assertEqual(exc.args[0],
"section [inet_http_server] has no port value")

def test_cleanup_ignore_pidfile(self):
fn = tempfile.mktemp()

with open(fn, 'w') as f:
f.write('1234')

try:
instance = self._makeOne()
instance.pidfile = fn

# cleanup without write pidfile
instance.cleanup()
self.assertTrue(os.path.exists(fn))
finally:
try:
os.unlink(fn)
except OSError:
pass

def test_cleanup_afunix_unlink(self):
fn = tempfile.mktemp()
with open(fn, 'w') as f:
Expand Down Expand Up @@ -1357,6 +1376,8 @@ def test_cleanup_removes_pidfile(self):
f.write('2')
instance = self._makeOne()
instance.pidfile = pidfile
instance.logger = DummyLogger()
instance.write_pidfile()
instance.cleanup()
self.assertFalse(os.path.exists(pidfile))
finally:
Expand Down