-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2213 from ripienaar/2209.2
(#2209) Add a signal API
- Loading branch information
Showing
7 changed files
with
233 additions
and
18 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
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,82 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package executor | ||
|
||
import ( | ||
"context" | ||
"syscall" | ||
|
||
"github.com/choria-io/go-choria/inter" | ||
"github.com/choria-io/go-choria/providers/agent/mcorpc" | ||
"github.com/choria-io/go-choria/providers/execution" | ||
) | ||
|
||
type SignalRequest struct { | ||
JobID string `json:"id"` | ||
Signal int `json:"signal"` | ||
} | ||
|
||
type SignalResponse struct { | ||
Pid int `json:"pid"` | ||
Running bool `json:"running"` | ||
} | ||
|
||
func signalAction(ctx context.Context, req *mcorpc.Request, reply *mcorpc.Reply, agent *mcorpc.Agent, conn inter.ConnectorInfo) { | ||
spool := agent.Config.Choria.ExecutorSpool | ||
if spool == "" { | ||
abort(reply, "Executor spool is not configured") | ||
return | ||
} | ||
|
||
args := &SignalRequest{} | ||
|
||
if !mcorpc.ParseRequestData(args, req, reply) { | ||
return | ||
} | ||
|
||
if args.JobID == "" { | ||
abort(reply, "ID is required") | ||
} | ||
|
||
if args.Signal < 0 { | ||
abort(reply, "Signal is required") | ||
} | ||
|
||
resp := &SignalResponse{} | ||
|
||
p, err := execution.Load(spool, args.JobID) | ||
if err != nil { | ||
abort(reply, "Could not load job: %v", err.Error()) | ||
return | ||
} | ||
|
||
if proxyAuthorize(p, req, agent) { | ||
agent.Log.Warnf("Denying %s access to process created by %s#%s based on authorization policy for request %s", req.CallerID, p.Agent, p.Action, req.RequestID) | ||
abort(reply, "You are not authorized to call this %s#%s", p.Agent, p.Action) | ||
return | ||
} | ||
|
||
resp.Running = p.IsRunning() | ||
if !resp.Running { | ||
abort(reply, "Job %s is not running", args.JobID) | ||
return | ||
} | ||
|
||
resp.Pid, err = p.ParsePid() | ||
if err != nil { | ||
abort(reply, "Could not parse pid file: %v", err.Error()) | ||
return | ||
} | ||
|
||
err = p.Signal(syscall.Signal(args.Signal)) | ||
if err != nil { | ||
abort(reply, "Could not send signal: %v", err.Error()) | ||
return | ||
} | ||
|
||
resp.Running = p.IsRunning() | ||
|
||
reply.Data = resp | ||
} |
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.