Add setHostname function to enit
This commit is contained in:
parent
57e92eef91
commit
e44e0df0d6
@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@ -41,6 +42,8 @@ func main() {
|
||||
mountVirtualFilesystems()
|
||||
// Mount filesystems in fstab
|
||||
mountFilesystems()
|
||||
// Set hostname
|
||||
setHostname()
|
||||
// Start service manager
|
||||
startServiceManager()
|
||||
|
||||
@ -168,6 +171,25 @@ func stopServiceManager() {
|
||||
fmt.Println("Done.")
|
||||
}
|
||||
|
||||
func setHostname() {
|
||||
fmt.Print("Setting hostname... ")
|
||||
|
||||
bytes, err := os.ReadFile("/etc/hostname")
|
||||
if err != nil {
|
||||
log.Println("Could not set hostname!")
|
||||
return
|
||||
}
|
||||
|
||||
hostname := strings.TrimSpace(string(bytes))
|
||||
|
||||
if err := syscall.Sethostname([]byte(hostname)); err != nil {
|
||||
log.Println("Could not set hostname!")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Done.")
|
||||
}
|
||||
|
||||
func waitZombieProcesses() {
|
||||
for {
|
||||
if wpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil); wpid <= 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user