Fixed Dockerfile and compose files for auto re-build, added loop for system service behaviour

pull/5/head
Paulo Truta 2021-02-11 19:56:35 +01:00
parent 78b89a107b
commit 0c2fd3066e
4 changed files with 50 additions and 16 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.dll *.dll
*.so *.so
*.dylib *.dylib
main
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View File

@ -8,4 +8,4 @@ RUN go mod download
RUN go get github.com/githubnemo/CompileDaemon RUN go get github.com/githubnemo/CompileDaemon
ENTRYPOINT CompileDaemon --build="go build main.go" --command=./runsysctl ENTRYPOINT CompileDaemon --build="go build main.go" --command=./main

View File

@ -4,5 +4,3 @@ services:
build: ./ build: ./
volumes: volumes:
- ./:/app - ./:/app
edgebox-queue:
image: redis-alpine

61
main.go
View File

@ -1,20 +1,55 @@
package main package main
import ( import (
"fmt" "flag"
"github.com/go-redis/redis/v8" "log"
"os"
"os/signal"
"time"
//"syscall"
) )
func main() { func main() {
fmt.Println("Hello World") // load command line arguments
// client := redis.NewClient(&redis.Options{ name := flag.String("name", "edgebox", "name for the service")
// Addr: "edgebox-queue:6379",
// Password: "", // no password set flag.Parse()
// DB: 0, // use default DB
// }) log.Printf("Starting Sysctl service for %s", *name)
// pong, err := client.Ping().Result()
// fmt.Println(pong, err) // setup signal catching
sigs := make(chan os.Signal, 1)
}
// catch all signals since not explicitly listing
signal.Notify(sigs)
// Cathing specific signals can be done with:
//signal.Notify(sigs,syscall.SIGQUIT)
// method invoked upon seeing signal
go func() {
s := <-sigs
log.Printf("RECEIVED SIGNAL: %s", s)
AppCleanup()
os.Exit(1)
}()
// infinite loop
for {
log.Printf("Executing instruction %s", *name)
// wait random number of milliseconds
Nsecs := 1000
log.Printf("Next instruction executed in %dms", Nsecs)
time.Sleep(time.Millisecond * time.Duration(Nsecs))
}
}
// AppCleanup : cleanup app state before exit
func AppCleanup() {
log.Println("Cleaning up app status before exit")
}