-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: run manager-api as an OS agnostic service #1667
Conversation
Backend CLI Test is failing for changing |
hi |
ya sure :) |
pinging @nic-chen for review when you have time. ps. reverted all the changes made to manger-api back. |
Codecov Report
@@ Coverage Diff @@
## master #1667 +/- ##
==========================================
+ Coverage 72.48% 73.96% +1.48%
==========================================
Files 133 86 -47
Lines 5728 2612 -3116
Branches 666 666
==========================================
- Hits 4152 1932 -2220
+ Misses 1332 680 -652
+ Partials 244 0 -244
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
@bisakhmondal |
Totally agree with you 👍 . A few days back I found https://github.com/kardianos/service. It seems it's gonna serve our purpose (I haven't tested it though). What do you think? |
looks good. you could find some more libs and compare them |
Ok, I'll post it here :) |
any news? @bisakhmondal |
Hii @membphis, @nic-chen, I have checked and found these few packages that look good and have cross-platform support. On the way, found a lot of packages that run as a bg process using
Let me know which one you like :) package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/takama/daemon"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
type Service struct {
daemon.Daemon
}
func (service* Service) Manage() (string, error){
if len(os.Args) > 1 {
command := os.Args[1]
switch command {
case "install":
return service.Install()
case "remove":
return service.Remove()
case "start":
return service.Start()
case "stop":
return service.Stop()
case "status":
return service.Status()
default:
return "Usage: myservice install | remove | start | stop | status", nil
}
}
r := gin.Default()
fmt.Println("id: ",os.Getpid())
fmt.Println("ppid: ", os.Getppid())
r.GET("/", func(g *gin.Context) {
g.JSON(http.StatusOK, gin.H{
"message": "Server running successfully",
})
})
go r.Run(":8080")
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
sis := <- sig
fmt.Println("signal received: ", sis.String())
time.Sleep(2*time.Second)
fmt.Println("Shutted down")
return "Closed", nil
}
func main() {
srv, err := daemon.New("my-gin-app", "my gin app", daemon.SystemDaemon)
if err !=nil{
panic(err)
}
service := &Service{srv}
status, err := service.Manage()
if err != nil{
panic(err)
}
fmt.Println(status)
} commands go build main.go
sudo ./main install
sudo ./main start Thanks😄 |
hi, @bisakhmondal I think you could start a discussion on the mailing list: dev@apisix.apache.org, including which lib should be used and what our service name should be called, |
Absolutely. No problem :) |
@tokers do you have time to look at this? #1667 (comment) In memory, you are familiar with this. |
api/manager-api.service
Outdated
Type=simple | ||
Restart=on-failure | ||
RestartSec=5 | ||
WorkingDirectory=<"Your Directory">/apisix-dashboard/output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the standard release have this directory? @nic-chen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if it is built from source. The build script takes care of that. However, for rpm tarball, the directory structure is slightly customized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tokers After the build, there will be an output
directory.
The current problem is to choose a suitable library to implement this feature. Please check the mailing list when you have time to discuss it. @bisakhmondal has started a discussion. thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have created an issue about this when we build an RPM package?
Hii all, I am updating this PR with |
don't see the update? @bisakhmondal |
Deploy preview for apisix-dashboard ready! Built with commit 3c81afd |
Codecov Report
@@ Coverage Diff @@
## master #1667 +/- ##
==========================================
- Coverage 71.62% 71.03% -0.60%
==========================================
Files 172 173 +1
Lines 6119 6200 +81
Branches 711 711
==========================================
+ Hits 4383 4404 +21
- Misses 1487 1539 +52
- Partials 249 257 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Updated :) Fully tested on Linux (ubuntu 20.04). I don't have macOS or windows. Please let me know if it is working or not when you have some time. |
LGTM too!. |
api/manager-api.service
Outdated
# | ||
|
||
[Unit] | ||
Description=Manager-API service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add the keyword "Apache APISIX"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, the binary takes care of running itself as a service. Unit file for each platform isn't required anymore. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing test cases for the new code
Agree. |
Okay |
var err error | ||
service, err = createService() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error occurred while initializing service: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can quit after outputing this message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I avoided quitting because executing plain ./manager-api
doesn't require service struct ref. If somehow createService
returns a nil service and service-specific commands are used go runtime manager will throw an error of referencing a nil struct before any line of actual logic of manager-api being executed (slightly ungraceful though). Let me know what you think.
@bisakhmondal I think we can change the title now, it's not so associated with systemd. |
Cool. Thank you. |
pinging @starsz to have a look, when you have some time. |
LGTM.Thank you very much. |
# Conflicts: # api/cmd/managerapi.go
Thank you @nic-chen for resolving the merge conflicts. All CI has passed. I guess it's now safe to merge into master :) |
Please answer these questions before submitting a pull request, or your PR will get closed.
Why submit this pull request?
What changes will this PR take into?
Currently to run manager-api as a background process is through nohup to avoid unintended SIGHUP from the shell used for initialization.
This PR focuses on running manager-api as an OS agnostic service.
to run,
Related issues
#842
Checklist: