Skip to content

Commit

Permalink
Merge tag '0.12.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Apr 6, 2017
2 parents 162e95e + efe46cf commit 0e9583c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
9 changes: 5 additions & 4 deletions cmd/immortalctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var version string
func main() {
var (
sdir, serviceName, signal string
options = []string{"once", "start", "status", "stop", "exit"}
options = []string{"exit", "halt", "once", "start", "status", "stop"}
ppid, pup, pdown, pname int
wg sync.WaitGroup
v = flag.Bool("v", false, fmt.Sprintf("Print version: %s", version))
Expand Down Expand Up @@ -47,14 +47,15 @@ func main() {
}

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [option] [-12achikinouqstvw] service\n\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s %s\n",
fmt.Fprintf(os.Stderr, "usage: %s [option] [-12achikinouqstvw] service\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s %s\n",
os.Args[0],
" Options:",
" exit Stop service and supervisor.",
" exit Exits the supervisor.",
" halt Stop the service by sending a TERM signal, and exits supervisor.",
" once If the service is not running, start it. Do not restart it if it stops.",
" start Start the service.",
" status Print status.",
" stop Stop the service.",
" stop Stop the service by sending a TERM signal.",
" Signals:",
" -1 USR1",
" -2 USR2",
Expand Down
4 changes: 4 additions & 0 deletions man/immortal.8
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ To stop the supervisor:

http://<domain>/signal/exit

To stop the supervisor and the service:

http://<domain>/signal/halt

Output is in JSON format.
.SH SEE ALSO
immortalctl(8), immortaldir(8)
Expand Down
10 changes: 6 additions & 4 deletions man/immortalctl.8
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ By queering the socket of the service directly, extra information can be obtaine
An option or signal can be sent to all the services by using a * instead of the service name.
.SH OPTIONS

exit Stop service and supervisor, when following a pid it will only exit the supervisor, normally this option should not be used since the required behavior is to keep the service running forever.
exit Exits supervisor, when following a pid it will only exit the supervisor, normally this option should not be used since the required behavior is to keep the service running forever.

halt Stop the service by sending a TERM signal, and exist the supervisor.

once If the service is not running, it will be started, if for some reason the process stops, it wont be starte again.

start Start the service.

status Print status.

stop Stop the service, will terminate the service and display the down time in the Down column when printing the status.
stop Stop the service by sending a TERM signal, will display the down time in the Down column when printing the status.

Signals:
When sending signals, options start with one dash.
Expand Down Expand Up @@ -80,9 +82,9 @@ Send signal USR2:

immortalctl -2 service

Stop all services, normally this is not the required behavior, since will exit the supervisor:
Stop all services, normally this is not the required behavior, since will exit the supervisor and terminate all services:

immortalctl exit "*"
immortalctl halt "*"
.SH SEE ALSO
immortal(8), immortaldir(8)
.SH BUGS
Expand Down
12 changes: 6 additions & 6 deletions scandir.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func (s *ScanDir) Start(ctl Control) {
}
}

// Scaner searches for run.yml if file changes it will reload(exit-start)
// Scaner searches for run.yml if file changes it will reload(stop-start)
func (s *ScanDir) Scaner(ctl Control) {
// var services used to keep track of what services should be removed if they don't
// exist any more
var services []string

find := func(path string, f os.FileInfo, err error) error {
var (
exit, start bool
stop, start bool
md5, name string
)
if err != nil {
Expand All @@ -96,12 +96,12 @@ func (s *ScanDir) Scaner(ctl Control) {
} else if hash != md5 {
// update to new hash
s.services[name] = md5
exit = true
stop = true
}
// check if file hasn't been changed since last tick (5 seconds)
refresh := (time.Now().Unix() - xtime.Get(f).Ctime().Unix()) <= int64(s.timeMultipler)
if refresh || start {
if exit {
if stop {
// restart = term + start
log.Printf("Restarting: %s\n", name)
ctl.SendSignal(filepath.Join(s.sdir, name, "immortal.sock"), "halt")
Expand All @@ -128,11 +128,11 @@ func (s *ScanDir) Scaner(ctl Control) {
log.Println(err)
}

// exit services that don't exist anymore
// halts services that don't exist anymore
for service := range s.services {
if !inSlice(services, service) {
delete(s.services, service)
ctl.SendSignal(filepath.Join(s.sdir, service, "immortal.sock"), "exit")
ctl.SendSignal(filepath.Join(s.sdir, service, "immortal.sock"), "halt")
log.Printf("Exiting: %s\n", service)
}
}
Expand Down
4 changes: 2 additions & 2 deletions scandir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func TestScaner(t *testing.T) {
}{
{"/var/run/immortal/run/immortal.sock", []string{"start"}, true, s.scandir, ""},
{"/var/run/immortal/run/immortal.sock", []string{"halt", "start"}, true, s.scandir, "return error 1"},
{"/var/run/immortal/run/immortal.sock", []string{"exit"}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{"halt"}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{"start"}, true, s.scandir, "can't start"},
{"/var/run/immortal/run/immortal.sock", []string{"start"}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{"start"}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{"exit"}, false, "", ""},
{"/var/run/immortal/run/immortal.sock", []string{"halt"}, false, "", ""},
},
}
// first call to scanner, should start services and create hashes
Expand Down

0 comments on commit 0e9583c

Please sign in to comment.