2024-07-04 15:21:04 +00:00
|
|
|
module Terminal
|
|
|
|
extend self
|
|
|
|
|
|
|
|
@@terminal_process : Process | Nil = nil
|
|
|
|
|
2024-07-04 17:44:16 +00:00
|
|
|
def start_terminal(_args = ["sh"], readonly = true)
|
2024-07-04 15:21:04 +00:00
|
|
|
args = ["-p", "7681", "-c", "admin:admin", "-o"]
|
|
|
|
args += ["-W"] unless readonly
|
2024-07-04 17:44:16 +00:00
|
|
|
args += _args
|
2024-07-04 15:21:04 +00:00
|
|
|
# We have a process there, kill it
|
2024-07-04 17:44:16 +00:00
|
|
|
begin
|
|
|
|
@@terminal_process.as(Process).terminate if !@@terminal_process.nil?
|
|
|
|
rescue e : RuntimeError
|
|
|
|
Log.error { "Error terminating terminal process: #{e.message}" }
|
|
|
|
end
|
2024-07-04 15:21:04 +00:00
|
|
|
@@terminal_process = Process.new(
|
|
|
|
command: "/usr/bin/ttyd",
|
|
|
|
args: args)
|
2024-07-04 17:44:16 +00:00
|
|
|
Log.info { "Terminal started on port 7681" }
|
2024-07-04 15:21:04 +00:00
|
|
|
end
|
|
|
|
end
|