Commit 7e1d16cf by Bogdan Ungureanu

Fix Permision denied for daemon pid file

parent fe0ade8e
...@@ -85,7 +85,10 @@ func (d *Daemon) Run() error { ...@@ -85,7 +85,10 @@ func (d *Daemon) Run() error {
if d.startServer || d.restartServer { if d.startServer || d.restartServer {
if pid := d.getPid(); pid == 0 { if pid := d.getPid(); pid == 0 {
d.startProcess() err := d.startProcess()
if err != nil {
return err
}
os.Exit(0) os.Exit(0)
} }
return errors.New("Process allready running") return errors.New("Process allready running")
...@@ -111,7 +114,11 @@ func (d *Daemon) Run() error { ...@@ -111,7 +114,11 @@ func (d *Daemon) Run() error {
// Read pid from file , check if process is running // Read pid from file , check if process is running
func (d *Daemon) getPid() int { func (d *Daemon) getPid() int {
var pid int var pid int
f, err := os.Open(d.PidFile) f, err := os.OpenFile(
d.PidFile,
os.O_RDONLY,
0666,
)
if err != nil { if err != nil {
return 0 return 0
} }
...@@ -182,6 +189,17 @@ func (d *Daemon) startProcess() error { ...@@ -182,6 +189,17 @@ func (d *Daemon) startProcess() error {
procArgs := []string{} procArgs := []string{}
opt := "" opt := ""
// Test if we can create pid file
pidfile, err := os.OpenFile(
d.PidFile,
os.O_CREATE|os.O_RDWR,
0666,
)
if err != nil {
return err
}
pidfile.Close()
for _, arg := range d.args { for _, arg := range d.args {
if strings.HasPrefix(arg, "-") { if strings.HasPrefix(arg, "-") {
opt = arg opt = arg
...@@ -199,9 +217,10 @@ func (d *Daemon) startProcess() error { ...@@ -199,9 +217,10 @@ func (d *Daemon) startProcess() error {
Dir: procPath, Dir: procPath,
Env: env, Env: env,
Files: []*os.File{nil, nil, nil}, Files: []*os.File{nil, nil, nil},
//Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
} }
_, err := os.StartProcess(procName, procArgs, procAttr) _, err = os.StartProcess(procName, procArgs, procAttr)
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment