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

Invalid daemon kind specified #104

Open
ImanMousavi opened this issue Oct 25, 2021 · 4 comments
Open

Invalid daemon kind specified #104

ImanMousavi opened this issue Oct 25, 2021 · 4 comments

Comments

@ImanMousavi
Copy link

func main() {
srv, err := daemon.New(name, description, daemon.SystemDaemon)
if err != nil { // <-- Invalid daemon kind specified
errlog.Println("Error: ************************", err)
os.Exit(1)
}

service := &Service{srv}
status, err := service.Manage()
if err != nil {
	log.Fatal(status, "\nError: ", err)
}
fmt.Println(status)


rand.Seed(time.Now().UnixNano())

}

@NateThornton
Copy link

If you're running on MacOSX; the simple example will not work as daemon.SystemDaemon is not supported. Try changing it to a different kind like GlobalDaemon

daemon/daemon.go

Lines 211 to 232 in 496d691

const (
// UserAgent is a user daemon that runs as the currently logged in user and
// stores its property list in the user’s individual LaunchAgents directory.
// In other words, per-user agents provided by the user. Valid for macOS only.
UserAgent Kind = "UserAgent"
// GlobalAgent is a user daemon that runs as the currently logged in user and
// stores its property list in the users' global LaunchAgents directory. In
// other words, per-user agents provided by the administrator. Valid for macOS
// only.
GlobalAgent Kind = "GlobalAgent"
// GlobalDaemon is a system daemon that runs as the root user and stores its
// property list in the global LaunchDaemons directory. In other words,
// system-wide daemons provided by the administrator. Valid for macOS only.
GlobalDaemon Kind = "GlobalDaemon"
// SystemDaemon is a system daemon that runs as the root user. In other words,
// system-wide daemons provided by the administrator. Valid for FreeBSD, Linux
// and Windows only.
SystemDaemon Kind = "SystemDaemon"
)

@ImanMousavi
Copy link
Author

Tank you

@prologic
Copy link

Just trying out your package. The "problem" on macOS is that neither UserAgent nor GlobalDaemon really "daemonize" the process. Is this a bug?

@doothez
Copy link

doothez commented Dec 19, 2022

Just trying out your package. The "problem" on macOS is that neither UserAgent nor GlobalDaemon really "daemonize" the process. Is this a bug?

Below code work for me for both MacOS and Linux.

func main() {
	var kind daemon.Kind
	switch runtime.GOOS {
	case "darwin":
		kind = daemon.GlobalDaemon
	default:
		kind = daemon.SystemDaemon
	}
	srv, err := daemon.New(name, description, kind, dependencies...)
	if err != nil {
		errlog.Println("Error: ", err)
		os.Exit(1)
	}
	service := &Service{srv}
	status, err := service.Manage()
	if err != nil {
		errlog.Println(status, "\nError: ", err)
		os.Exit(1)
	}
	fmt.Println(status)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants