Skip to content

Commit

Permalink
modified: README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Mar 31, 2017
1 parent d3ac9e0 commit 2592776
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
55 changes: 42 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,56 @@ https://immortal.run/

[ ![Download](https://api.bintray.com/packages/nbari/immortal/immortal/images/download.svg) ](https://bintray.com/nbari/immortal/immortal/_latestVersion)

# configuration example

Content of file `/usr/local/etc/immortal/www.yml`:

```yaml
# pkg install go-www
cmd: www
cwd: /usr/ports
log:
file: /var/log/www.log
age: 10 # seconds
num: 7 # int
size: 1 # MegaBytes
wait: 1
require:
- foo
- bar
```

If `foo` and `bar` not up, the service `www` will not be started.

> `foo` and `bar` are the names for the services defined on the same path www.yaml is located, foo.yml & bar.yml

# Paths

When using immortaldir:

/usr/local/etc/immortal
|--api1.yml
|--api2.yml
`--api3.yml
|--foo.yml
|--bar.yml
`--www.yml

The name of the `file.yml` will be used to reference the service to be
daemonized excluding the extension `.yml`.:

The name of the `file.yml` will be used to reference the service to be daemonized.
foo
bar
www

## /var/run/immortal/<name>

/var/run/immortal
|--api1
|--foo
| |-lock
| `-immortal.sock
|--api2
|--bar
| |-lock
| `-immortal.sock
`--api3
`--www
|-lock
`-immortal.sock

Expand All @@ -42,14 +71,14 @@ structure:

~/.immortal
|--(pid)
| `--supervise
| `--immortal.sock
| |--lock
| `--immortal.sock
|--(pid)
| `--supervise
| `--immortal.sock
| |--lock
| `--immortal.sock
`--(pid)
`--supervise
`--immortal.sock
|--lock
`--immortal.sock

# immortalctl

Expand Down
2 changes: 2 additions & 0 deletions scandir.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (s *ScanDir) Scaner(ctl Control) {
// try to start before via socket
if _, err := ctl.SendSignal(filepath.Join(s.sdir, name, "immortal.sock"), "start"); err != nil {
if out, err := ctl.Run(fmt.Sprintf("immortal -c %s -ctl %s", path, name)); err != nil {
// keep retrying
delete(s.services, name)
log.Println(err)
} else {
log.Printf("%s\n", out)
Expand Down
9 changes: 3 additions & 6 deletions scandir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func TestScaner(t *testing.T) {
t.Fatal(err)
}
s.Scaner(ctl)
expect(t, "0af0f52bb73880b58d20ec86a9c5b1dc", s.services["run"])
// if error while starting, the service will be removed in order to keep retrying
expect(t, len(s.services), 0)
re = regexp.MustCompile(`return error 1`)
expect(t, "return error 1", re.FindString(buf.String()))
buf.Reset()
Expand All @@ -132,9 +133,6 @@ func TestScaner(t *testing.T) {
t.Fatal(err)
}
s.Scaner(ctl)
re = regexp.MustCompile(`Exiting: run`)
expect(t, "Exiting: run", re.FindString(buf.String()))
buf.Reset()
ctl.i++
ctl.j = -1
expect(t, 0, len(s.services))
Expand All @@ -144,15 +142,14 @@ func TestScaner(t *testing.T) {
t.Fatal(err)
}
s.Scaner(ctl)
expect(t, "9944429f23907af240460d0583a27cd2", s.services["run"])
expect(t, len(s.services), 0)
re = regexp.MustCompile(`Starting: run`)
expect(t, "Starting: run", re.FindString(buf.String()))
re = regexp.MustCompile(`can't start`)
expect(t, "can't start", re.FindString(buf.String()))
buf.Reset()
ctl.i++
ctl.j = -1
expect(t, 1, len(s.services))

// scan again and send signal START because it has passed less than 5 sec
s.Scaner(ctl)
Expand Down

0 comments on commit 2592776

Please sign in to comment.