MCPcopy Create free account
hub / github.com/PasarGuard/node / Start

Method Start

backend/xray/core.go:180–263  ·  view source on GitHub ↗
(xConfig *Config, debugMode bool)

Source from the content-addressed store, hash-verified

178}
179
180func (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

Callers 1

RestartMethod · 0.95

Calls 15

GenerateConfigFileMethod · 0.95
StartedMethod · 0.95
setStartupLogPhaseMethod · 0.95
handleProcessExitMethod · 0.95
captureProcessLogsMethod · 0.95
collectUnixSocketPathsFunction · 0.85
removeUnixSocketFilesFunction · 0.85
GetLogFilesMethod · 0.80
ToBytesMethod · 0.80
resetMethod · 0.80

Tested by

no test coverage detected