Graceful exit.

This commit is contained in:
Philippe Pittoli 2024-12-15 18:29:56 +01:00
parent 8abe49672b
commit 2bfddd1d57
4 changed files with 41 additions and 0 deletions

View File

@ -99,6 +99,10 @@ module AuthD
], read ], read
end end
def exit
send_now Request::Exit.new
end
def validate_user(login : String, activation_key : String) def validate_user(login : String, activation_key : String)
send_now Request::ValidateUser.new login, activation_key send_now Request::ValidateUser.new login, activation_key
parse_message [ parse_message [

View File

@ -79,6 +79,15 @@ parser = OptionParser.new do |parser|
unrecognized_args_to_context_args.call parser, 2 unrecognized_args_to_context_args.call parser, 2
end end
parser.on "exit", "Kill the service." do
parser.banner = "Usage: exit"
Baguette::Log.info "Kill the service."
Context.command = "exit"
opt_authd_login.call parser
opt_help.call parser
unrecognized_args_to_context_args.call parser, 0
end
parser.on "migration-script", "Add a batch of users from old code base." do parser.on "migration-script", "Add a batch of users from old code base." do
parser.banner = "usage: migration-script user-db.txt" parser.banner = "usage: migration-script user-db.txt"
Baguette::Log.info "Add a batch of users." Baguette::Log.info "Add a batch of users."

View File

@ -66,6 +66,7 @@ class Actions
@the_call["user-migrate"] = ->user_migrate @the_call["user-migrate"] = ->user_migrate
@the_call["migration-script"] = ->migration_script @the_call["migration-script"] = ->migration_script
@the_call["user-mod"] = ->user_mod @the_call["user-mod"] = ->user_mod
@the_call["exit"] = ->kill_service
@the_call["permission-set"] = ->permission_set @the_call["permission-set"] = ->permission_set
@the_call["permission-check"] = ->permission_check @the_call["permission-check"] = ->permission_check
@ -192,6 +193,14 @@ class Actions
puts "error: #{e.message}" puts "error: #{e.message}"
end end
def kill_service
puts "Kill the service."
authd.exit
rescue e : AuthD::Exception
puts "error: #{e.message}"
end
def user_change_password def user_change_password
args = Context.args.not_nil! args = Context.args.not_nil!
login = args[0] login = args[0]

View File

@ -120,4 +120,23 @@ class AuthD::Request
end end
end end
AuthD.requests << DecodeToken AuthD.requests << DecodeToken
IPC::JSON.message Exit, 248 do
def initialize
end
def to_s(io : IO)
super io
end
def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil?
logged_user.assert_permission("authd", "*", User::PermissionLevel::Admin)
Baguette::Log.warning "exit requested, bye"
exit 0
end
end
AuthD.requests << Exit
end end