mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-12 08:04:25 +08:00
Merge pull request #64 from gravitl/feature_v0.2_multinet
cleaned up netclient uninstall for multiple networks
This commit is contained in:
commit
3ac3ed1228
1 changed files with 24 additions and 1 deletions
|
@ -173,9 +173,29 @@ WantedBy=timers.target
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isOnlyService(network string) (bool, error) {
|
||||||
|
isonly := false
|
||||||
|
files, err := filepath.Glob("/etc/netclient/netconfig-*")
|
||||||
|
if err != nil {
|
||||||
|
return isonly, err
|
||||||
|
}
|
||||||
|
count := len(files)
|
||||||
|
if count == 0 {
|
||||||
|
isonly = true
|
||||||
|
}
|
||||||
|
return isonly, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func RemoveSystemDServices(network string) error {
|
func RemoveSystemDServices(network string) error {
|
||||||
sysExec, err := exec.LookPath("systemctl")
|
sysExec, err := exec.LookPath("systemctl")
|
||||||
|
|
||||||
|
|
||||||
|
fullremove, err := isOnlyService(network)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
cmdSysDisableService := &exec.Cmd {
|
cmdSysDisableService := &exec.Cmd {
|
||||||
Path: sysExec,
|
Path: sysExec,
|
||||||
Args: []string{ sysExec, "disable", "netclient@.service"},
|
Args: []string{ sysExec, "disable", "netclient@.service"},
|
||||||
|
@ -212,11 +232,13 @@ func RemoveSystemDServices(network string) error {
|
||||||
fmt.Println("Error stopping netclient@.service. Please investigate.")
|
fmt.Println("Error stopping netclient@.service. Please investigate.")
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
if fullremove {
|
||||||
err = cmdSysDisableService.Run()
|
err = cmdSysDisableService.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error disabling netclient@.service. Please investigate.")
|
fmt.Println("Error disabling netclient@.service. Please investigate.")
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
err = cmdSysStopTimer.Run()
|
err = cmdSysStopTimer.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error stopping netclient-"+network+".timer. Please investigate.")
|
fmt.Println("Error stopping netclient-"+network+".timer. Please investigate.")
|
||||||
|
@ -227,8 +249,9 @@ func RemoveSystemDServices(network string) error {
|
||||||
fmt.Println("Error disabling netclient-"+network+".timer. Please investigate.")
|
fmt.Println("Error disabling netclient-"+network+".timer. Please investigate.")
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
if fullremove {
|
||||||
err = os.Remove("/etc/systemd/system/netclient@.service")
|
err = os.Remove("/etc/systemd/system/netclient@.service")
|
||||||
|
}
|
||||||
err = os.Remove("/etc/systemd/system/netclient-"+network+".timer")
|
err = os.Remove("/etc/systemd/system/netclient-"+network+".timer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error removing file. Please investigate.")
|
fmt.Println("Error removing file. Please investigate.")
|
||||||
|
|
Loading…
Add table
Reference in a new issue