Skip to content
Snippets Groups Projects
Commit 5d2ac566 authored by Loraine Gueguen's avatar Loraine Gueguen
Browse files

Add docker tools

parent f8dfe448
No related branches found
No related tags found
1 merge request!18Release v2.1.0
Useful tools to run docker commands for all running stacks
=================
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import logging
import utilities
import time
def run_docker_service_scale(stack, service, state):
utilities.run_command(["docker", "service", "scale", stack + "_" + service + "=" + state])
def run_docker_stack_services(stack, service):
stdout = utilities.run_command_and_get_stdout(["docker", "stack", "services",
"--format", "'{{.Replicas}}'",
"--filter", "name=" + stack + "_" + service,
stack])
return stdout
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Start or stop the Galaxy container for all the stacks")
parser.add_argument("-s", "--state",
type=int,
choices=[0,1],
help="State to set the Galaxy container in")
parser.add_argument("-v", "--verbose",
help="Increase output verbosity",
action="store_true")
args = parser.parse_args()
state = args.state
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.debug("Debug mode")
else:
logging.basicConfig(level=logging.INFO)
stacks = utilities.run_docker_stack_ls()
# Stop the Galaxy services
for stack in stacks:
if stack not in ["traefik", "portainer"]:
run_docker_service_scale(
stack=stack,
service="galaxy",
state=state
)
time.sleep(60)
# Check that the Galaxy services are down
for stack in stacks:
if stack not in ["traefik", "portainer"]:
stdout = run_docker_stack_services(
stack=stack,
service="galaxy"
)
if stdout != "0/1":
logging.error("The Galaxy service is not stopped for %s" % stack)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import logging
import utilities
def run_docker_service_update(stack, service):
utilities.run_command(["docker", "service", "update", "--force", stack + "_" + service])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Update a service for all the stacks")
parser.add_argument("-s", "--service",
choices=["tripal", "galaxy", "jbrowse", "tripal-db", "elasticsearch", "proxy"],
help="Service to update")
parser.add_argument("-v", "--verbose",
help="Increase output verbosity",
action="store_true")
args = parser.parse_args()
service = args.service
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.debug("Debug mode")
else:
logging.basicConfig(level=logging.INFO)
stacks = utilities.run_docker_stack_ls()
# Stop the Galaxy services
for stack in stacks:
if stack not in ["traefik", "portainer"]:
run_docker_service_update(
stack=stack,
service=service
)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import logging
def run_command(command):
subprocess.run(command)
def run_command_and_get_stdout(command):
completed_process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
return completed_process.stdout
def run_docker_stack_ls():
stdout = run_command_and_get_stdout(["docker", "stack", "ls", "--format", "{{.Name}}"])
stacks = stdout.splitlines()
logging.info("{0} stacks running: {1}".format(len(stacks), ", ".join(stacks)))
return stacks
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment