-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
#!/bin/bash | ||
|
||
|
||
echo "" | ||
echo "Building for Linux" | ||
echo "" | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o secrets-bridge-linux-amd64 | ||
|
||
echo "" | ||
echo "Building for Windows" | ||
echo "" | ||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o secrets-bridge-windows-amd64.exe | ||
|
||
echo "" | ||
echo "Building for Darwin" | ||
echo "" | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -o secrets-bridge-darwin-amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
daemon "github.com/sevlyar/go-daemon" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func serveDaemonized(cmd *cobra.Command, args []string) { | ||
if daemonize == "" { | ||
serve(cmd, args) | ||
return | ||
} | ||
|
||
ctx := daemon.Context{ | ||
LogFileName: daemonize, | ||
} | ||
child, err := ctx.Reborn() | ||
if err != nil { | ||
log.Fatalln("Error setting up daemon:", err) | ||
} | ||
|
||
if child == nil { | ||
log.Printf("Will daemonize upon successful socket listening. pid=%d\n", os.Getpid()) | ||
|
||
serve(cmd, args) | ||
// WARN: with all those `Fatalln` in `serve`, it's possible | ||
// `ctx.Release()` won't get called. | ||
ctx.Release() | ||
return | ||
} | ||
|
||
log.Printf("Setting up secrets-bridge daemon, pid=%d\n", child.Pid) | ||
|
||
// Parent, waiting for Listen signal, then exits. | ||
childReady := make(chan os.Signal, 5) | ||
signal.Notify(childReady, syscall.SIGUSR1) | ||
select { | ||
case <-childReady: | ||
log.Println("Setup successfully.") | ||
return | ||
case <-time.After(5 * time.Second): | ||
log.Fatalln("Failed. Timed out") | ||
} | ||
} | ||
|
||
func detachFromParent() { | ||
if daemonize != "" { | ||
time.Sleep(100 * time.Millisecond) | ||
proc, err := os.FindProcess(os.Getppid()) | ||
if err != nil { | ||
log.Fatalln("Couldn't find parent process id:", err) | ||
} | ||
|
||
log.Println("Daemonizing") | ||
|
||
if err := proc.Signal(syscall.SIGUSR1); err != nil { | ||
log.Fatalln("couldn't send SIGUSR1 signal to parent:", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// +build !linux | ||
|
||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func serveDaemonized(cmd *cobra.Command, args []string) { | ||
if daemonize == "" { | ||
serve(cmd, args) | ||
return | ||
} else { | ||
log.Fatalln("Daemonization not support on this platform.") | ||
} | ||
} | ||
|
||
func detachFromParent() {} |