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

flag redefined: log_dir #1

Open
cloudscode opened this issue Jan 9, 2017 · 2 comments
Open

flag redefined: log_dir #1

cloudscode opened this issue Jan 9, 2017 · 2 comments

Comments

@cloudscode
Copy link

flag redefined: log_dir

goroutine 1 [running]:
panic(0x739b40, 0xc420011480)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
flag.(*FlagSet).Var(0xc4200581e0, 0x955f40, 0xc420011430, 0x7bcc29, 0x7, 0x7cdea2, 0x2f)
/usr/local/go/src/flag/flag.go:791 +0x43e
flag.(*FlagSet).StringVar(0xc4200581e0, 0xc420011430, 0x7bcc29, 0x7, 0x0, 0x0, 0x7cdea2, 0x2f)
/usr/local/go/src/flag/flag.go:694 +0x8b
flag.(*FlagSet).String(0xc4200581e0, 0x7bcc29, 0x7, 0x0, 0x0, 0x7cdea2, 0x2f, 0xc420011420)
/usr/local/go/src/flag/flag.go:707 +0x90
flag.String(0x7bcc29, 0x7, 0x0, 0x0, 0x7cdea2, 0x2f, 0xc420049f28)
/usr/local/go/src/flag/flag.go:714 +0x69
github.com/golang/glog.init()
/root/goquery/src/github.com/golang/glog/glog_file.go:41 +0x148
github.com/zieckey/simgo.init()
/root/goquery/src/github.com/zieckey/simgo/module_monitor.go:73 +0x76
main.init()

[root@localhost dist]# go version
go version go1.7.1 linux/amd64

THx

@zieckey
Copy link
Owner

zieckey commented Jan 10, 2017

Please paste your code and the steps how to reproduce this issue. Thanks your feedback.

@cloudscode
Copy link
Author

[root@c2f13ffa8a58 dist]# cat idgenerator/logs/run.log 
/src/github.com/Qihoo360/poseidon/dist/idgenerator/bin/idgenerator flag redefined: log_dir
panic: /src/github.com/Qihoo360/poseidon/dist/idgenerator/bin/idgenerator flag redefined: log_dir

goroutine 1 [running]:
panic(0x73ab40, 0xc420013480)
	/var/java/go/src/runtime/panic.go:500 +0x1a1
flag.(*FlagSet).Var(0xc4200581e0, 0x956f80, 0xc420013430, 0x7bdd09, 0x7, 0x7cef6f, 0x2f)
	/var/java/go/src/flag/flag.go:791 +0x43e
flag.(*FlagSet).StringVar(0xc4200581e0, 0xc420013430, 0x7bdd09, 0x7, 0x0, 0x0, 0x7cef6f, 0x2f)
	/var/java/go/src/flag/flag.go:694 +0x8b
flag.(*FlagSet).String(0xc4200581e0, 0x7bdd09, 0x7, 0x0, 0x0, 0x7cef6f, 0x2f, 0xc420013420)
	/var/java/go/src/flag/flag.go:707 +0x90
flag.String(0x7bdd09, 0x7, 0x0, 0x0, 0x7cef6f, 0x2f, 0xc420049f28)
	/var/java/go/src/flag/flag.go:714 +0x69
github.com/golang/glog.init()
	/root/gofile/src/github.com/golang/glog/glog_file.go:41 +0x148
github.com/zieckey/simgo.init()
	/root/gofile/src/github.com/zieckey/simgo/module_monitor.go:73 +0x76
main.init()
	/src/github.com/Qihoo360/poseidon/service/idgenerator/main.go:41 +0x33
package main

import (
	idgen "github.com/Qihoo360/poseidon/service/idgenerator/module"
	"github.com/zieckey/simgo"
	"io/ioutil"
	"os"
	"path"
	"strconv"
)

//@todo pidfile configure
var pidfile string = "./pid"

func main() {
	os.Chdir(path.Dir(os.Args[0]))
	fw := simgo.DefaultFramework
	fw.RegisterModule("idgen_service", idgen.New())
	managePid(true, pidfile)
	err := fw.Initialize()
	if err != nil {
		panic(err.Error())
	}

	fw.Run()
}

//生成/删除当前进程id文件
func managePid(create bool, pidfile string) {
	if pidfile == "" {
		panic("pidfile is null, please configure it")
	}
	if create {
		pid := os.Getpid()
		pidString := strconv.Itoa(pid)
		ioutil.WriteFile(pidfile, []byte(pidString), 0777)
	} else {
		os.Remove(pidfile)
	}
}

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