(cmd *exec.Cmd, config *globalProcessComposeConfig, port int, projectDir string, w io.Writer)
| 214 | } |
| 215 | |
| 216 | func runProcessManagerInBackground(cmd *exec.Cmd, config *globalProcessComposeConfig, port int, projectDir string, w io.Writer) error { |
| 217 | logdir := filepath.Join(projectDir, processComposeLogfile) |
| 218 | logfile, err := os.OpenFile(logdir, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_TRUNC, 0o664) |
| 219 | if err != nil { |
| 220 | return fmt.Errorf("failed to open process-compose log file: %w", err) |
| 221 | } |
| 222 | |
| 223 | cmd.Stdout = logfile |
| 224 | cmd.Stderr = logfile |
| 225 | |
| 226 | // These attributes set the process group ID to the process ID of process-compose |
| 227 | // Starting in it's own process group means it won't be terminated if the shell crashes |
| 228 | cmd.SysProcAttr = &syscall.SysProcAttr{ |
| 229 | Setpgid: true, |
| 230 | Pgid: 0, |
| 231 | } |
| 232 | |
| 233 | if err := cmd.Start(); err != nil { |
| 234 | return fmt.Errorf("failed to start process-compose: %w", err) |
| 235 | } |
| 236 | |
| 237 | fmt.Fprintf(w, "Process-compose is now running on port %d\n", port) |
| 238 | fmt.Fprintf(w, "To stop your services, run `devbox services stop`\n") |
| 239 | |
| 240 | projectConfig := instance{ |
| 241 | Pid: cmd.Process.Pid, |
| 242 | Port: port, |
| 243 | } |
| 244 | |
| 245 | config.Instances[projectDir] = projectConfig |
| 246 | |
| 247 | err = writeGlobalProcessComposeJSON(config, config.File) |
| 248 | if err != nil { |
| 249 | return fmt.Errorf("failed to write global process-compose config: %w", err) |
| 250 | } |
| 251 | |
| 252 | return nil |
| 253 | } |
| 254 | |
| 255 | func StopProcessManager(ctx context.Context, projectDir string, w io.Writer) error { |
| 256 | configFile, err := openGlobalConfigFile() |
no test coverage detected