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
*.so
*.dylib
main
# Test binary, built with `go test -c`
*.test

View File

@ -8,4 +8,4 @@ RUN go mod download
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: ./
volumes:
- ./:/app
edgebox-queue:
image: redis-alpine

55
main.go
View File

@ -1,20 +1,55 @@
package main
import (
"fmt"
"github.com/go-redis/redis/v8"
"flag"
"log"
"os"
"os/signal"
"time"
//"syscall"
)
func main() {
fmt.Println("Hello World")
// load command line arguments
// client := redis.NewClient(&redis.Options{
// Addr: "edgebox-queue:6379",
// Password: "", // no password set
// DB: 0, // use default DB
// })
// pong, err := client.Ping().Result()
// fmt.Println(pong, err)
name := flag.String("name", "edgebox", "name for the service")
flag.Parse()
log.Printf("Starting Sysctl service for %s", *name)
// 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")
}