(xConfig *Config, debugMode bool)
| 178 | } |
| 179 | |
| 180 | func (c *Core) Start(xConfig *Config, debugMode bool) error { |
| 181 | accessFile, errorFile := xConfig.GetLogFiles() |
| 182 | |
| 183 | bytesConfig, err := xConfig.ToBytes() |
| 184 | if debugMode { |
| 185 | if err = c.GenerateConfigFile(bytesConfig); err != nil { |
| 186 | return err |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | c.mu.Lock() |
| 191 | defer c.mu.Unlock() |
| 192 | |
| 193 | // Check if already started after acquiring lock to prevent race condition |
| 194 | if c.Started() { |
| 195 | return errors.New("xray is started already") |
| 196 | } |
| 197 | |
| 198 | c.runtimeMu.Lock() |
| 199 | c.runtimeLogs.reset() |
| 200 | c.runtimeMu.Unlock() |
| 201 | |
| 202 | c.EnableStartupDiagnostics(c.startupLogSize) |
| 203 | c.setStartupLogPhase() |
| 204 | |
| 205 | // Clean up any orphaned xray processes before starting new one |
| 206 | if err := c.cleanupOrphanedProcesses(); err != nil { |
| 207 | log.Printf("warning: failed to cleanup orphaned processes: %v", err) |
| 208 | } |
| 209 | |
| 210 | // Force kill any orphaned process in this Core instance before starting new one |
| 211 | if c.process != nil && c.process.Process != nil { |
| 212 | pid := c.process.Process.Pid |
| 213 | _ = c.process.Process.Kill() |
| 214 | _ = killProcessTree(pid) |
| 215 | c.process = nil |
| 216 | c.processPID = 0 |
| 217 | } |
| 218 | |
| 219 | socketPaths := collectUnixSocketPaths(xConfig) |
| 220 | removeUnixSocketFiles(socketPaths) |
| 221 | |
| 222 | cmd := exec.Command(c.executablePath, "-c", "stdin:") |
| 223 | cmd.Env = append(os.Environ(), "XRAY_LOCATION_ASSET="+c.assetsPath) |
| 224 | // Set process attributes for proper process management |
| 225 | setProcAttributes(cmd) |
| 226 | |
| 227 | stdout, err := cmd.StdoutPipe() |
| 228 | if err != nil { |
| 229 | return err |
| 230 | } |
| 231 | |
| 232 | // Create a new logger for this core instance |
| 233 | c.logger = nodeLogger.New(debugMode) |
| 234 | if err = c.logger.SetLogFile(accessFile, errorFile); err != nil { |
| 235 | return err |
| 236 | } |
| 237 |
no test coverage detected