forked from ochinchina/supervisord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d63540
commit 608fedb
Showing
3 changed files
with
64 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// +build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
) | ||
|
||
func (s *Supervisor) checkRequiredResources() error { | ||
if minfds, vErr := s.getMinRequiredRes("minfds"); vErr == nil { | ||
return s.checkMinLimit(syscall.RLIMIT_NOFILE, "NOFILE", minfds) | ||
} | ||
if minprocs, vErr := s.getMinRequiredRes("minprocs"); vErr == nil { | ||
//RPROC = 6 | ||
return s.checkMinLimit(6, "NPROC", minprocs) | ||
} | ||
return nil | ||
|
||
} | ||
|
||
func (s *Supervisor) getMinRequiredRes(resourceName string) (uint64, error) { | ||
if entry, ok := s.config.GetSupervisord(); ok { | ||
value := uint64(entry.GetInt(resourceName, 0)) | ||
if value > 0 { | ||
return value, nil | ||
} else { | ||
return 0, fmt.Errorf("No such key %s", resourceName) | ||
} | ||
} else { | ||
return 0, fmt.Errorf("No supervisord section") | ||
} | ||
|
||
} | ||
|
||
|
||
func (s *Supervisor) checkMinLimit(resource int, resourceName string, minRequiredSource uint64) error { | ||
var limit syscall.Rlimit | ||
|
||
if syscall.Getrlimit(resource, &limit) != nil { | ||
return fmt.Errorf("fail to get the %s limit", resourceName) | ||
} | ||
|
||
if minRequiredSource > limit.Max { | ||
return fmt.Errorf("%s %d is greater than Hard limit %d", resourceName, minRequiredSource, limit.Max) | ||
} | ||
|
||
if limit.Cur >= minRequiredSource { | ||
return nil | ||
} | ||
|
||
limit.Cur = limit.Max | ||
if syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit) != nil { | ||
return fmt.Errorf(fmt.Sprintf("fail to set the %s to %d", resourceName, limit.Cur)) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build windows | ||
|
||
package main | ||
|
||
func (s *Supervisor) checkRequiredResources() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters