# Service Command Handler # Domain: Cross-platform service management (systemd, launchd, runit, openrc) use ./shared.nu * def service-install [name: string binary: string --check = false] { {name: $name} } def service-start [name: string --check = false] { {name: $name} } def service-stop [name: string --check = false] { {name: $name} } def service-restart [name: string --check = false] { {name: $name} } def service-status [name: string] { {name: $name, running: false} } def service-list [--filter: string = ""] { [] } def service-detect-init [] { "systemd" } export def cmd-service [ action: string args: list = [] --check = false ] { if ($action == null) { help-service; return } match $action { "install" => { let name = ($args | get 0?) let binary = ($args | get 1?) if ($name == null or $binary == null) { print "Usage: provisioning service install [options]" exit 1 } let result = (service-install $name $binary --check=$check) print $"Service installed: [$result.name]" } "start" => { let name = ($args | get 0?) if ($name == null) { print "Usage: provisioning service start " exit 1 } let result = (service-start $name --check=$check) print $"Service started: [$result.name]" } "stop" => { let name = ($args | get 0?) if ($name == null) { print "Usage: provisioning service stop " exit 1 } let result = (service-stop $name --check=$check) print $"Service stopped: [$result.name]" } "restart" => { let name = ($args | get 0?) if ($name == null) { print "Usage: provisioning service restart " exit 1 } let result = (service-restart $name --check=$check) print $"Service restarted: [$result.name]" } "status" => { let name = ($args | get 0?) if ($name == null) { print "Usage: provisioning service status " exit 1 } let status = (service-status $name) print $"Service: [$status.name]" print $" Running: [$status.running]" } "list" => { let filter = ($args | get 0?) let services = (service-list --filter=$filter) if ($services | length) == 0 { print "No services found" } else { print "Services:" $services | each {|s| print $" • [$s.name] - Running: [$s.running]"} } } "detect-init" => { let init = (service-detect-init) print $"Detected init system: [$init]" } "help" | "--help" => { help-service } _ => { print $"Unknown service command: [$action]"; help-service; exit 1 } } } def help-service [] { print "Service management - Cross-platform service operations" print "" print "Usage: provisioning service [args]" print "" print "Actions:" print " install Install service" print " start Start service" print " stop Stop service" print " restart Restart service" print " status Check service status" print " list [filter] List services" print " detect-init Detect init system" }