-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
517 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/achu-1612/glcm" | ||
) | ||
|
||
/* | ||
This example demonstrates how to use socket communication with the runner. | ||
*/ | ||
|
||
var _ glcm.Service = &ServiceA{} | ||
var _ glcm.Hook = &ServiceA{} | ||
|
||
// ServiceA will imeplement the Service interface as well as the hook Handler interface. | ||
type ServiceA struct { | ||
PreHookResult string | ||
} | ||
|
||
func (s *ServiceA) Start(ctx glcm.Terminator) { | ||
for { | ||
<-time.After(time.Second * 2) | ||
|
||
select { | ||
case <-ctx.TermCh(): | ||
return | ||
|
||
default: | ||
log.Println("ServiceA is running ", time.Now()) | ||
log.Println("ServiceA PreHookResult: ", s.PreHookResult) | ||
} | ||
} | ||
} | ||
|
||
func (s *ServiceA) Status() string { | ||
return "" | ||
} | ||
|
||
func (s *ServiceA) Name() string { | ||
return "ServiceA" | ||
} | ||
|
||
func (s *ServiceA) Execute() error { | ||
log.Println("ServiceA PreHook executed") | ||
s.PreHookResult = "ServiceA PreHook executed successfully" | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
base := glcm.NewRunner(context.Background(), glcm.RunnerOptions{ | ||
Socket: true, | ||
Verbose: true, | ||
AllowedUID: []int{1000}, | ||
}) | ||
|
||
sA := &ServiceA{} | ||
|
||
if err := base.RegisterService( | ||
sA, | ||
glcm.ServiceOptions{ | ||
PreHooks: []glcm.Hook{sA}, | ||
}, | ||
); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
go func() { | ||
<-time.After(time.Second * 20) | ||
|
||
process, err := os.FindProcess(os.Getpid()) | ||
if err != nil { | ||
log.Printf("Error finding process: %s\n", err) | ||
return | ||
} | ||
|
||
if err := process.Signal(syscall.SIGTERM); err != nil { | ||
log.Printf("Error sending termination signal: %s\n", err) | ||
} | ||
|
||
}() | ||
|
||
if err := base.BootUp(); err != nil { | ||
log.Fatalf("Error while booting up the runner: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.