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

Pidfile #57

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"os"
"os/exec"
"os/signal"
"os/user"
"path"
"path/filepath"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/facebookgo/pidfile"
"github.com/golang/glog"
bnet "github.com/livepeer/go-livepeer-basicnet"
"github.com/livepeer/go-livepeer/core"
Expand Down Expand Up @@ -101,19 +103,34 @@ func main() {
glog.Fatalf("Please provide rtmp port")
}

//Make sure datadir is present
if _, err := os.Stat(*datadir); os.IsNotExist(err) {
glog.Infof("Creating data dir: %v", *datadir)
if err = os.Mkdir(*datadir, 0755); err != nil {
glog.Errorf("Error creating datadir: %v", err)
}
}

//Set pidfile
if _, err = os.Stat(fmt.Sprintf("%v/livepeer.pid", *datadir)); !os.IsNotExist(err) {
glog.Errorf("Node already running with datadir: %v", *datadir)
return
}
pidfile.SetPidfilePath(fmt.Sprintf("%v/livepeer.pid", *datadir))
if err = pidfile.Write(); err != nil {
glog.Errorf("Error writing pidfile: %v", err)
return
}
defer os.Remove(fmt.Sprintf("%v/livepeer.pid", *datadir))

//Take care of priv/pub keypair
priv, pub, err := getLPKeys(*datadir)
if err != nil {
glog.Errorf("Error getting keys: %v", err)
return
}

//Create Livepeer Node
if *monitor {
lpmon.Endpoint = *monhost
}
Expand Down Expand Up @@ -206,6 +223,8 @@ func main() {
ec <- s.StartMediaServer(msCtx)
}()

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
select {
case err := <-ec:
glog.Infof("Error from media server: %v", err)
Expand All @@ -215,6 +234,8 @@ func main() {
glog.Infof("MediaServer Done()")
cancel()
return
case sig := <-c:
glog.Infof("Exiting Livepeer: %v", sig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cleanup or return statement necessary in the case of an os.Interrupt signal?

}
}

Expand Down