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

generates a blank pid file on Mac (Darwin) #25

Closed
Shashwatsh opened this issue Jun 25, 2017 · 3 comments
Closed

generates a blank pid file on Mac (Darwin) #25

Shashwatsh opened this issue Jun 25, 2017 · 3 comments

Comments

@Shashwatsh
Copy link

package main

import (
	"fmt"
	"github.com/sevlyar/go-daemon"
	"html"
	"log"
	"net/http"
	"os"
)

// To terminate the daemon use:
//  kill `cat pid`
func main()  {

	fmt.Println(os.Args[1])
	if os.Args[1] == "test" {
		test("hello,world")
	}
	if os.Args[1] == "hello" {
		serveHttp()
	}

}

func test(t string) {
	cntxt := &daemon.Context{
		PidFileName: "pid",
		PidFilePerm: 0644,
		LogFileName: "log",
		LogFilePerm: 0640,
		WorkDir:     "./test2/",
		Umask:       027,
		Args:        []string{"[go-daemon sample]", "hello"},
	}

	d, err := cntxt.Reborn()
	if err != nil {
		log.Fatal("Unable to run: ", err)
	}
	if d != nil {
		return
	}
	defer cntxt.Release()

	log.Print("- - - - - - - - - - - - - - -")
	log.Print("daemon started")

	log.Print(t)
}

func serveHttp() {

	log.Print("testing!")
	http.HandleFunc("/", httpHandler)
	http.ListenAndServe("127.0.0.1:3080", nil)
}

func httpHandler(w http.ResponseWriter, r *http.Request) {
	log.Printf("request from %s: %s %q", r.RemoteAddr, r.Method, r.URL)
	fmt.Fprintf(w, "go-daemon: %q", html.EscapeString(r.URL.Path))
}

it just saves a blank PID file...Nope..Nothing on it...No PIDs

@sevlyar
Copy link
Owner

sevlyar commented Jun 26, 2017

@Shashwatsh please provide an output of uname -a && go version && go env command.

@Shashwatsh
Copy link
Author

Darwin Shashwats-MacBook-Air.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
go version go1.8.3 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shashwat/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kg/fqkyc3h968s3dqd079_zhblm0000gn/T/go-build029181875=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

@sevlyar
Copy link
Owner

sevlyar commented Jun 26, 2017

Thank you, @Shashwatsh !
Duplicates #22

@sevlyar sevlyar closed this as completed Jun 26, 2017
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

2 participants