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 50805e6 + 691d9e2 commit 25de5cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -5,5 +5,5 @@
* 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
* Replaced lock/map with sync.Map in scandir.go
* Updated HandleSignal to use `GetParam` from violetear
12 changes: 6 additions & 6 deletions scandir_linux.go
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/immortal/xtime"
Expand All @@ -18,7 +17,7 @@ import (
type ScanDir struct {
scandir string
sdir string
services sync.Map
services map[string]string
timeMultipler time.Duration
}

Expand Down Expand Up @@ -52,6 +51,7 @@ func NewScanDir(path string) (*ScanDir, error) {
return &ScanDir{
scandir: dir,
sdir: GetSdir(),
services: map[string]string{},
timeMultipler: 5,
}, nil
}
Expand Down Expand Up @@ -92,12 +92,12 @@ func (s *ScanDir) Scanner(ctl Control) {
}
// add service to services map or reload if file has been changed
services = append(services, name)
if hash, ok := s.services.Load(name); !ok || !isFile(filepath.Join(s.sdir, name, "lock")) {
if hash, ok := s.services[name]; !ok || !isFile(filepath.Join(s.sdir, name, "lock")) {
start = true
} else if hash != md5 {
stop = true
}
s.services.Store(name, md5)
s.services[name] = md5
// 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 {
Expand All @@ -111,7 +111,7 @@ func (s *ScanDir) Scanner(ctl Control) {
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
s.services.Delete(name)
delete(s.services, name)
log.Println(err)
} else {
log.Printf("%s\n", out)
Expand All @@ -131,7 +131,7 @@ func (s *ScanDir) Scanner(ctl Control) {
// halts services that don't exist anymore
for service := range s.services {
if !inSlice(services, service) {
s.services.Delete(service)
delete(s.services, service)
ctl.SendSignal(filepath.Join(s.sdir, service, "immortal.sock"), "halt")
log.Printf("Exiting: %s\n", service)
}
Expand Down

0 comments on commit 25de5cc

Please sign in to comment.