// Start the assetto server. If it's already running, an ErrServerAlreadyRunning is returned.
Start the assetto server. If it's already running, an ErrServerAlreadyRunning is returned.
// Start the assetto server . If it ' s already running an ErrServerAlreadyRunning is returned .
func (as *AssettoServerProcess) Start() error {
	if as.IsRunning() {
		return ErrServerAlreadyRunning
	}
	as.mutex.Lock()
	defer as.mutex.Unlock()
	wd, err := os.Getwd()
	if err != nil {
		return err
	}
	as.cmd = exec.Command(filepath.Join(ServerInstallPath, serverExecutablePath))
	as.cmd.Dir = ServerInstallPath
	if as.out == nil {
		as.out = newLogBuffer(MaxLogSizeBytes)
	}
	as.cmd.Stdout = as.out
	as.cmd.Stderr = as.out
	err = as.cmd.Start()
	if err != nil {
		as.cmd = nil
		return err
	}
	for _, command := range config.Server.RunOnStart {
		parts := strings.Split(command, " ")
		var cmd *exec.Cmd
		if len(parts) > 1 {
			cmd = buildCommand(parts[0], parts[1:]...)
		} else {
			cmd = buildCommand(parts[0])
		}
		cmd.Stdout = pluginsOutput
		cmd.Stderr = pluginsOutput
		cmd.Dir = wd
		err := cmd.Start()
		if err != nil {
			logrus.Errorf("Could not run extra command: %s, err: %s", command, err)
			continue
		}
		as.extraProcesses = append(as.extraProcesses, cmd)
	}
	go func() {
		_ = as.cmd.Wait()
		as.stopChildProcesses()
		as.doneCh <- struct{}{}
	}()
	return nil
}
func ( as * AssettoServerProcess ) Start ( ) error { if as . IsRunning ( ) { return ErrServerAlreadyRunning } as . mutex . Lock ( ) defer as . mutex . Unlock ( ) wd , err := os . Getwd ( ) if err != nil { return err } as . cmd = exec . Command ( filepath . Join ( ServerInstallPath , serverExecutablePath ) ) as . cmd . Dir = ServerInstallPath if as . out == nil { as . out = newLogBuffer ( MaxLogSizeBytes ) } as . cmd . Stdout = as . out as . cmd . Stderr = as . out err = as . cmd . Start ( ) if err != nil { as . cmd = nil return err } for _ , command := range config . Server . RunOnStart { parts := strings . Split ( command , " " ) var cmd * exec . Cmd if len ( parts ) > 1 { cmd = buildCommand ( parts [ 0 ] , parts [ 1 : ] ... ) } else { cmd = buildCommand ( parts [ 0 ] ) } cmd . Stdout = pluginsOutput cmd . Stderr = pluginsOutput cmd . Dir = wd err := cmd . Start ( ) if err != nil { logrus . Errorf ( " " , command , err ) continue } as . extraProcesses = append ( as . extraProcesses , cmd ) } go func ( ) { _ = as . cmd . Wait ( ) as . stopChildProcesses ( ) as . doneCh <- struct { } { } } ( ) return nil }
Start the assetto server.
Start the assetto server .