Skip to content

Commit ae8bd5f

Browse files
committed
CP-54138: Sync SSH status during XAPI startup
- Ensure host.ssh_enabled reflects the actual SSH service state on startup, in case it was manually changed by the user. - Reschedule the "disable SSH" job if: - SSH is currently enabled, - host.ssh_enabled_timeout is set to a positive value, and - host.ssh_expiry is in the future. Signed-off-by: Lunfan Zhang <[email protected]>
1 parent e29eda2 commit ae8bd5f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ocaml/xapi/xapi_host.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,6 @@ val set_ssh_enabled_timeout :
577577

578578
val set_console_idle_timeout :
579579
__context:Context.t -> self:API.ref_host -> value:int64 -> unit
580+
581+
val schedule_disable_ssh_job :
582+
__context:Context.t -> self:API.ref_host -> timeout:int64 -> unit

ocaml/xapi/xapi_periodic_scheduler_init.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*)
1414
(** Periodic scheduler for background tasks. *)
1515

16+
module Date = Clock.Date
17+
1618
module D = Debug.Make (struct let name = "backgroundscheduler" end)
1719

1820
open D
@@ -73,6 +75,24 @@ let register ~__context =
7375
(fun __context -> Xapi_subject.update_all_subjects ~__context
7476
)
7577
in
78+
let sync_ssh_status ~__context =
79+
let self = Helpers.get_localhost ~__context in
80+
let ssh_service = !Xapi_globs.ssh_service in
81+
let status = Fe_systemctl.is_active ~service:ssh_service in
82+
Db.Host.set_ssh_enabled ~__context ~self ~value:status ;
83+
84+
if status && Db.Host.get_ssh_enabled_timeout ~__context ~self > 0L then
85+
let expiry_time =
86+
Db.Host.get_ssh_expiry ~__context ~self
87+
|> Date.to_unix_time
88+
|> Int64.of_float
89+
in
90+
let current_time = Unix.time () |> Int64.of_float in
91+
92+
if Int64.compare expiry_time current_time > 0 then
93+
let timeout = Int64.sub expiry_time current_time in
94+
Xapi_host.schedule_disable_ssh_job ~__context ~self ~timeout
95+
in
7696
let update_all_subjects_delay = 10.0 in
7797
(* initial delay = 10 seconds *)
7898
if master then
@@ -133,6 +153,7 @@ let register ~__context =
133153
"Check stunnel cache expiry"
134154
(Xapi_stdext_threads_scheduler.Scheduler.Periodic stunnel_period)
135155
stunnel_period Stunnel_cache.gc ;
156+
sync_ssh_status ~__context ;
136157
if
137158
master
138159
&& Db.Pool.get_update_sync_enabled ~__context

0 commit comments

Comments
 (0)