Add setHostname function to enit
This commit is contained in:
parent
57e92eef91
commit
e44e0df0d6
@ -9,6 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -41,6 +42,8 @@ func main() {
|
|||||||
mountVirtualFilesystems()
|
mountVirtualFilesystems()
|
||||||
// Mount filesystems in fstab
|
// Mount filesystems in fstab
|
||||||
mountFilesystems()
|
mountFilesystems()
|
||||||
|
// Set hostname
|
||||||
|
setHostname()
|
||||||
// Start service manager
|
// Start service manager
|
||||||
startServiceManager()
|
startServiceManager()
|
||||||
|
|
||||||
@ -168,6 +171,25 @@ func stopServiceManager() {
|
|||||||
fmt.Println("Done.")
|
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() {
|
func waitZombieProcesses() {
|
||||||
for {
|
for {
|
||||||
if wpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil); wpid <= 0 {
|
if wpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil); wpid <= 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user