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

Add a flag to control daemon or not, the signal handling miss #64

Open
liminghuang opened this issue Nov 13, 2019 · 4 comments
Open

Add a flag to control daemon or not, the signal handling miss #64

liminghuang opened this issue Nov 13, 2019 · 4 comments

Comments

@liminghuang
Copy link

Follow the Signal handling to do a sample, my program needs a flag to control it into daemon mode or not.
I add a new flag to control it.
dMode = flag.Bool("d", false, "Enable/Disable daemon mode")
and check the flag to enable daemon or not


    if *dMode == true {
		cntxt := &daemon.Context{
			PidFileName: "sample.pid",
			PidFilePerm: 0644,
			LogFileName: "sample.log",
			LogFilePerm: 0640,
			WorkDir:     "./",
			Umask:       027,
			Args:        []string{"[go-daemon sample]"},
		}

		if len(daemon.ActiveFlags()) > 0 {
			d, err := cntxt.Search()
			if err != nil {
				log.Fatalf("Unable send signal to the daemon: %s", err.Error())
			}
			daemon.SendCommands(d)
			return
		}

		d, err := cntxt.Reborn()
		if err != nil {
			log.Fatalln(err)
		}
		if d != nil {
			return
		}
		defer cntxt.Release()
	}

The program look likes running normally in background by daemon, but the pid file is created with empty content, then use -s stop flag to stop daemon, I got the error msg
Unable send signal to the daemon: EOF

Any idea? Please

@Masquerade0097
Copy link

Facing the same problem. Can you please have a look @sevlyar?

@wbtlb
Copy link

wbtlb commented May 24, 2021

Facing the same problem.

@deniszh
Copy link
Collaborator

deniszh commented May 24, 2021

Maybe related to #62
Will merge it and check.

@deniszh
Copy link
Collaborator

deniszh commented May 24, 2021

I tried signal-handling.go and I can't reproduce - for me it works fine, both on Linux and MacOS. If someone have clear steps to reproduce - please let me know.

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