go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/cmd/dev/main.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package main 9 10 import ( 11 "context" 12 "fmt" 13 "os" 14 15 "go.charczuk.com/sdk/cliutil" 16 "go.charczuk.com/sdk/graceful" 17 "go.charczuk.com/sdk/supervisor" 18 ) 19 20 func main() { 21 s := &supervisor.Supervisor{ 22 Services: []*supervisor.Service{ 23 { 24 Background: func(_ context.Context) context.Context { return context.Background() }, 25 Command: "go", 26 Args: []string{"run", "server/main.go", "--next-proxy-url=http://localhost:3000"}, 27 Env: append([]string{"PORT=8080"}, os.Environ()...), 28 WatchedPaths: []string{ 29 "./pkg/...", 30 "./server/...", 31 }, 32 Stdout: supervisor.PrefixWriter{Prefix: "nodes-srv| ", Writer: os.Stdout}, 33 Stderr: supervisor.PrefixWriter{Prefix: "nodes-srv-err| ", Writer: os.Stdout}, 34 RestartPolicy: supervisor.RestartPolicySuccessiveFailures(5), 35 }, 36 { 37 Background: func(_ context.Context) context.Context { return context.Background() }, 38 Command: "npm", 39 Args: []string{"run", "dev"}, 40 WorkDir: "./static/_nextjs", 41 Stdout: supervisor.PrefixWriter{Prefix: "nodes-ui| ", Writer: os.Stdout}, 42 Stderr: supervisor.PrefixWriter{Prefix: "nodes-ui-err| ", Writer: os.Stdout}, 43 RestartPolicy: supervisor.RestartPolicySuccessiveFailures(5), 44 }, 45 { 46 Background: func(_ context.Context) context.Context { return context.Background() }, 47 Command: "go", 48 Args: []string{"run", "worker/main.go"}, 49 WatchedPaths: []string{ 50 "./pkg/...", 51 "./worker/...", 52 }, 53 Stdout: supervisor.PrefixWriter{Prefix: "nodes-wrk| ", Writer: os.Stdout}, 54 Stderr: supervisor.PrefixWriter{Prefix: "nodes-wrk-err| ", Writer: os.Stdout}, 55 RestartPolicy: supervisor.RestartPolicySuccessiveFailures(5), 56 }, 57 { 58 Background: func(_ context.Context) context.Context { return context.Background() }, 59 Command: "temporal", 60 Args: []string{"server", "start-dev", "--log-format=pretty", "--log-level=warn"}, 61 Env: os.Environ(), 62 Stdout: supervisor.PrefixWriter{Prefix: "temporalite| ", Writer: os.Stdout}, 63 Stderr: supervisor.PrefixWriter{Prefix: "temporalite-err| ", Writer: os.Stdout}, 64 RestartPolicy: supervisor.RestartPolicySuccessiveFailures(5), 65 }, 66 }, 67 } 68 fmt.Printf("!! nodes dev starting\n") 69 fmt.Printf("!! you can force a restart of the sub-process tree with: kill -HUP %d\n", os.Getpid()) 70 if err := graceful.StartForShutdown(context.Background(), s); err != nil { 71 cliutil.Fatal(err) 72 } 73 }