Skip to content

Commit

Permalink
improved handling
Browse files Browse the repository at this point in the history
- shutdown container on SIGTERM
- more status information
- improved SIGINT handling in script
- remove stopped containers
  • Loading branch information
Matthias Lohr committed Jun 9, 2017
1 parent 9548464 commit 2d341d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions f5fpc-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,31 @@ def main():

last_status = -255
while True:
status = container_exec(container_name, '/usr/local/bin/f5fpc -i')

if status == 5 and last_status != 5:
logging.info('Connection established')
status, stdout, stderr = container_exec(container_name, '/usr/local/bin/f5fpc -i')
logging.debug('f5fpc --info returns {code}'.format(code=status))
if status == 1 and last_status != 1:
logging.info('Session initialized.')
elif status == 2 and last_status != 2:
logging.info('Logging in...')
elif status == 5:
logging.info('Connection established. Welcome to {host} network!'.format(host=args.host))
break
elif status == 7:
logging.error('Login was denied.')
container.stop()
container.remove()
return 1
last_status = status

# TODO set routes

# wait for signal
def shutdown(signal, frame):
logging.info('Shutting down...')
# TODO remove routes
container.stop()
container.remove()
return 0

signal.signal(signal.SIGINT, shutdown)
signal.pause()
Expand All @@ -88,8 +101,10 @@ def container_exec(container, command):
command_string = '/usr/bin/docker exec -it {container} {command}'.format(container=container, command=command)
command_splitted = shlex.split(command_string)
logger.debug(command_splitted)
return_code = subprocess.call(command_splitted, stdout=None)
return return_code
process = subprocess.Popen(command_splitted, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
returncode = process.returncode
return returncode, stdout, stderr


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion files/idle.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

trap 'exit 1' SIGINT
trap 'exit' SIGINT SIGTERM

while true ; do
sleep 1
Expand Down

0 comments on commit 2d341d8

Please sign in to comment.