add update service command
All checks were successful
Publish Docker Image / docker (push) Successful in 1m12s

This commit is contained in:
Lee 2024-01-13 20:49:05 +00:00
parent 6ed38ad5f0
commit d9c0cb746a

View File

@ -14,7 +14,7 @@ if os.environ.get("CONTAINER_NAME"):
containerName = os.environ.get("CONTAINER_NAME")
# DO NOT TOUCH
commands = ["add", "remove", "list"]
commands = ["add", "remove", "list", "update"]
command = len(sys.argv) > 1 and sys.argv[1]
if command not in commands:
@ -24,6 +24,7 @@ if command not in commands:
print("Commands:")
print(" - add [name] [domain] [service host]")
print(" - remove [name]")
print(" - update [name] [new service host]")
print(" - list")
exit()
@ -127,15 +128,44 @@ def listDomains():
print("")
print("Total: %s" % len(domains))
def updateDomain(name, serviceHost):
# Check if name exists
if name not in routers:
print("Name \"%s\" does not exist" % name)
exit()
print("Updating domain \"%s\" -> \"%s\"" % (name, serviceHost))
# Update service
services[name] = {
"loadBalancer": {
"servers": [
{
"url": serviceHost
}
]
}
}
# Write to file
with open(configFile, "w") as config:
yaml.dump(configYml, config)
# Restart Traefik
restartTraefik()
match command:
case "add":
name = sys.argv[2]
domain = sys.argv[3]
serviceHost = sys.argv[4]
addDomain(name, domain, serviceHost)
case "remove":
name = sys.argv[2]
removeDomain(name)
case "update":
name = sys.argv[2]
serviceHost = sys.argv[3]
updateDomain(name, serviceHost)
case "list":
listDomains()