Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sobrinho committed Mar 8, 2022
1 parent 46e7650 commit 641cb5d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Gabriel Sobrinho
Copyright (c) 2017-2022 Gabriel Sobrinho

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ heroku config:set PGPOOL_ENABLED=0 # disables pgpool
heroku config:set PGPOOL_ENABLED=1 # enables pgpool
```

## Building

```bash
env GOOS=linux GOARCH=amd64 go build -o bin/start-pgpool src/start-pgpool.go
```

## FAQ

### This will start one pgpool per dyno?
Expand Down
Binary file modified bin/start-pgpool
Binary file not shown.
43 changes: 43 additions & 0 deletions src/start-pgpool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"log"
"os"
"os/exec"
)

func main() {
pgpool := run(false, "pgpool", "-n", "-f", "/app/vendor/pgpool/pgpool.conf", "-a", "/app/vendor/pgpool/pool_hba.conf")
app := run(true, os.Args[1], os.Args[2:]...)

go func() {
pgpool.Wait()

if app.Process != nil {
app.Process.Kill()
}
}()

app.Wait()

if pgpool.Process != nil {
pgpool.Process.Kill()
}
}

func run(pipeStdin bool, command string, args ...string) *exec.Cmd {
cmd := exec.Command(command, args...)

if pipeStdin {
cmd.Stdin = os.Stdin
}

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Start(); err != nil {
log.Fatal(err)
}

return cmd
}

0 comments on commit 641cb5d

Please sign in to comment.