Browse Source

Merge pull request #64 from gravitl/feature_v0.2_multinet

cleaned up netclient uninstall for multiple networks
Alex 4 years ago
parent
commit
3ac3ed1228
1 changed files with 24 additions and 1 deletions
  1. 24 1
      netclient/functions/local.go

+ 24 - 1
netclient/functions/local.go

@@ -173,9 +173,29 @@ WantedBy=timers.target
 	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 {
         sysExec, err := exec.LookPath("systemctl")
 
+
+	fullremove, err := isOnlyService(network)
+	if err != nil {
+		fmt.Println(err)
+	}
+
         cmdSysDisableService := &exec.Cmd {
                 Path: sysExec,
                 Args: []string{ sysExec, "disable", "[email protected]"},
@@ -212,11 +232,13 @@ func RemoveSystemDServices(network string) error {
                 fmt.Println("Error stopping [email protected]. Please investigate.")
                 fmt.Println(err)
         }
+	if fullremove {
         err = cmdSysDisableService.Run()
         if  err  !=  nil {
                 fmt.Println("Error disabling [email protected]. Please investigate.")
                 fmt.Println(err)
         }
+	}
         err = cmdSysStopTimer.Run()
         if  err  !=  nil {
                 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(err)
         }
-
+	if fullremove {
 	err = os.Remove("/etc/systemd/system/[email protected]")
+	}
 	err = os.Remove("/etc/systemd/system/netclient-"+network+".timer")
 	if err != nil {
                 fmt.Println("Error removing file. Please investigate.")