Skip to content

Commit

Permalink
cleanup initi detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
taigrr committed Feb 14, 2025
1 parent 210a32c commit 143fc80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
15 changes: 2 additions & 13 deletions ingredients/service/providers_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"errors"
"fmt"
"os"
"sync"

"github.com/gogrlx/grlx/config"
Expand Down Expand Up @@ -45,24 +44,14 @@ func guessInit() string {
Init = c
return c
}
// Check if the init system is systemd
// https://manpages.ubuntu.com/manpages/xenial/en/man3/sd_booted.3.html
if _, ok := os.Stat("/run/systemd/system"); ok == nil {
return "systemd"
}

// allow the registered providers to guess the init system
for _, initSys := range provMap {
if initSys.IsInit() {
Init = initSys.InitName()
return Init
}
}
// otherwise, return the name of the process in PID 1
f, err := os.ReadFile("/proc/1/comm")
if err != nil {
return "unknown"
}
return string(f)
return ""
}

func NewServiceProvider(id string, method string, params map[string]interface{}) (types.ServiceProvider, error) {
Expand Down
7 changes: 2 additions & 5 deletions ingredients/service/systemd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package systemd

import (
"context"
"os"

"github.com/taigrr/systemctl"

Expand Down Expand Up @@ -86,10 +85,8 @@ func (s SystemdService) InitName() string {
}

func (s SystemdService) IsInit() bool {
if _, ok := os.Stat("/run/systemd/system"); ok == nil {
return true
}
return false
isSystemd, err := systemctl.IsSystemd()
return isSystemd && err == nil
}

func (s SystemdService) IsEnabled(ctx context.Context) (bool, error) {
Expand Down

0 comments on commit 143fc80

Please sign in to comment.