@@ -3112,18 +3112,47 @@ let emergency_clear_mandatory_guidance ~__context =
3112
3112
) ;
3113
3113
Db.Host. set_pending_guidances ~__context ~self ~value: []
3114
3114
3115
+ let set_ssh_auto_mode ~__context ~self ~value =
3116
+ debug " Setting SSH auto mode for host %s to %B"
3117
+ (Helpers. get_localhost_uuid () )
3118
+ value ;
3119
+
3120
+ Db.Host. set_ssh_auto_mode ~__context ~self ~value ;
3121
+
3122
+ try
3123
+ (* When enabled, the ssh_monitor_service regularly checks XAPI status to manage SSH availability.
3124
+ During normal operation when XAPI is running properly, SSH is automatically disabled.
3125
+ SSH is only enabled during emergency scenarios
3126
+ (e.g., when XAPI is down) to allow administrative access for troubleshooting. *)
3127
+ if value then (
3128
+ Xapi_systemctl. enable ~wait_until_success: false
3129
+ ! Xapi_globs. ssh_monitor_service ;
3130
+ Xapi_systemctl. start ~wait_until_success: false
3131
+ ! Xapi_globs. ssh_monitor_service
3132
+ ) else (
3133
+ Xapi_systemctl. stop ~wait_until_success: false
3134
+ ! Xapi_globs. ssh_monitor_service ;
3135
+ Xapi_systemctl. disable ~wait_until_success: false
3136
+ ! Xapi_globs. ssh_monitor_service
3137
+ )
3138
+ with e ->
3139
+ error " Failed to configure SSH auto mode: %s" (Printexc. to_string e) ;
3140
+ Helpers. internal_error " Failed to configure SSH auto mode: %s"
3141
+ (Printexc. to_string e)
3142
+
3115
3143
let disable_ssh_internal ~__context ~self =
3116
3144
try
3117
3145
debug " Disabling SSH for host %s" (Helpers. get_localhost_uuid () ) ;
3118
- Xapi_systemctl. disable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3146
+ if not (Db.Host. get_ssh_auto_mode ~__context ~self ) then
3147
+ Xapi_systemctl. disable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3119
3148
Xapi_systemctl. stop ~wait_until_success: false ! Xapi_globs. ssh_service ;
3120
3149
Db.Host. set_ssh_enabled ~__context ~self ~value: false
3121
3150
with e ->
3122
3151
error " Failed to disable SSH for host %s: %s" (Ref. string_of self)
3123
3152
(Printexc. to_string e) ;
3124
3153
Helpers. internal_error " Failed to disable SSH: %s" (Printexc. to_string e)
3125
3154
3126
- let schedule_disable_ssh_job ~__context ~self ~timeout =
3155
+ let schedule_disable_ssh_job ~__context ~self ~timeout ~ auto_mode =
3127
3156
let host_uuid = Helpers. get_localhost_uuid () in
3128
3157
let expiry_time =
3129
3158
match
@@ -3152,7 +3181,11 @@ let schedule_disable_ssh_job ~__context ~self ~timeout =
3152
3181
Xapi_stdext_threads_scheduler.Scheduler. add_to_queue
3153
3182
! Xapi_globs. job_for_disable_ssh
3154
3183
Xapi_stdext_threads_scheduler.Scheduler. OneShot (Int64. to_float timeout)
3155
- (fun () -> disable_ssh_internal ~__context ~self
3184
+ (fun () ->
3185
+ disable_ssh_internal ~__context ~self ;
3186
+ (* re-enable SSH auto mode if it was enabled before calling host.enable_ssh *)
3187
+ if auto_mode then
3188
+ set_ssh_auto_mode ~__context ~self ~value: true
3156
3189
) ;
3157
3190
3158
3191
Db.Host. set_ssh_expiry ~__context ~self ~value: expiry_time
@@ -3161,6 +3194,10 @@ let enable_ssh ~__context ~self =
3161
3194
try
3162
3195
debug " Enabling SSH for host %s" (Helpers. get_localhost_uuid () ) ;
3163
3196
3197
+ let cached_ssh_auto_mode = Db.Host. get_ssh_auto_mode ~__context ~self in
3198
+ (* Disable SSH auto mode when SSH is enabled manually *)
3199
+ set_ssh_auto_mode ~__context ~self ~value: false ;
3200
+
3164
3201
Xapi_systemctl. enable ~wait_until_success: false ! Xapi_globs. ssh_service ;
3165
3202
Xapi_systemctl. start ~wait_until_success: false ! Xapi_globs. ssh_service ;
3166
3203
@@ -3171,6 +3208,7 @@ let enable_ssh ~__context ~self =
3171
3208
! Xapi_globs. job_for_disable_ssh
3172
3209
| t ->
3173
3210
schedule_disable_ssh_job ~__context ~self ~timeout: t
3211
+ ~auto_mode: cached_ssh_auto_mode
3174
3212
) ;
3175
3213
3176
3214
Db.Host. set_ssh_enabled ~__context ~self ~value: true
@@ -3208,7 +3246,7 @@ let set_ssh_enabled_timeout ~__context ~self ~value =
3208
3246
! Xapi_globs. job_for_disable_ssh ;
3209
3247
Db.Host. set_ssh_expiry ~__context ~self ~value: Date. epoch
3210
3248
| t ->
3211
- schedule_disable_ssh_job ~__context ~self ~timeout: t
3249
+ schedule_disable_ssh_job ~__context ~self ~timeout: t ~auto_mode: false
3212
3250
3213
3251
let set_console_idle_timeout ~__context ~self ~value =
3214
3252
let assert_timeout_valid timeout =
@@ -3243,5 +3281,3 @@ let set_console_idle_timeout ~__context ~self ~value =
3243
3281
error " Failed to configure console timeout: %s" (Printexc. to_string e) ;
3244
3282
Helpers. internal_error " Failed to set console timeout: %Ld: %s" value
3245
3283
(Printexc. to_string e)
3246
-
3247
- let set_ssh_auto_mode ~__context ~self :_ ~value :_ = ()
0 commit comments