Files
forego/unix.go
T
Bernerd Schaefer c6e54eeee7 Use bash from current environment
Not all Unix platforms put their `bash` executable at `/bin/bash`,
for example on NixOS it may exist at `/run/current-system/sw/bin/bash`.

Instead of using `/bin/bash`, then, use `bash` alone,
and allow the [cmd package to resolve the correct path][cmd]
bashed on the user's current environment.

  [cmd]: https://golang.org/pkg/os/exec/#Command

Before:

```
$ forego start
forego  | starting web.1 on port 3000
forego  | Failed to start web.1: fork/exec /bin/bash: no such file or directory
forego  | starting worker.1 on port 3100
forego  | Failed to start worker.1: fork/exec /bin/bash: no such file or directory
```

After:

```
$ forego start
forego  | starting web.1 on port 3000
forego  | starting worker.1 on port 3100
web.1   | [26076] Started
```
2016-02-23 15:32:55 -08:00

39 lines
741 B
Go

// +build darwin freebsd linux netbsd openbsd
package main
import (
"fmt"
"path/filepath"
"syscall"
)
const osHaveSigTerm = true
func ShellInvocationCommand(interactive bool, root, command string) []string {
shellArgument := "-c"
if interactive {
shellArgument = "-ic"
}
profile := filepath.Join(root, ".profile")
shellCommand := fmt.Sprintf("source \"%s\" 2>/dev/null; %s", profile, command)
return []string{"bash", shellArgument, shellCommand}
}
func (p *Process) PlatformSpecificInit() {
if !p.Interactive {
p.SysProcAttr = &syscall.SysProcAttr{}
p.SysProcAttr.Setsid = true
}
return
}
func (p *Process) SendSigTerm() {
p.Signal(syscall.SIGTERM)
}
func (p *Process) SendSigKill() {
p.Signal(syscall.SIGKILL)
}