From: Sebastien Douheret Date: Sat, 7 Oct 2017 21:10:38 +0000 (+0200) Subject: Kill right Syncthing (same url) in DEBUG mode X-Git-Tag: v1.0.0-rc1~22 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-server.git;a=commitdiff_plain;h=a3d2ca72d05d28b1ae5820787ff696dd75fd17cc Kill right Syncthing (same url) in DEBUG mode Signed-off-by: Sebastien Douheret --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 826f7fd..d2c6144 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -55,6 +55,7 @@ "mfolders", "IFOLDER", "flds", - "dflt" + "dflt", + "stconfig" ] } diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go index b14f40d..d1ebbe6 100644 --- a/lib/syncthing/st.go +++ b/lib/syncthing/st.go @@ -34,16 +34,16 @@ type SyncThing struct { STICmd *exec.Cmd MyID string Connected bool + Events *Events // Private fields binDir string logsDir string exitSTChan chan ExitChan exitSTIChan chan ExitChan - conf *xdsconfig.Config client *common.HTTPClient log *logrus.Logger - Events *Events + conf *xdsconfig.Config } // ExitChan Channel used for process exit @@ -134,7 +134,8 @@ func (s *SyncThing) startProc(exeName string, args []string, env []string, eChan // Kill existing process (useful for debug ;-) ) if os.Getenv("DEBUG_MODE") != "" { - exec.Command("bash", "-c", "pkill -9 "+exeName).Output() + fmt.Printf("\n!!! DEBUG_MODE set: KILL existing %s process(es) !!!\n", exeName) + exec.Command("bash", "-c", "ps -ax |grep "+exeName+" |grep "+s.BaseURL+" |cut -d' ' -f 1|xargs -I{} kill -9 {}").Output() } // When not set (or set to '.') set bin to path of xds-agent executable diff --git a/lib/syncthing/stfolder.go b/lib/syncthing/stfolder.go index 5c570a5..503ba4b 100644 --- a/lib/syncthing/stfolder.go +++ b/lib/syncthing/stfolder.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/iotbzh/xds-server/lib/folder" - "github.com/syncthing/syncthing/lib/config" + stconfig "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/protocol" ) @@ -69,7 +69,7 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { return "", err } - newDevice := config.DeviceConfiguration{ + newDevice := stconfig.DeviceConfiguration{ DeviceID: devID, Name: stClientID, Addresses: []string{"dynamic"}, @@ -95,7 +95,7 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { id = stClientID[0:15] + "_" + label } - folder := config.FolderConfiguration{ + folder := stconfig.FolderConfiguration{ ID: id, Label: label, Path: filepath.Join(s.conf.FileConf.ShareRootDir, f.ClientPath), @@ -105,12 +105,12 @@ func (s *SyncThing) FolderChange(f folder.FolderConfig) (string, error) { folder.RescanIntervalS = s.conf.FileConf.SThgConf.RescanIntervalS } - folder.Devices = append(folder.Devices, config.FolderDeviceConfiguration{ + folder.Devices = append(folder.Devices, stconfig.FolderDeviceConfiguration{ DeviceID: newDevice.DeviceID, }) found = false - var fld config.FolderConfiguration + var fld stconfig.FolderConfiguration for _, fld = range stCfg.Folders { if folder.ID == fld.ID { fld = folder @@ -155,8 +155,8 @@ func (s *SyncThing) FolderDelete(id string) error { } // FolderConfigGet Returns the configuration of a specific folder -func (s *SyncThing) FolderConfigGet(folderID string) (config.FolderConfiguration, error) { - fc := config.FolderConfiguration{} +func (s *SyncThing) FolderConfigGet(folderID string) (stconfig.FolderConfiguration, error) { + fc := stconfig.FolderConfiguration{} if folderID == "" { return fc, fmt.Errorf("folderID not set") }