|
13 | 13 | *) |
14 | 14 | (** Periodic scheduler for background tasks. *) |
15 | 15 |
|
| 16 | +module Date = Clock.Date |
| 17 | + |
16 | 18 | module D = Debug.Make (struct let name = "backgroundscheduler" end) |
17 | 19 |
|
18 | 20 | open D |
@@ -73,6 +75,24 @@ let register ~__context = |
73 | 75 | (fun __context -> Xapi_subject.update_all_subjects ~__context |
74 | 76 | ) |
75 | 77 | 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 |
76 | 96 | let update_all_subjects_delay = 10.0 in |
77 | 97 | (* initial delay = 10 seconds *) |
78 | 98 | if master then |
@@ -133,6 +153,7 @@ let register ~__context = |
133 | 153 | "Check stunnel cache expiry" |
134 | 154 | (Xapi_stdext_threads_scheduler.Scheduler.Periodic stunnel_period) |
135 | 155 | stunnel_period Stunnel_cache.gc ; |
| 156 | + sync_ssh_status ~__context ; |
136 | 157 | if |
137 | 158 | master |
138 | 159 | && Db.Pool.get_update_sync_enabled ~__context |
|
0 commit comments