Skip to content

Commit

Permalink
Merge branch 'release/0.2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Jan 31, 2015
2 parents 3f02715 + 2e32035 commit e5fd25b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {

Real example:
```go
// Example of the daemon with echo service
// Example of a daemon with echo service
package main

import (
Expand All @@ -57,6 +57,8 @@ const (
port = ":9977"
)

var stdlog, errlog *log.Logger

// Service has embedded daemon
type Service struct {
daemon.Daemon
Expand Down Expand Up @@ -111,8 +113,8 @@ func (service *Service) Manage() (string, error) {
case conn := <-listen:
go handleClient(conn)
case killSignal := <-interrupt:
log.Println("Got signal:", killSignal)
log.Println("Stoping listening on ", listener.Addr())
stdlog.Println("Got signal:", killSignal)
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
Expand Down Expand Up @@ -147,20 +149,24 @@ func handleClient(client net.Conn) {
}
}

func init() {
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
}

func main() {
srv, err := daemon.New(name, description)
if err != nil {
fmt.Println("Error: ", err)
errlog.Println("Error: ", err)
os.Exit(1)
}
service := &Service{srv}
status, err := service.Manage()
if err != nil {
fmt.Println(status, "\nError: ", err)
errlog.Println(status, "\nError: ", err)
os.Exit(1)
}
fmt.Println(status)

}
```

Expand Down
19 changes: 13 additions & 6 deletions daemon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand All @@ -12,7 +12,7 @@ In the current implementation is only supported Linux and Mac Os X daemon.
Example:
//Example of the daemon with echo service
// Example of a daemon with echo service
package main
import (
Expand All @@ -36,6 +36,8 @@ Example:
port = ":9977"
)
var stdlog, errlog *log.Logger
// Service has embedded daemon
type Service struct {
daemon.Daemon
Expand Down Expand Up @@ -90,8 +92,8 @@ Example:
case conn := <-listen:
go handleClient(conn)
case killSignal := <-interrupt:
log.Println("Got signal:", killSignal)
log.Println("Stoping listening on ", listener.Addr())
stdlog.Println("Got signal:", killSignal)
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
Expand Down Expand Up @@ -126,16 +128,21 @@ Example:
}
}
func init() {
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
}
func main() {
srv, err := daemon.New(name, description)
if err != nil {
fmt.Println("Error: ", err)
errlog.Println("Error: ", err)
os.Exit(1)
}
service := &Service{srv}
status, err := service.Manage()
if err != nil {
fmt.Println(status, "\nError: ", err)
errlog.Println(status, "\nError: ", err)
os.Exit(1)
}
fmt.Println(status)
Expand Down
2 changes: 1 addition & 1 deletion daemon_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion daemon_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion daemon_linux_systemd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion daemon_linux_systemv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion daemon_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 Igor Dolzhikov. All rights reserved.
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.

Expand Down
15 changes: 11 additions & 4 deletions example/myservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
port = ":9977"
)

var stdlog, errlog *log.Logger

// Service has embedded daemon
type Service struct {
daemon.Daemon
Expand Down Expand Up @@ -76,8 +78,8 @@ func (service *Service) Manage() (string, error) {
case conn := <-listen:
go handleClient(conn)
case killSignal := <-interrupt:
log.Println("Got signal:", killSignal)
log.Println("Stoping listening on ", listener.Addr())
stdlog.Println("Got signal:", killSignal)
stdlog.Println("Stoping listening on ", listener.Addr())
listener.Close()
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
Expand Down Expand Up @@ -112,16 +114,21 @@ func handleClient(client net.Conn) {
}
}

func init() {
stdlog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
errlog = log.New(os.Stderr, "", log.Ldate|log.Ltime)
}

func main() {
srv, err := daemon.New(name, description)
if err != nil {
fmt.Println("Error: ", err)
errlog.Println("Error: ", err)
os.Exit(1)
}
service := &Service{srv}
status, err := service.Manage()
if err != nil {
fmt.Println(status, "\nError: ", err)
errlog.Println(status, "\nError: ", err)
os.Exit(1)
}
fmt.Println(status)
Expand Down

0 comments on commit e5fd25b

Please sign in to comment.