Skip to content
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

rm support for windows named pipe #15

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,10 @@ The following messages can be sent to the socket to control the services:
- `list`: list all the service and their current status.

### Example Usage

#### Windows

```go
// Example for Windows named pipe communication
pipeName := `\\.\pipe\glcm_pipe`
conn, err := winio.DialPipe(pipeName, nil)
if err != nil {
log.Fatalf("Failed to connect to pipe: %v", err)
}
defer conn.Close()

_, err = conn.Write([]byte("start MyService"))
if err != nil {
log.Fatalf("Failed to send message: %v", err)
}
```sh
echo "restartAll" | socat - UNIX-CONNECT:/tmp/glcm.sock
```

#### Linux

```go
// Example for Linux Unix domain socket communication
socketPath := "/tmp/glcm_socket"
Expand Down
1 change: 1 addition & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var (
ErrRunnerAlreadyRunning = errors.New("runner already running")
ErrRegisterNilService = errors.New("can not register nil service")
ErrUnsupportedOS = errors.New("unsupported OS")
ErrSocketNoService = errors.New("no service provided")
)
24 changes: 12 additions & 12 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ type runner struct {
allowedUIDs []int
}

// RunnerStatus represents the status of the runner.
type RunnerStatus struct {
IsRunning bool `json:"isRunning"`
Services map[string]ServiceStatus `json:"services"`
}

// New returns a new instance of the runner.
func NewRunner(ctx context.Context, opts RunnerOptions) Runner {
r := &runner{
Expand Down Expand Up @@ -300,24 +306,18 @@ func (r *runner) RestartAllServices() {
}
}

func (r *runner) ListServices() interface{} {
func (r *runner) Status() *RunnerStatus {
r.mu.Lock()
defer r.mu.Unlock()

var services []struct {
Name string
Status string
status := &RunnerStatus{
IsRunning: r.isRunning,
Services: make(map[string]ServiceStatus),
}

for _, svc := range r.svc {
services = append(services, struct {
Name string
Status string
}{
Name: svc.Name(),
Status: string(svc.Status),
})
status.Services[svc.Name()] = svc.Status
}

return services
return status
}
Loading