feat(pidproxy): read startsecs from env

chore: centralize env prefix
This commit is contained in:
2023-12-10 22:23:43 +11:00
parent 8704f80d4b
commit ad8499daa5
6 changed files with 19 additions and 10 deletions

View File

@@ -8,13 +8,16 @@ import (
"syscall"
"time"
"gitea.suyono.dev/suyono/wingmate"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/sys/unix"
)
const (
pidFileFlag = "pid-file"
pidFileFlag = "pid-file"
EnvStartSecs = "STARTSECS"
EnvDefaultStartSecs = 1
)
var (
@@ -34,6 +37,10 @@ func main() {
found bool
)
viper.SetEnvPrefix(wingmate.EnvPrefix)
viper.BindEnv(EnvStartSecs)
viper.SetDefault(EnvStartSecs, EnvDefaultStartSecs)
if len(os.Args) <= 2 {
log.Println("invalid argument")
os.Exit(1)
@@ -77,7 +84,8 @@ func pidProxy(cmd *cobra.Command, args []string) error {
} else {
go startProcess(childArgs[0])
}
time.Sleep(time.Second)
initialWait := viper.GetInt(EnvStartSecs)
time.Sleep(time.Second * time.Duration(initialWait))
var (
err error