Skip to content

Commit aa1653a

Browse files
authored
CA-412636: hostname changed to localhost with static IP and reboot (#6546)
According to https://www.freedesktop.org/software/systemd/man/latest/hostname.html Systemd set hostname with following sequence - kernel parameter, systemd.hostname - static hostname in /etc/hostname - transient hostname like DHCP - localhost at systemd compile time Once the host is configured with static IP and reboot, it would just lost its hostname as no DHCP or static IP available. However, the hostname is critical to AD function as it construct the machine account. The hostname should be persisted as static name during joining AD, this is also what PBIS does. Note: the static hostname is not cleaned during domain leave. This is by intention to avoid losing hostname after reboot with static IP cba2f1d tried to resovle the issue and update /etc/resolv.conf However, /etc/resolv.conf does not help and conflict with xcp-networkd, as networkd override the configure every 5 minutes Here we just revert the resolv.conf update
2 parents f9e7969 + 267c414 commit aa1653a

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

ocaml/xapi/extauth_plugin_ADwinbind.ml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,23 +1434,6 @@ module ConfigHosts = struct
14341434
|> write_string_to_file path
14351435
end
14361436

1437-
module ResolveConfig = struct
1438-
let path = "/etc/resolv.conf"
1439-
1440-
type t = Add | Remove
1441-
1442-
let handle op domain =
1443-
let open Xapi_stdext_unix.Unixext in
1444-
let config = Printf.sprintf "search %s" domain in
1445-
read_lines ~path |> List.filter (fun x -> x <> config) |> fun x ->
1446-
(match op with Add -> config :: x | Remove -> x) |> fun x ->
1447-
x @ [""] |> String.concat "\n" |> write_string_to_file path
1448-
1449-
let join ~domain = handle Add domain
1450-
1451-
let leave ~domain = handle Remove domain
1452-
end
1453-
14541437
module DNSSync = struct
14551438
let task_name = "Sync hostname with DNS"
14561439

@@ -1827,7 +1810,11 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18271810
ClosestKdc.trigger_update ~start:0. ;
18281811
RotateMachinePassword.trigger_rotate ~start:0. ;
18291812
ConfigHosts.join ~domain:service_name ~name:netbios_name ;
1830-
ResolveConfig.join ~domain:service_name ;
1813+
let _, _ =
1814+
Forkhelpers.execute_command_get_output !Xapi_globs.set_hostname
1815+
[get_localhost_name ()]
1816+
in
1817+
(* Trigger right now *)
18311818
DNSSync.trigger_sync ~start:0. ;
18321819
Winbind.set_machine_account_encryption_type netbios_name ;
18331820
debug "Succeed to join domain %s" service_name
@@ -1836,15 +1823,13 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18361823
error "Join domain: %s error: %s" service_name stdout ;
18371824
clear_winbind_config () ;
18381825
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1839-
ResolveConfig.leave ~domain:service_name ;
18401826
(* The configure is kept for debug purpose with max level *)
18411827
raise (Auth_service_error (stdout |> tag_from_err_msg, stdout))
18421828
| Xapi_systemctl.Systemctl_fail _ ->
18431829
let msg = Printf.sprintf "Failed to start %s" Winbind.name in
18441830
error "Start daemon error: %s" msg ;
18451831
config_winbind_daemon ~domain:None ~workgroup:None ~netbios_name:None ;
18461832
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1847-
ResolveConfig.leave ~domain:service_name ;
18481833
raise (Auth_service_error (E_GENERIC, msg))
18491834
| e ->
18501835
let msg =
@@ -1856,7 +1841,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18561841
error "Enable extauth error: %s" msg ;
18571842
clear_winbind_config () ;
18581843
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1859-
ResolveConfig.leave ~domain:service_name ;
18601844
raise (Auth_service_error (E_GENERIC, msg))
18611845

18621846
(* unit on_disable()
@@ -1871,7 +1855,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18711855
let user = List.assoc_opt "user" config_params in
18721856
let pass = List.assoc_opt "pass" config_params in
18731857
let {service_name; netbios_name; _} = get_domain_info_from_db () in
1874-
ResolveConfig.leave ~domain:service_name ;
18751858
DNSSync.stop_sync () ;
18761859
( match netbios_name with
18771860
| Some netbios ->

0 commit comments

Comments
 (0)