Fixed Dockerfile and compose files for auto re-build, added loop for system service behaviour
							parent
							
								
									78b89a107b
								
							
						
					
					
						commit
						0c2fd3066e
					
				|  | @ -4,6 +4,7 @@ | |||
| *.dll | ||||
| *.so | ||||
| *.dylib | ||||
| main | ||||
| 
 | ||||
| # Test binary, built with `go test -c` | ||||
| *.test | ||||
|  |  | |||
|  | @ -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 | ||||
|  | @ -4,5 +4,3 @@ services: | |||
|     build: ./ | ||||
|     volumes: | ||||
|       - ./:/app | ||||
|   edgebox-queue: | ||||
|     image: redis-alpine | ||||
								
									
									
										
											61
										
									
									main.go
									
									
									
									
								
								
							
							
										
											61
										
									
									main.go
									
									
									
									
								|  | @ -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") | ||||
| 	 | ||||
| 	// 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)
 | ||||
| 	 | ||||
| } | ||||
| 	// load command line arguments
 | ||||
| 
 | ||||
| 	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") | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue