Graceful exit.

This commit is contained in:
Philippe Pittoli 2024-12-15 18:38:41 +01:00
parent c476d89f69
commit 96eb605682
4 changed files with 39 additions and 0 deletions

View File

@ -181,6 +181,11 @@ class DNSManager::Client < IPC
parse_message [ Response::Success ], read
end
def admin_exit
request = Request::Exit.new
send_now request
end
#
# Utils
#

View File

@ -32,6 +32,7 @@ class Actions
@the_call["admin-migration-script"] = ->admin_migration_script
@the_call["admin-generate-all-zonefiles"] = ->admin_generate_all_zonefiles
@the_call["admin-provide-domain"] = ->admin_provide_domain
@the_call["admin-exit"] = ->admin_exit
# Domain operations.
@the_call["user-domain-add"] = ->user_domain_add
@ -155,6 +156,12 @@ class Actions
puts "error for provide_domain: #{e.message}"
end
def admin_exit
@dnsmanagerd.admin_exit
rescue e
puts "error for provide_domain: #{e.message}"
end
def user_domain_add
domains = Context.args.not_nil!
domains.each do |domain|

View File

@ -131,6 +131,14 @@ def parsing_cli(authd_config : Baguette::Configuration::Auth)
parser.banner = "COMMAND: admin migration-script user-db.txt"
unrecognized_args_to_context_args.call parser, 1, nil
end
# Kill the service.
parser.on("exit", "Kill the service.") do
Baguette::Log.info "kill the service."
Context.command = "admin-exit"
parser.banner = "COMMAND: exit"
unrecognized_args_to_context_args.call parser, nil, 0
end
end
# User section.

View File

@ -91,4 +91,23 @@ class DNSManager::Request
end
end
DNSManager.requests << GenerateZoneFile
IPC::JSON.message Exit, 248 do
def initialize
end
def to_s(io : IO)
super io
end
def handle(dnsmanagerd : DNSManager::Service, event : IPC::Event) : IPC::JSON
user = dnsmanagerd.get_logged_user event
return Response::ErrorUserNotLogged.new unless user
dnsmanagerd.storage.user_must_be_admin! user.uid
Baguette::Log.warning "exit requested, bye"
exit 0
end
end
DNSManager.requests << Exit
end