forked from wrenn/wrenn
Prototype with single host server and no admin panel (#2)
Reviewed-on: wrenn/sandbox#2 Co-authored-by: pptx704 <rafeed@omukk.dev> Co-committed-by: pptx704 <rafeed@omukk.dev>
This commit is contained in:
40
envd/internal/services/process/signal.go
Normal file
40
envd/internal/services/process/signal.go
Normal file
@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package process
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"connectrpc.com/connect"
|
||||
|
||||
rpc "git.omukk.dev/wrenn/sandbox/envd/internal/services/spec/process"
|
||||
)
|
||||
|
||||
func (s *Service) SendSignal(
|
||||
_ context.Context,
|
||||
req *connect.Request[rpc.SendSignalRequest],
|
||||
) (*connect.Response[rpc.SendSignalResponse], error) {
|
||||
handler, err := s.getProcess(req.Msg.GetProcess())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var signal syscall.Signal
|
||||
switch req.Msg.GetSignal() {
|
||||
case rpc.Signal_SIGNAL_SIGKILL:
|
||||
signal = syscall.SIGKILL
|
||||
case rpc.Signal_SIGNAL_SIGTERM:
|
||||
signal = syscall.SIGTERM
|
||||
default:
|
||||
return nil, connect.NewError(connect.CodeUnimplemented, fmt.Errorf("invalid signal: %s", req.Msg.GetSignal()))
|
||||
}
|
||||
|
||||
err = handler.SendSignal(signal)
|
||||
if err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("error sending signal: %w", err))
|
||||
}
|
||||
|
||||
return connect.NewResponse(&rpc.SendSignalResponse{}), nil
|
||||
}
|
||||
Reference in New Issue
Block a user