Skip to content
Merged
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
84 changes: 3 additions & 81 deletions src/dlstbx/cli/shutdown.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,6 @@
#
# dlstbx.shutdown
# Stop a dlstbx service
#


import sys
from optparse import SUPPRESS_HELP, OptionParser

import workflows
import workflows.services
from workflows.transport.stomp_transport import StompTransport

# Example: dlstbx.shutdown computer.12345
# dlstbx.shutdown --all
import zocalo.cli.shutdown


def run():
parser = OptionParser()

parser.add_option("-?", action="help", help=SUPPRESS_HELP)
# parser.add_option("--all", dest="all",
# action="store_true", default=False,
# help="Stop all dlstbx services (use with caution)")

known_services = workflows.services.get_known_services()
parser.add_option(
"-s",
"--service",
dest="services",
metavar="SVC",
action="append",
default=[],
help="Stop all instances of a service. Use 'none' for instances without "
"loaded service. Known services: " + ", ".join(known_services),
)
parser.add_option(
"--test",
action="store_true",
dest="test",
help="Run in ActiveMQ testing namespace (zocdev, default)",
)
parser.add_option(
"--live",
action="store_true",
dest="test",
help="Run in ActiveMQ live namespace (zocalo)",
)

# change settings when in live mode
default_configuration = "/dls_sw/apps/zocalo/secrets/credentials-testing.cfg"
if "--live" in sys.argv:
default_configuration = "/dls_sw/apps/zocalo/secrets/credentials-live.cfg"

StompTransport.load_configuration_file(default_configuration)
StompTransport.add_command_line_options(parser)
(options, args) = parser.parse_args(sys.argv[1:])
stomp = StompTransport()

if not options.services and not len(args):
print("Need to specify one or more services to shut down.")
print("Either specify service groups with -s or specify specific instances")
print("as: hostname.pid")
sys.exit(1)

stomp.connect()

for host in args:
if not host.startswith("uk.ac.diamond."):
host = "uk.ac.diamond." + host

message = {"command": "shutdown", "host": host}

stomp.broadcast("command", message)
print("Shutting down", host)

for service in options.services:
if service.lower() == "none":
# Special case for placeholder instances
service = None
message = {"command": "shutdown", "service": service}

stomp.broadcast("command", message)
print("Stopping all instances of", service)
print("\ndlstbx.shutdown is deprecated. Use 'zocalo.shutdown' instead\n")
zocalo.cli.shutdown.run()