Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
''',
'''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/logs/current <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl] less +G playground/slow-startup/logs/current
[pgctl] ERROR: Some services failed to start: slow-startup
''',
1,
norm=norm.pgctl,
)
assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)
assert_command(
('pgctl', 'log'),
'''\
==> playground/slow-startup/logs/current <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
'',
0,
norm=norm.pgctl,
)
def it_can_shut_down_successfully_with_longer_timeout(self):
# if we configure it to wait a bit longer, it works fine
with open('playground/sweet/timeout-stop', 'w') as timeout:
timeout.write('3')
check_call(('pgctl', 'start'))
assert_svstat('playground/sweet', state='up')
check_call(('pgctl', 'restart'))
assert_svstat('playground/sweet', state='up')
check_call(('pgctl', 'stop'))
assert_svstat('playground/sweet', state=SvStat.UNSUPERVISED)
def it_works_with_nothing_running():
assert_svstat('playground/greeter', state=SvStat.UNSUPERVISED)
assert_works_interactively()
def it_stops_multiple_services(self, in_example_dir):
check_call(('pgctl', 'start', 'sleep', 'tail'))
assert_svstat('playground/sleep', state='up')
assert_svstat('playground/tail', state='up')
check_call(('pgctl', 'stop', 'sleep', 'tail'))
assert_svstat('playground/sleep', state=SvStat.UNSUPERVISED)
assert_svstat('playground/tail', state=SvStat.UNSUPERVISED)
def is_logger_running(self):
status = self._svstat_path(self.path.join('.log'))
return status.state != SvStat.UNSUPERVISED
def svstat_string(service_path):
"""Wrapper for daemontools svstat cmd"""
# svstat *always* exits with code zero...
if not svok(service_path):
return SvStat.UNSUPERVISED
cmd = ('s6-svstat', service_path)
process = Popen(cmd, stdout=PIPE, stderr=STDOUT)
status, _ = process.communicate()
status = status.decode('UTF-8')
#status is listed per line for each argument
return status
down (exitcode 0) 0 seconds, starting
'''
status = svstat_string.strip()
trace('RAW : %s', status)
if status.startswith(('up ', 'down ')):
state, buffer = parse(status, '', ' ')
elif status.startswith('unable to chdir:'):
return SvStat(SvStat.INVALID, None, None, None, None)
elif (
status.startswith('s6-svstat: fatal: unable to read status for ') and status.endswith((
': No such file or directory',
': Broken pipe',
))
):
# the service has never been started before; it's down.
return SvStat(SvStat.UNSUPERVISED, None, None, None, None)
else: # unknown errors
return SvStat(status, None, None, None, None)
pid, buffer = parse(buffer, '(pid ', ') ', int)
exitcode, buffer = parse(buffer, '(exitcode ', ') ', int)
_, buffer = parse(buffer, '(signal ', ') ')
seconds, buffer = parse(buffer, '', ' seconds', int)
buffer = buffer.lstrip(', ')
# we actually dont care about this value
_, buffer = parse(buffer, 'normally ', ', ')
process, buffer = parse(buffer, 'want ', ', ')
if process is not None:
process = process.strip('\x00') # s6 microbug