From e70590c5cc3e2fe52ad92f5c32dfe38a3e4ede66 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 19 Sep 2017 10:56:27 +0200 Subject: [PATCH 01/37] using go dep --- .gitignore | 1 + Gopkg.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ Gopkg.toml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml diff --git a/.gitignore b/.gitignore index eedba18..16b059d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ coverage.* .goxc.json build supervise +vendor diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..b3e6a2b --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,45 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "v2" + name = "github.com/go-yaml/yaml" + packages = ["."] + revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f" + +[[projects]] + name = "github.com/immortal/logrotate" + packages = ["."] + revision = "6f52ae74e103a0691e70ae31d82c0d99ab9ba973" + version = "0.3.0" + +[[projects]] + branch = "master" + name = "github.com/immortal/multiwriter" + packages = ["."] + revision = "2555774a03ac1d12b5bb4392858959ee50f78884" + +[[projects]] + name = "github.com/immortal/natcasesort" + packages = ["."] + revision = "162328b7d427d6f2d85a71ac77c175a53034229b" + version = "0.2.0" + +[[projects]] + branch = "master" + name = "github.com/immortal/xtime" + packages = ["."] + revision = "fb1aca1146ea82769e8433f5bb22f373765e7ecc" + +[[projects]] + name = "github.com/nbari/violetear" + packages = ["."] + revision = "13cb9a63c0cb68977810a7f38ced9f93178d5d62" + version = "3.1.2" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "cd775f8319d754c54df16d7240b4730fc7ab9c7fba703a4aaf59866bbe52ec55" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..7e3b3ae --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,46 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + branch = "v2" + name = "github.com/go-yaml/yaml" + +[[constraint]] + name = "github.com/immortal/logrotate" + version = "0.3.0" + +[[constraint]] + branch = "master" + name = "github.com/immortal/multiwriter" + +[[constraint]] + name = "github.com/immortal/natcasesort" + version = "0.2.0" + +[[constraint]] + branch = "master" + name = "github.com/immortal/xtime" + +[[constraint]] + name = "github.com/nbari/violetear" + version = "3.1.2" From dc6f779e13ae6fb716707503340e03f0af894cb3 Mon Sep 17 00:00:00 2001 From: Davor Kapsa Date: Sun, 1 Oct 2017 13:10:13 +0200 Subject: [PATCH 02/37] travis: update go versions --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f34cdb5..6c17675 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: go go: - - 1.9 - - 1.8 - - 1.7 + - 1.9.x + - 1.8.x + - 1.7.x - tip before_install: From 9a23cd6089eb96d20cde554590b0f8730f608bda Mon Sep 17 00:00:00 2001 From: nbari Date: Sun, 1 Oct 2017 13:45:52 +0200 Subject: [PATCH 03/37] travis os: osx --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6c17675..64005f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: go +os: + - linux + - osx + go: - 1.9.x - 1.8.x From 9f1ba246c75b13bbbe7a4cefbf166ccdf38fc1ad Mon Sep 17 00:00:00 2001 From: nbari Date: Sun, 1 Oct 2017 14:25:47 +0200 Subject: [PATCH 04/37] dep ensure -update --- Gopkg.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index b3e6a2b..8659885 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,8 +34,8 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "13cb9a63c0cb68977810a7f38ced9f93178d5d62" - version = "3.1.2" + revision = "875703ed7ae9b57e9a19cb18fff2ec362448a7d8" + version = "3.1.8" [solve-meta] analyzer-name = "dep" From 71f7d05fbc8dfcaa92c81c58814e867ea4e8596f Mon Sep 17 00:00:00 2001 From: nbari Date: Sun, 1 Oct 2017 19:51:35 +0200 Subject: [PATCH 05/37] update signals to use GetParam from violetear --- Gopkg.lock | 6 +++--- Gopkg.toml | 2 +- Makefile | 8 +------- signals.go | 3 +-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 8659885..ece6015 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,12 +34,12 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "875703ed7ae9b57e9a19cb18fff2ec362448a7d8" - version = "3.1.8" + revision = "f127f59047eecb0646ecd70ff0fbb52f6b37d0c4" + version = "4.0.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "cd775f8319d754c54df16d7240b4730fc7ab9c7fba703a4aaf59866bbe52ec55" + inputs-digest = "d96a9a626a35b249b34d494c3e6df0f1f3171581f1bd906650cd5f94e8bb215e" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 7e3b3ae..26470c2 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -43,4 +43,4 @@ [[constraint]] name = "github.com/nbari/violetear" - version = "3.1.2" + version = "4.0.0" diff --git a/Makefile b/Makefile index bb81bb5..e30bd6f 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,7 @@ DESTDIR ?= /usr/local all: clean build get: - ${GO} get - ${GO} get -u github.com/go-yaml/yaml; - ${GO} get -u github.com/nbari/violetear; - ${GO} get -u github.com/immortal/logrotate; - ${GO} get -u github.com/immortal/multiwriter; - ${GO} get -u github.com/immortal/natcasesort; - ${GO} get -u github.com/immortal/xtime; + dep ensure build: get ${GO} build -ldflags "-s -w -X main.version=${VERSION}" -o immortal cmd/immortal/main.go; diff --git a/signals.go b/signals.go index 5629d74..0c1a45f 100644 --- a/signals.go +++ b/signals.go @@ -20,8 +20,7 @@ func (d *Daemon) HandleSignal(w http.ResponseWriter, r *http.Request) { var err error // get signal from request params - params := r.Context().Value(violetear.ParamsKey).(violetear.Params) - signal := params["*"].(string) + signal := violetear.GetParam("*", r) switch signal { // a: Alarm. Send the service an ALRM signal. From 87f3cf9295d49d393a1aede7bd696e7a7e54107b Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 2 Oct 2017 09:32:32 +0200 Subject: [PATCH 06/37] modified: Makefile --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e30bd6f..bb81bb5 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,13 @@ DESTDIR ?= /usr/local all: clean build get: - dep ensure + ${GO} get + ${GO} get -u github.com/go-yaml/yaml; + ${GO} get -u github.com/nbari/violetear; + ${GO} get -u github.com/immortal/logrotate; + ${GO} get -u github.com/immortal/multiwriter; + ${GO} get -u github.com/immortal/natcasesort; + ${GO} get -u github.com/immortal/xtime; build: get ${GO} build -ldflags "-s -w -X main.version=${VERSION}" -o immortal cmd/immortal/main.go; From 18ba26a54554e7b3bc9f39850efb5a2bbf8b2102 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 2 Oct 2017 09:48:34 +0200 Subject: [PATCH 07/37] modify test to pass with tip in travis --- daemon_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon_test.go b/daemon_test.go index abeffe3..b49a5e8 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -298,7 +298,7 @@ func TestSignalsUDOT(t *testing.T) { if status, err = ctl.GetStatus(filepath.Join(sdir, "immortal.sock")); err != nil { t.Fatal(err) } - expect(t, "_test/immortal.test -test.run=TestHelperProcessSignalsUDOT --", status.Cmd) + expect(t, true, strings.HasSuffix(status.Cmd, "/immortal.test -test.run=TestHelperProcessSignalsUDOT --")) expect(t, 1, int(status.Count)) // http socket client From cf3e3d1d6f4ab6835736e2646fdf88310f875e60 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 2 Oct 2017 22:26:59 +0200 Subject: [PATCH 08/37] update dep --- Gopkg.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index ece6015..6411c92 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,8 +34,8 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "f127f59047eecb0646ecd70ff0fbb52f6b37d0c4" - version = "4.0.0" + revision = "a225aa95a4112a1745ce804d9edd50ad487d48bf" + version = "4.0.2" [solve-meta] analyzer-name = "dep" From a4843079769b64fc85be5bd77990b03a40d46029 Mon Sep 17 00:00:00 2001 From: nbari Date: Thu, 5 Oct 2017 21:47:32 +0200 Subject: [PATCH 09/37] update dep --- Gopkg.lock | 6 +++--- Gopkg.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 6411c92..d2f7158 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,12 +34,12 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "a225aa95a4112a1745ce804d9edd50ad487d48bf" - version = "4.0.2" + revision = "72cf83a095fe6dcd7bc4bc16d0aac49696b8c614" + version = "4.1.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d96a9a626a35b249b34d494c3e6df0f1f3171581f1bd906650cd5f94e8bb215e" + inputs-digest = "12cbf78a7a54ecab16ccfad41821782ff4d59a9d9cf8d7891ce0f227e93068c7" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 26470c2..7e814b8 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -43,4 +43,4 @@ [[constraint]] name = "github.com/nbari/violetear" - version = "4.0.0" + version = "4.1.0" From cbff3e11bf7852cfd4f08e3ba9094aae13ee95f9 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 10 Oct 2017 12:30:39 +0200 Subject: [PATCH 10/37] test --- signals_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/signals_test.go b/signals_test.go index e49f69e..6b87dd4 100644 --- a/signals_test.go +++ b/signals_test.go @@ -239,6 +239,7 @@ func waitSig(t *testing.T, fifo *os.File, sig string) { buf = buf[:n] msg := strings.TrimSpace(string(buf)) if msg != sig { + t.Log(msg, sig) expect(t, sig, msg) } return From 86af49a9e88eca1fbcfef84e47416dfb522aa451 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 10 Oct 2017 12:47:32 +0200 Subject: [PATCH 11/37] dep ensure in travis --- .travis.yml | 1 + Gopkg.lock | 6 +++--- Gopkg.toml | 2 +- signals_test.go | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64005f4..861fb82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ before_install: - go get github.com/mattn/goveralls - go get github.com/nbari/violetear - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi + - dep ensure script: - go test -v -covermode=count -coverprofile=coverage.out diff --git a/Gopkg.lock b/Gopkg.lock index d2f7158..ffcb6f4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,12 +34,12 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "72cf83a095fe6dcd7bc4bc16d0aac49696b8c614" - version = "4.1.0" + revision = "128bb205fd36e62abecc955ea6fde72c58e90708" + version = "4.1.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "12cbf78a7a54ecab16ccfad41821782ff4d59a9d9cf8d7891ce0f227e93068c7" + inputs-digest = "487bf31d74bc680c58d37bafb737804cb7a4334c4abb1c13c59403d16f897fd1" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 7e814b8..e9e26d0 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -43,4 +43,4 @@ [[constraint]] name = "github.com/nbari/violetear" - version = "4.1.0" + version = "4.1.1" diff --git a/signals_test.go b/signals_test.go index 6b87dd4..e49f69e 100644 --- a/signals_test.go +++ b/signals_test.go @@ -239,7 +239,6 @@ func waitSig(t *testing.T, fifo *os.File, sig string) { buf = buf[:n] msg := strings.TrimSpace(string(buf)) if msg != sig { - t.Log(msg, sig) expect(t, sig, msg) } return From 2c81c5711aaa92cb220aa299556dd5ed6ca73fba Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 10 Oct 2017 12:52:48 +0200 Subject: [PATCH 12/37] master instead of tip --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 861fb82..b2602c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ go: - 1.9.x - 1.8.x - 1.7.x - - tip + - master before_install: - go get github.com/axw/gocov/gocov @@ -20,7 +20,6 @@ before_install: - go get github.com/mattn/goveralls - go get github.com/nbari/violetear - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi - - dep ensure script: - go test -v -covermode=count -coverprofile=coverage.out From a5616833f1171f709db7e7f2fc9bade3e9f9b6b0 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 10 Oct 2017 14:26:00 +0200 Subject: [PATCH 13/37] .travis go get dep --- .travis.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2602c7..d32f352 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,15 +12,13 @@ go: before_install: - go get github.com/axw/gocov/gocov - - go get github.com/go-yaml/yaml - - go get github.com/immortal/logrotate - - go get github.com/immortal/multiwriter - - go get github.com/immortal/natcasesort - - go get github.com/immortal/xtime - go get github.com/mattn/goveralls - - go get github.com/nbari/violetear - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi +install: + - go get -u github.com/golang/dep/... + - dep ensure + script: - go test -v -covermode=count -coverprofile=coverage.out - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci From 16d365e70fe5f3e4f6ea016c8733b1018c996961 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 10 Oct 2017 14:31:41 +0200 Subject: [PATCH 14/37] get dep not working in 1.7 --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d32f352..b2602c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,13 +12,15 @@ go: before_install: - go get github.com/axw/gocov/gocov + - go get github.com/go-yaml/yaml + - go get github.com/immortal/logrotate + - go get github.com/immortal/multiwriter + - go get github.com/immortal/natcasesort + - go get github.com/immortal/xtime - go get github.com/mattn/goveralls + - go get github.com/nbari/violetear - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi -install: - - go get -u github.com/golang/dep/... - - dep ensure - script: - go test -v -covermode=count -coverprofile=coverage.out - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci From 8ff93ae501abc1d740d66e9d341a92b326ad5d4e Mon Sep 17 00:00:00 2001 From: nbari Date: Wed, 11 Oct 2017 18:43:03 +0200 Subject: [PATCH 15/37] sync --- fifo.go | 30 ------------------------------ fifo_test.go | 42 ------------------------------------------ signals_test.go | 2 ++ 3 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 fifo.go delete mode 100644 fifo_test.go diff --git a/fifo.go b/fifo.go deleted file mode 100644 index d0cfe72..0000000 --- a/fifo.go +++ /dev/null @@ -1,30 +0,0 @@ -package immortal - -import ( - "os" - "path/filepath" - "syscall" -) - -// MakeFifo creates a fifo file -func MakeFifo(path string) error { - err := os.MkdirAll(filepath.Dir(path), os.ModePerm) - if err != nil { - return err - } - err = syscall.Mknod(path, syscall.S_IFIFO|0666, 0) - // ignore "file exists" errors and assume the FIFO was pre-made - if err != nil && !os.IsExist(err) { - return err - } - return nil -} - -// OpenFifo open fifo and returns its file descriptor -func OpenFifo(path string) (*os.File, error) { - f, err := os.OpenFile(path, os.O_RDWR, os.ModeNamedPipe) - if err != nil { - return nil, err - } - return f, nil -} diff --git a/fifo_test.go b/fifo_test.go deleted file mode 100644 index 9c8e338..0000000 --- a/fifo_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package immortal - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestMakeFIFOError(t *testing.T) { - err := MakeFifo("/dev/null/pipe") - if err == nil { - t.Error("Expecting error") - } -} - -func TestMakeFIFO(t *testing.T) { - dir, err := ioutil.TempDir("", "TestMakeFIFO") - if err != nil { - t.Error(err) - } - defer os.RemoveAll(dir) - fifo := filepath.Join(dir, "pipe") - err = MakeFifo(fifo) - if err != nil { - t.Error(err) - } - f, err := OpenFifo(fifo) - if err != nil { - f.Close() - t.Error(err) - } - os.Chmod(dir, 0000) - err = MakeFifo(fifo) - if err == nil { - t.Error("Expecting error") - } - f, err = OpenFifo(fifo) - if err == nil { - t.Error("Expecting error") - } -} diff --git a/signals_test.go b/signals_test.go index e49f69e..763a09a 100644 --- a/signals_test.go +++ b/signals_test.go @@ -17,6 +17,8 @@ import ( "time" ) +var testSignals = make(chan string) + func TestHelperProcessSignalsFiFo(*testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { return From b57120f008eb66de34a18113fa1a1728b99473b0 Mon Sep 17 00:00:00 2001 From: nbari Date: Wed, 11 Oct 2017 20:33:28 +0200 Subject: [PATCH 16/37] named pipes for testing signals --- signals_test.go | 51 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/signals_test.go b/signals_test.go index 763a09a..0d44cec 100644 --- a/signals_test.go +++ b/signals_test.go @@ -17,7 +17,28 @@ import ( "time" ) -var testSignals = make(chan string) +// MakeFifo creates a fifo file +func MakeFifo(path string) error { + err := os.MkdirAll(filepath.Dir(path), os.ModePerm) + if err != nil { + return err + } + err = syscall.Mknod(path, syscall.S_IFIFO|0666, 0) + // ignore "file exists" errors and assume the FIFO was pre-made + if err != nil && !os.IsExist(err) { + return err + } + return nil +} + +// OpenFifo open fifo and returns its file descriptor +func OpenFifo(path string) (*os.File, error) { + f, err := os.OpenFile(path, os.O_RDWR, os.ModeNamedPipe) + if err != nil { + return nil, err + } + return f, nil +} func TestHelperProcessSignalsFiFo(*testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { @@ -177,12 +198,14 @@ func TestSignalsFiFo(t *testing.T) { } res := &Response{} - for _, s := range testSignals { - if err := GetJSON(filepath.Join(sdir, "immortal.sock"), fmt.Sprintf("/signal/%s", s.signal), res); err != nil { - t.Fatal(err) - } - expect(t, "", res.Err) - waitSig(t, fifo, s.expected) + for _, tc := range testSignals { + t.Run(tc.signal, func(t *testing.T) { + if err := GetJSON(filepath.Join(sdir, "immortal.sock"), fmt.Sprintf("/signal/%s", tc.signal), res); err != nil { + t.Fatal(err) + } + expect(t, "", res.Err) + waitSig(t, fifo, tc.expected) + }) } // test "d", (keep it down and don't restart) @@ -196,12 +219,14 @@ func TestSignalsFiFo(t *testing.T) { // create error os: process already finished mylog.Reset() - for _, s := range testSignals { - if err := GetJSON(filepath.Join(sdir, "immortal.sock"), fmt.Sprintf("/signal/%s", s.signal), res); err != nil { - t.Fatal(err) - } - expect(t, true, strings.HasSuffix(strings.TrimSpace(mylog.String()), "no such process")) - mylog.Reset() + for _, tc := range testSignals { + t.Run(tc.signal, func(t *testing.T) { + if err := GetJSON(filepath.Join(sdir, "immortal.sock"), fmt.Sprintf("/signal/%s", tc.signal), res); err != nil { + t.Fatal(err) + } + expect(t, true, strings.HasSuffix(strings.TrimSpace(mylog.String()), "no such process")) + mylog.Reset() + }) } if err := GetJSON(filepath.Join(sdir, "immortal.sock"), "/signal/d", res); err != nil { From 2bf35888ff9f52eacf594fc167089954d75112d9 Mon Sep 17 00:00:00 2001 From: Marko Turk Date: Sat, 14 Oct 2017 14:31:37 +0200 Subject: [PATCH 17/37] Print cmd name (not just PID) in the log when the process terminates --- supervise.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/supervise.go b/supervise.go index 38fe608..1ae12db 100644 --- a/supervise.go +++ b/supervise.go @@ -52,10 +52,11 @@ func Supervise(d *Daemon) { // unlock, or lock once atomic.StoreUint32(&d.lock, d.lockOnce) if err != nil && err.Error() == "EXIT" { - log.Printf("PID: %d Exited", pid) + log.Printf("PID: %d (%s) Exited", pid, p.cmd.Path) } else { - log.Printf("PID %d terminated, %s [%v user %v sys %s up]\n", + log.Printf("PID %d (%s) terminated, %s [%v user %v sys %s up]\n", p.cmd.ProcessState.Pid(), + p.cmd.Path, p.cmd.ProcessState, p.cmd.ProcessState.UserTime(), p.cmd.ProcessState.SystemTime(), From c40625f19501650017ad44c8fc7553acf84d3faf Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 27 Oct 2017 17:45:52 +0200 Subject: [PATCH 18/37] update dep --- Gopkg.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index ffcb6f4..312ea96 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,8 +34,8 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "128bb205fd36e62abecc955ea6fde72c58e90708" - version = "4.1.1" + revision = "8d442e7abd7c93f57504fbda57fd564d4f72283f" + version = "4.1.2" [solve-meta] analyzer-name = "dep" From 378f42fcbf1b9e8ef3842b99a68ecdc8ffde8cec Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 15:12:48 +0100 Subject: [PATCH 19/37] golint --- .travis.yml | 2 -- ctl.go | 4 ++-- daemon.go | 7 ++----- parser.go | 12 ++++++------ scandir.go | 2 +- signals.go | 2 +- signals_test.go | 2 +- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2602c7..3b8c563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,6 @@ os: go: - 1.9.x - - 1.8.x - - 1.7.x - master before_install: diff --git a/ctl.go b/ctl.go index 4bf1982..68b147e 100644 --- a/ctl.go +++ b/ctl.go @@ -87,12 +87,12 @@ func (c *Controller) PurgeServices(dir string) error { continue } if f.IsDir() { - return fmt.Errorf("Could not purge dir: %s", dir) + return fmt.Errorf("could not purge dir: %s", dir) } } return os.RemoveAll(filepath.Dir(dir)) } - return fmt.Errorf("Could not purge dir: %s", dir) + return fmt.Errorf("could not purge dir: %s", dir) } // Run executes a command and print combinedOutput diff --git a/daemon.go b/daemon.go index 35956bd..1890c1a 100644 --- a/daemon.go +++ b/daemon.go @@ -31,7 +31,7 @@ func (d *Daemon) Run(p Process) (*process, error) { // return if process is running if atomic.SwapUint32(&d.lock, uint32(1)) != 0 { - return nil, fmt.Errorf("Cannot start, process still running") + return nil, fmt.Errorf("cannot start, process still running") } // increment count by 1 @@ -66,10 +66,7 @@ func (d *Daemon) Run(p Process) (*process, error) { // WritePid write pid to file func (d *Daemon) WritePid(file string, pid int) error { - if err := ioutil.WriteFile(file, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil { - return err - } - return nil + return ioutil.WriteFile(file, []byte(fmt.Sprintf("%d", pid)), 0644) } // IsRunning check if process is running diff --git a/parser.go b/parser.go index e25dd00..86d5952 100644 --- a/parser.go +++ b/parser.go @@ -59,7 +59,7 @@ func (p *Parse) parseYml(file string) (*Config, error) { } var cfg Config if err := yaml.Unmarshal(f, &cfg); err != nil { - return nil, fmt.Errorf("Unable to parse YAML file %q %s", file, err) + return nil, fmt.Errorf("unable to parse YAML file %q %s", file, err) } return &cfg, nil } @@ -106,9 +106,9 @@ func (p *Parse) checkUser(u string) (*user.User, error) { usr, err := p.UserLookup(u) if err != nil { if _, ok := err.(user.UnknownUserError); ok { - return nil, fmt.Errorf("User %q does not exist.", u) + return nil, fmt.Errorf("user %q does not exist", u) } - return nil, fmt.Errorf("Error looking up user: %q. %s", u, err) + return nil, fmt.Errorf("error looking up user: %q. %s", u, err) } return usr, nil } @@ -165,7 +165,7 @@ func ParseArgs(p Parser, fs *flag.FlagSet) (cfg *Config, err error) { // if -c if flags.Configfile != "" { if !isFile(flags.Configfile) { - err = fmt.Errorf("Cannot read file: %q, use (\"%s -h\") for help.", flags.Configfile, os.Args[0]) + err = fmt.Errorf("cannot read file: %q, use (\"%s -h\") for help", flags.Configfile, os.Args[0]) return } cfg, err = p.parseYml(flags.Configfile) @@ -173,7 +173,7 @@ func ParseArgs(p Parser, fs *flag.FlagSet) (cfg *Config, err error) { return } if cfg.Cmd == "" { - err = fmt.Errorf("Missing command, use (\"%s -h\") for help.", os.Args[0]) + err = fmt.Errorf("missing command, use (\"%s -h\") for help", os.Args[0]) return } cfg.command = strings.Fields(cfg.Cmd) @@ -193,7 +193,7 @@ func ParseArgs(p Parser, fs *flag.FlagSet) (cfg *Config, err error) { // if no args if len(fs.Args()) < 1 { - err = fmt.Errorf("Missing command, use (\"%s -h\") for help.", os.Args[0]) + err = fmt.Errorf("missing command, use (\"%s -h\") for help", os.Args[0]) return } diff --git a/scandir.go b/scandir.go index e1cdae2..d084fa3 100644 --- a/scandir.go +++ b/scandir.go @@ -156,7 +156,7 @@ func (s *ScanDir) Scandir(ctl Control) error { name := strings.TrimSuffix(f.Name(), filepath.Ext(f.Name())) md5, err := md5sum(path) if err != nil { - return fmt.Errorf("Error getting the md5sum: %s", err) + return fmt.Errorf("error getting the md5sum: %s", err) } // start or restart if service is not in map or file lock don't exists if _, ok := s.services[name]; !ok || !isFile(filepath.Join(s.sdir, name, "lock")) { diff --git a/signals.go b/signals.go index 0c1a45f..811e5a2 100644 --- a/signals.go +++ b/signals.go @@ -112,7 +112,7 @@ func (d *Daemon) HandleSignal(w http.ResponseWriter, r *http.Request) { close(d.quit) default: - err = fmt.Errorf("Unknown signal: %s", signal) + err = fmt.Errorf("unknown signal: %s", signal) } res := &SignalResponse{} diff --git a/signals_test.go b/signals_test.go index 0d44cec..5ba7f01 100644 --- a/signals_test.go +++ b/signals_test.go @@ -242,7 +242,7 @@ func TestSignalsFiFo(t *testing.T) { if err := GetJSON(filepath.Join(sdir, "immortal.sock"), "/signal/unknown", res); err != nil { t.Fatal(err) } - expect(t, "Unknown signal: unknown", res.Err) + expect(t, "unknown signal: unknown", res.Err) if err := GetJSON(filepath.Join(sdir, "immortal.sock"), "/signal/halt", res); err != nil { t.Fatal(err) From bb161857d3ed9ca2c1f1a875226cd64d486f2707 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 18:14:54 +0100 Subject: [PATCH 20/37] test lock --- daemon.go | 2 +- daemon_test.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/daemon.go b/daemon.go index 1890c1a..d028862 100644 --- a/daemon.go +++ b/daemon.go @@ -132,7 +132,7 @@ func New(cfg *Config) (*Daemon, error) { cfg: cfg, supDir: supDir, quit: make(chan struct{}), - run: make(chan struct{}, 1), + run: make(chan struct{}), sTime: time.Now(), }, nil } diff --git a/daemon_test.go b/daemon_test.go index b49a5e8..1534b69 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -346,10 +346,12 @@ func TestSignalsUDOT(t *testing.T) { // test "u" t.Log("testing up") - if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "up"); err != nil { - t.Fatal(err) - } - <-d.run + go func() { + if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "up"); err != nil { + t.Fatal(err) + } + <-d.run + }() p, err = d.Run(NewProcess(cfg)) if err != nil { t.Error(err) @@ -360,6 +362,9 @@ func TestSignalsUDOT(t *testing.T) { if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "o"); err != nil { t.Fatal(err) } + + // TODO check lock + if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "k"); err != nil { t.Fatal(err) } From 679e32c6cad47ead3a7ad08fe736622a43213155 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 20:49:36 +0100 Subject: [PATCH 21/37] clean supervisor --- supervise.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/supervise.go b/supervise.go index 1ae12db..329e545 100644 --- a/supervise.go +++ b/supervise.go @@ -32,8 +32,6 @@ func Supervise(d *Daemon) { select { case <-d.quit: return - case <-info: - d.Info() case <-d.run: time.Sleep(wait) // create a new process @@ -46,6 +44,8 @@ func Supervise(d *Daemon) { d.run <- struct{}{} } } + case <-info: + d.Info() case err := <-p.errch: // set end time p.eTime = time.Now() @@ -69,8 +69,7 @@ func Supervise(d *Daemon) { wait = time.Second - uptime } } - // follow the new pid and stop running the command - // unless the new pid dies + // follow the new pid instead of trying to call run again unless the new pid dies if d.cfg.Pid.Follow != "" { pid, err = d.ReadPidFile(d.cfg.Pid.Follow) if err != nil { @@ -90,6 +89,7 @@ func Supervise(d *Daemon) { } } } else { + // run again d.run <- struct{}{} } } From fcc0b9196cf9e1b802c5ee3faa4615143121581a Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 22:34:33 +0100 Subject: [PATCH 22/37] clean up tests --- daemon.go | 2 +- daemon_test.go | 12 ++++++------ supervise_test.go | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/daemon.go b/daemon.go index d028862..1890c1a 100644 --- a/daemon.go +++ b/daemon.go @@ -132,7 +132,7 @@ func New(cfg *Config) (*Daemon, error) { cfg: cfg, supDir: supDir, quit: make(chan struct{}), - run: make(chan struct{}), + run: make(chan struct{}, 1), sTime: time.Now(), }, nil } diff --git a/daemon_test.go b/daemon_test.go index 1534b69..40e753e 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -350,8 +350,8 @@ func TestSignalsUDOT(t *testing.T) { if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "up"); err != nil { t.Fatal(err) } - <-d.run }() + <-d.run p, err = d.Run(NewProcess(cfg)) if err != nil { t.Error(err) @@ -363,8 +363,6 @@ func TestSignalsUDOT(t *testing.T) { t.Fatal(err) } - // TODO check lock - if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "k"); err != nil { t.Fatal(err) } @@ -387,9 +385,11 @@ func TestSignalsUDOT(t *testing.T) { // test "u" t.Log("testing u") - if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "u"); err != nil { - t.Fatal(err) - } + go func() { + if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "u"); err != nil { + t.Fatal(err) + } + }() <-d.run p, err = d.Run(NewProcess(cfg)) if err != nil { diff --git a/supervise_test.go b/supervise_test.go index 6fe6575..6cbcefa 100644 --- a/supervise_test.go +++ b/supervise_test.go @@ -18,7 +18,7 @@ func TestHelperProcessSupervise(*testing.T) { if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { return } - c := make(chan os.Signal, 1) + c := make(chan os.Signal) signal.Notify(c, os.Interrupt, os.Kill) select { case <-c: @@ -36,7 +36,7 @@ func TestHelperProcessSupervise2(*testing.T) { } func TestSupervise(t *testing.T) { - sdir, err := ioutil.TempDir("", "TestDaemonNewCtlErr") + sdir, err := ioutil.TempDir("", "TestSupervise") if err != nil { t.Error(err) } @@ -139,8 +139,10 @@ func TestSupervise(t *testing.T) { } } +// TestSuperviseWait will test that the wait variable in supervise.go is set to +// approximately 1 second (wait = time.Second - uptime) to avoid high CPU usage func TestSuperviseWait(t *testing.T) { - sdir, err := ioutil.TempDir("", "TestDaemonNewCtlErr") + sdir, err := ioutil.TempDir("", "TestSuperviseWait") if err != nil { t.Error(err) } From 02ec3f613635af4acd693568a1257610b006e655 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 23:44:26 +0100 Subject: [PATCH 23/37] CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..264e99a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## 0.17.0 Unreleased + +* Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) +* Cleaned tests From 0bf0c8bd4c0640105083cf76863c928f21c07ac0 Mon Sep 17 00:00:00 2001 From: nbari Date: Mon, 30 Oct 2017 23:49:52 +0100 Subject: [PATCH 24/37] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 264e99a..5aacd17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## 0.17.0 Unreleased -* Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) * Cleaned tests +* Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) +* Updated HandleSignal to use `GetParam` from violetear From 830bfd58b1daa3a5d330909403ca5ba484fe2c3c Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 31 Oct 2017 11:16:54 +0100 Subject: [PATCH 25/37] golint --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aacd17..2d4c286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.17.0 Unreleased * Cleaned tests +* Improved lint * Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) * Updated HandleSignal to use `GetParam` from violetear From 13a36a7c5b44b27a0ecfe08bf3fac76697f50a37 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 31 Oct 2017 18:42:56 +0100 Subject: [PATCH 26/37] test sync map --- scandir.go | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/scandir.go b/scandir.go index d084fa3..497e4af 100644 --- a/scandir.go +++ b/scandir.go @@ -17,9 +17,8 @@ import ( type ScanDir struct { scandir string sdir string - services map[string]string + services sync.Map watch chan string - sync.Mutex } // NewScanDir returns ScanDir struct @@ -48,10 +47,9 @@ func NewScanDir(path string) (*ScanDir, error) { defer d.Close() return &ScanDir{ - scandir: dir, - sdir: GetSdir(), - services: map[string]string{}, - watch: make(chan string, 1), + scandir: dir, + sdir: GetSdir(), + watch: make(chan string, 1), }, nil } @@ -97,20 +95,19 @@ func (s *ScanDir) Start(ctl Control) { if err != nil { log.Fatalf("Error getting the md5sum: %s", err) } - s.Lock() // restart if file changed - if md5 != s.services[serviceName] { - s.services[serviceName] = md5 + hash, _ := s.services.Load(serviceName) + if md5 != hash { + s.services.Store(serviceName, md5) log.Printf("Stopping: %s\n", serviceName) ctl.SendSignal(filepath.Join(s.sdir, serviceName, "immortal.sock"), "halt") } - s.Unlock() log.Printf("Starting: %s\n", serviceName) // try to start before via socket if _, err := ctl.SendSignal(filepath.Join(s.sdir, serviceName, "immortal.sock"), "start"); err != nil { if out, err := ctl.Run(fmt.Sprintf("immortal -c %s -ctl %s", watch, serviceName)); err != nil { // keep retrying - delete(s.services, serviceName) + s.services.Delete(serviceName) log.Println(err) } else { log.Printf("%s\n", out) @@ -132,9 +129,7 @@ func (s *ScanDir) Start(ctl Control) { }() } else { // remove service - s.Lock() - delete(s.services, serviceName) - s.Unlock() + s.services.Delete(serviceName) ctl.SendSignal(filepath.Join(s.sdir, serviceName, "immortal.sock"), "halt") log.Printf("Exiting: %s\n", serviceName) } @@ -145,8 +140,6 @@ func (s *ScanDir) Start(ctl Control) { // Scandir searches for *.yml if file changes it will reload(stop-start) func (s *ScanDir) Scandir(ctl Control) error { - s.Lock() - defer s.Unlock() find := func(path string, f os.FileInfo, err error) error { if err != nil { return err @@ -159,8 +152,8 @@ func (s *ScanDir) Scandir(ctl Control) error { return fmt.Errorf("error getting the md5sum: %s", err) } // start or restart if service is not in map or file lock don't exists - if _, ok := s.services[name]; !ok || !isFile(filepath.Join(s.sdir, name, "lock")) { - s.services[name] = md5 + if _, ok := s.services.Load(name); !ok || !isFile(filepath.Join(s.sdir, name, "lock")) { + s.services.Store(name, md5) log.Printf("Starting: %s\n", name) if out, err := ctl.Run(fmt.Sprintf("immortal -c %s -ctl %s", path, name)); err != nil { log.Println(err) From 066f0c812fac5133373b46ff8768d46fde97a30b Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 31 Oct 2017 19:20:20 +0100 Subject: [PATCH 27/37] sync.map --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d4c286..4266b2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,4 +3,5 @@ * Cleaned tests * Improved lint * Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) +* Replaced lock/map with sync.Map in scandir.go * Updated HandleSignal to use `GetParam` from violetear From cf3aad8324d89f3bdacb36e782729b5955231fa1 Mon Sep 17 00:00:00 2001 From: nbari Date: Tue, 31 Oct 2017 19:39:21 +0100 Subject: [PATCH 28/37] commented code --- scandir.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scandir.go b/scandir.go index 497e4af..425e97c 100644 --- a/scandir.go +++ b/scandir.go @@ -70,6 +70,8 @@ func (s *ScanDir) Start(ctl Control) { // check for new services on scandir go WatchDir(s.scandir, s.watch) + + // start with scandir s.watch <- s.scandir for { From 136a46e092c39cd84254fd269cedfff526a61ef0 Mon Sep 17 00:00:00 2001 From: nbari Date: Thu, 2 Nov 2017 10:10:24 +0100 Subject: [PATCH 29/37] contributing --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++ CONTRIBUTING.md | 76 ++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 CONTRIBUTING.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..991c14e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,3 @@ +- [ ] Have you test the code? +- [ ] Have you check that the existing tests are passing? +- [ ] The destination branch is **develop**? diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ca284cc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,76 @@ +# Contributing to immortal + +First and foremost, thank you! We appreciate that you want to contribute to +immortal, your time is valuable, and your contributions mean a lot to us. + +## Important! + +By contributing to this project, you: + +* Agree that you have authored 100% of the content +* Agree that you have the necessary rights to the content +* Agree that you have received the necessary permissions from your employer to make the contributions (if applicable) +* Agree that the content you contribute may be provided under the Project license(s) + +## Getting started + +**What does "contributing" mean?** + +Creating an issue is the simplest form of contributing to a project. But there +are many ways to contribute, including the following: + +- Updating or correcting documentation +- Feature requests +- Bug reports + +**Showing support for immortal** + +Please keep in mind that open source software is built by people like you, who +spend their free time creating things the rest the community can use. + +Don't have time to contribute? No worries, here are some other ways to show your +support for immortal: + +- star the [project](https://github.com/immortal/immortal) +- tweet your support for immortal + +## Issues + +### Before creating an issue + +Please try to determine if the issue is caused by an underlying library, and if +so, create the issue there. Sometimes this is difficult to know. We only ask +that you attempt to give a reasonable attempt to find out. Oftentimes the readme +will have advice about where to go to create issues. + +Try to follow these guidelines + +- **Avoid creating issues for implementation help**. It's much better for discoverability, SEO, and semantics - to keep the issue tracker focused on bugs and feature requests - to ask implementation-related questions on [stackoverflow.com][so] +- **Investigate the issue**: +- **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. +- Create the issue in the appropriate repository. + +### Creating an issue + +Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: + +- **version**: please note the version of immortal are you using +- **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using +- **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) + +### Closing issues + +The original poster or the maintainer's of immortal may close an issue at any time. Typically, but not exclusively, issues are closed when: + +- The issue is resolved +- The project's maintainers have determined the issue is out of scope +- An issue is clearly a duplicate of another issue, in which case the duplicate issue will be linked. +- A discussion has clearly run its course + + +## Pull Request Process + +- Make sure the destination branch is **develop**, We are using git-flow. + + +[so]: http://stackoverflow.com/questions/tagged/immortal From 9888211a1f68aa690549dc61b91ea6315a577d00 Mon Sep 17 00:00:00 2001 From: nbari Date: Thu, 2 Nov 2017 10:47:35 +0100 Subject: [PATCH 30/37] udpate dep --- Gopkg.lock | 6 +++--- Gopkg.toml | 25 +------------------------ 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 312ea96..569b082 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,12 +34,12 @@ [[projects]] name = "github.com/nbari/violetear" packages = ["."] - revision = "8d442e7abd7c93f57504fbda57fd564d4f72283f" - version = "4.1.2" + revision = "f7bc38ce29e218ffc860294acabef409ace48ad3" + version = "4.1.3" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "487bf31d74bc680c58d37bafb737804cb7a4334c4abb1c13c59403d16f897fd1" + inputs-digest = "7f12c59f30422446fb3ecec367b323fe37b1e0ec81be4cc26f188ba9ad64d3f1" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index e9e26d0..56a97e3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,26 +1,3 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - [[constraint]] branch = "v2" name = "github.com/go-yaml/yaml" @@ -43,4 +20,4 @@ [[constraint]] name = "github.com/nbari/violetear" - version = "4.1.1" + version = "4.1.3" From aa87e689c3243baabe22d6fa12066c535ec4a7fa Mon Sep 17 00:00:00 2001 From: nbari Date: Thu, 2 Nov 2017 12:30:04 +0100 Subject: [PATCH 31/37] removed info.go --- CHANGELOG.md | 1 + info.go | 39 --------------------------------------- supervise.go | 9 --------- supervise_test.go | 5 ----- 4 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 info.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 4266b2c..768c9a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,5 +3,6 @@ * Cleaned tests * Improved lint * Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) +* Removed info.go (signal.Notify) from supervise.go * Replaced lock/map with sync.Map in scandir.go * Updated HandleSignal to use `GetParam` from violetear diff --git a/info.go b/info.go deleted file mode 100644 index 562b27d..0000000 --- a/info.go +++ /dev/null @@ -1,39 +0,0 @@ -package immortal - -import ( - "log" - "os" - "runtime" - "time" -) - -// Info log current daemon status after receiving a QUIT signal "kill -3 PID" -func (d *Daemon) Info() { - var m runtime.MemStats - runtime.ReadMemStats(&m) - status := `PID: %d -Gorutines: %d -Alloc : %d -Total Alloc: %d -Sys: %d -Lookups: %d -Mallocs: %d -Frees: %d -Seconds in GC: %d -Started on: %v -Uptime: %v -Process count: %d` - log.Printf(status, - os.Getpid(), - runtime.NumGoroutine(), - m.Alloc, - m.TotalAlloc, - m.Sys, - m.Lookups, - m.Mallocs, - m.Frees, - m.PauseTotalNs/1000000000, - d.sTime.Format(time.RFC3339), - time.Since(d.sTime), - d.count) -} diff --git a/supervise.go b/supervise.go index 329e545..ae08131 100644 --- a/supervise.go +++ b/supervise.go @@ -2,10 +2,7 @@ package immortal import ( "log" - "os" - "os/signal" "sync/atomic" - "syscall" "time" ) @@ -13,7 +10,6 @@ import ( func Supervise(d *Daemon) { var ( err error - info = make(chan os.Signal) p *process pid int wait time.Duration @@ -25,9 +21,6 @@ func Supervise(d *Daemon) { log.Fatal(err) } - // Info loop, kill -3 PPID get stats - signal.Notify(info, syscall.SIGQUIT) - for { select { case <-d.quit: @@ -44,8 +37,6 @@ func Supervise(d *Daemon) { d.run <- struct{}{} } } - case <-info: - d.Info() case err := <-p.errch: // set end time p.eTime = time.Now() diff --git a/supervise_test.go b/supervise_test.go index 6cbcefa..ca769e1 100644 --- a/supervise_test.go +++ b/supervise_test.go @@ -9,7 +9,6 @@ import ( "path/filepath" "strconv" "sync" - "syscall" "testing" "time" ) @@ -105,10 +104,6 @@ func TestSupervise(t *testing.T) { t.Error("Expecting new child pid") } - // test info - syscall.Kill(os.Getpid(), syscall.SIGQUIT) - time.Sleep(time.Second) - // fake watch pid with other process cmd := exec.Command("sleep", "1") cmd.Start() From c80bdfe4569683bc5e5f42d37a0fdf7c56bcad30 Mon Sep 17 00:00:00 2001 From: nbari Date: Thu, 2 Nov 2017 14:20:55 +0100 Subject: [PATCH 32/37] /Users/nbari --- CHANGELOG.md | 1 + daemon.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 768c9a6..d5766de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.17.0 Unreleased * Cleaned tests +* Give priority to environment `$HOME` instead of HomeDir from `user.Current()` * Improved lint * Print cmd name (not just PID) in the log when the process terminates [#29](https://github.com/immortal/immortal/pull/29) * Removed info.go (signal.Notify) from supervise.go diff --git a/daemon.go b/daemon.go index 1890c1a..b162061 100644 --- a/daemon.go +++ b/daemon.go @@ -104,11 +104,15 @@ func New(cfg *Config) (*Daemon, error) { // create an .immortal dir on $HOME user when calling immortal directly // and not using immortal-dir, this helps to run immortal-ctl and // check status of all daemons - usr, err := user.Current() - if err != nil { - return nil, err + home := os.Getenv("HOME") + if home == "" { + usr, err := user.Current() + if err != nil { + return nil, err + } + home = usr.HomeDir } - supDir = filepath.Join(usr.HomeDir, + supDir = filepath.Join(home, ".immortal", fmt.Sprintf("%d", os.Getpid())) } From e0725bacda1fbc4fadb1fa80874ca576e2565136 Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 3 Nov 2017 07:44:20 +0100 Subject: [PATCH 33/37] update readme go >= 1.9 --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97ee7e6..2fd786e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ https://immortal.run/ [![GitHub release](https://img.shields.io/github/release/immortal/immortal.svg)](https://github.com/immortal/immortal/releases) [![GoDoc](https://godoc.org/github.com/immortal/immortal?status.svg)](https://godoc.org/github.com/immortal/immortal) + +## Contributing [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/immortal/immortal/blob/master/CONTRIBUTING.md) + If services need to run on behalf other system user `www, nobody, www-data`, not `root`, **immortal** should be compiled from source for the desired target/architecture, otherwise, this error may be returned: @@ -31,7 +34,7 @@ appreciated. Setup go environment https://golang.org/doc/install -> go >= 1.7 is required +> go >= 1.9 is required For example using $HOME/go for your workspace From 2164cb30dbceb4a1cb0c33e55512e60574747f2d Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 3 Nov 2017 07:45:58 +0100 Subject: [PATCH 34/37] update readme go >= 1.9 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2fd786e..9d07b5b 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ https://immortal.run/ [![GitHub release](https://img.shields.io/github/release/immortal/immortal.svg)](https://github.com/immortal/immortal/releases) [![GoDoc](https://godoc.org/github.com/immortal/immortal?status.svg)](https://godoc.org/github.com/immortal/immortal) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/immortal/immortal/blob/master/CONTRIBUTING.md) - -## Contributing [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/immortal/immortal/blob/master/CONTRIBUTING.md) +## run on behalf other system user If services need to run on behalf other system user `www, nobody, www-data`, not `root`, **immortal** should be compiled from source for the desired From 5621388759235ca99cb3b92139411fe468c4d128 Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 3 Nov 2017 07:47:30 +0100 Subject: [PATCH 35/37] update contributing --- CONTRIBUTING.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ca284cc..12308d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing to immortal First and foremost, thank you! We appreciate that you want to contribute to -immortal, your time is valuable, and your contributions mean a lot to us. +**immortal**, your time is valuable, and your contributions mean a lot to us. ## Important! @@ -29,7 +29,7 @@ Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. Don't have time to contribute? No worries, here are some other ways to show your -support for immortal: +support for **immortal**: - star the [project](https://github.com/immortal/immortal) - tweet your support for immortal @@ -54,13 +54,14 @@ Try to follow these guidelines Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: -- **version**: please note the version of immortal are you using +- **version**: please note the version of **immortal** are you using - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) ### Closing issues -The original poster or the maintainer's of immortal may close an issue at any time. Typically, but not exclusively, issues are closed when: +The original poster or the maintainer's of **immortal** may close an issue at +any time. Typically, but not exclusively, issues are closed when: - The issue is resolved - The project's maintainers have determined the issue is out of scope From 41577c1cdb45fad47d313a01dd295eb18650dfd1 Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 3 Nov 2017 07:48:51 +0100 Subject: [PATCH 36/37] update contributing --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12308d5..daa2fd3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to immortal +# Contributing to ⭕ immortal First and foremost, thank you! We appreciate that you want to contribute to **immortal**, your time is valuable, and your contributions mean a lot to us. From 194116df21fa5bc7fe6d0458452368a0562ce080 Mon Sep 17 00:00:00 2001 From: nbari Date: Fri, 3 Nov 2017 11:18:48 +0100 Subject: [PATCH 37/37] update CONTRIBUTING --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index daa2fd3..bb49f3a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ Don't have time to contribute? No worries, here are some other ways to show your support for **immortal**: - star the [project](https://github.com/immortal/immortal) -- tweet your support for immortal +- tweet your support for **immortal** ## Issues