Skip to content

Commit ce45a11

Browse files
committed
CA-412636: hostname changed to localhost with static IP and reboot
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. Other parts of that commit can still benifit as it push the hostname to DNS Signed-off-by: Lin Liu <[email protected]>
1 parent a14bc90 commit ce45a11

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

ocaml/xapi/extauth_plugin_ADwinbind.ml

Lines changed: 4 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,10 @@ 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+
Forkhelpers.execute_command_get_output !Xapi_globs.set_hostname
1814+
[get_localhost_name ()]
1815+
|> ignore ;
1816+
(* Trigger right now *)
18311817
DNSSync.trigger_sync ~start:0. ;
18321818
Winbind.set_machine_account_encryption_type netbios_name ;
18331819
debug "Succeed to join domain %s" service_name
@@ -1836,15 +1822,13 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18361822
error "Join domain: %s error: %s" service_name stdout ;
18371823
clear_winbind_config () ;
18381824
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1839-
ResolveConfig.leave ~domain:service_name ;
18401825
(* The configure is kept for debug purpose with max level *)
18411826
raise (Auth_service_error (stdout |> tag_from_err_msg, stdout))
18421827
| Xapi_systemctl.Systemctl_fail _ ->
18431828
let msg = Printf.sprintf "Failed to start %s" Winbind.name in
18441829
error "Start daemon error: %s" msg ;
18451830
config_winbind_daemon ~domain:None ~workgroup:None ~netbios_name:None ;
18461831
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1847-
ResolveConfig.leave ~domain:service_name ;
18481832
raise (Auth_service_error (E_GENERIC, msg))
18491833
| e ->
18501834
let msg =
@@ -1856,7 +1840,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18561840
error "Enable extauth error: %s" msg ;
18571841
clear_winbind_config () ;
18581842
ConfigHosts.leave ~domain:service_name ~name:netbios_name ;
1859-
ResolveConfig.leave ~domain:service_name ;
18601843
raise (Auth_service_error (E_GENERIC, msg))
18611844

18621845
(* unit on_disable()
@@ -1871,7 +1854,6 @@ module AuthADWinbind : Auth_signature.AUTH_MODULE = struct
18711854
let user = List.assoc_opt "user" config_params in
18721855
let pass = List.assoc_opt "pass" config_params in
18731856
let {service_name; netbios_name; _} = get_domain_info_from_db () in
1874-
ResolveConfig.leave ~domain:service_name ;
18751857
DNSSync.stop_sync () ;
18761858
( match netbios_name with
18771859
| Some netbios ->

0 commit comments

Comments
 (0)