mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-12 03:18:08 -04:00
feat: add start endpoint
This commit is contained in:
@@ -138,6 +138,13 @@ func Restart(envMap map[string]any) (bool, string) {
|
||||
return WaitForConnection()
|
||||
}
|
||||
|
||||
func IsOcisRunning() bool {
|
||||
if cmd != nil {
|
||||
return cmd.Process.Pid > 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func waitAllServices(startTime time.Time, timeout time.Duration) {
|
||||
timeoutS := timeout * time.Second
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"ociswrapper/common"
|
||||
"ociswrapper/ocis"
|
||||
)
|
||||
|
||||
@@ -115,7 +116,7 @@ func RollbackHandler(res http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
func StopOcisHandler(res http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodDelete {
|
||||
if req.Method != http.MethodPost {
|
||||
http.Error(res, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
@@ -124,6 +125,24 @@ func StopOcisHandler(res http.ResponseWriter, req *http.Request) {
|
||||
sendResponse(res, success, message)
|
||||
}
|
||||
|
||||
func StartOcisHandler(res http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPost {
|
||||
http.Error(res, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
if ocis.IsOcisRunning() {
|
||||
sendResponse(res, false, "oCIS server is already running")
|
||||
return
|
||||
}
|
||||
|
||||
common.Wg.Add(1)
|
||||
go ocis.Start(nil)
|
||||
|
||||
success, message := ocis.WaitForConnection()
|
||||
sendResponse(res, success, message)
|
||||
}
|
||||
|
||||
func CommandHandler(res http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPost {
|
||||
http.Error(res, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
|
||||
@@ -26,6 +26,7 @@ func Start(port string) {
|
||||
mux.HandleFunc("/rollback", handlers.RollbackHandler)
|
||||
mux.HandleFunc("/command", handlers.CommandHandler)
|
||||
mux.HandleFunc("/stop", handlers.StopOcisHandler)
|
||||
mux.HandleFunc("/start", handlers.StartOcisHandler)
|
||||
|
||||
httpServer.Handler = mux
|
||||
|
||||
|
||||
Reference in New Issue
Block a user