Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Nov 3, 2017
2 parents dc52b1f + 194116d commit 65340cc
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 192 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage.*
.goxc.json
build
supervise
vendor
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 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
* Replaced lock/map with sync.Map in scandir.go
* Updated HandleSignal to use `GetParam` from violetear
45 changes: 45 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[[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 = "4.1.3"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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)

## 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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -107,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()))
}
Expand Down
19 changes: 12 additions & 7 deletions daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -346,9 +346,11 @@ 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)
}
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 {
Expand All @@ -360,6 +362,7 @@ func TestSignalsUDOT(t *testing.T) {
if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "o"); err != nil {
t.Fatal(err)
}

if _, err := ctl.SendSignal(filepath.Join(sdir, "immortal.sock"), "k"); err != nil {
t.Fatal(err)
}
Expand All @@ -382,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 {
Expand Down
30 changes: 0 additions & 30 deletions fifo.go

This file was deleted.

42 changes: 0 additions & 42 deletions fifo_test.go

This file was deleted.

39 changes: 0 additions & 39 deletions info.go

This file was deleted.

12 changes: 6 additions & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -165,15 +165,15 @@ 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)
if err != nil {
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)
Expand All @@ -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
}

Expand Down

0 comments on commit 65340cc

Please sign in to comment.