Skip to content

Commit

Permalink
Add upstart check for /etc/init/<service>.override (#245)
Browse files Browse the repository at this point in the history
* Add upstart check for /etc/init/<service>.override containing "manual" keyword

* Add tests for upstart <service>.override

* Move apache2.override to precise Dockerfile
  • Loading branch information
marclop authored and aelsabbahy committed Jul 6, 2017
1 parent dc3861f commit 291b441
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion integration-tests/Dockerfile_precise
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN mv /sbin/initctl /sbin/initctl.orig && \
apt-get remove -y vim-tiny && \
apt-get clean && \
rm -f /sbin/initctl && \
mv /sbin/initctl.orig /sbin/initctl
mv /sbin/initctl.orig /sbin/initctl && \
echo manual > /etc/init/apache2.override

RUN chkconfig apache2 on
4 changes: 4 additions & 0 deletions integration-tests/goss/goss-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ service:
{{else}}
apache2:
{{end}}
{{ if .Env.OS | regexMatch "precise" }}
enabled: false
{{else}}
enabled: true
{{end}}
running: true
2 changes: 1 addition & 1 deletion integration-tests/goss/precise/goss-aa-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ port:
- 0.0.0.0
service:
apache2:
enabled: true
enabled: false
running: true
process:
apache2:
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/precise/goss-expected-q.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ port:
listening: false
service:
apache2:
enabled: true
enabled: false
running: true
foobar:
enabled: false
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/precise/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ port:
ip: []
service:
apache2:
enabled: true
enabled: false
running: true
foobar:
enabled: false
Expand Down
13 changes: 13 additions & 0 deletions system/service_upstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ServiceUpstart struct {
}

var upstartEnabled = regexp.MustCompile(`^\s*start on`)
var upstartDisabled = regexp.MustCompile(`^manual`)

func NewServiceUpstart(service string, system *System, config util.Config) Service {
return &ServiceUpstart{service: service}
Expand All @@ -38,6 +39,18 @@ func (s *ServiceUpstart) Exists() (bool, error) {
}

func (s *ServiceUpstart) Enabled() (bool, error) {
if fh, err := os.Open(fmt.Sprintf("/etc/init/%s.override", s.service)); err == nil {
scanner := bufio.NewScanner(fh)
for scanner.Scan() {
line := scanner.Text()
if upstartDisabled.MatchString(line) {
return false, nil
}
}
}

// If no /etc/init/<service>.override with `manual` keyword in it has been found
// Check the contents of the upstart manifest.
if fh, err := os.Open(fmt.Sprintf("/etc/init/%s.conf", s.service)); err == nil {
scanner := bufio.NewScanner(fh)
for scanner.Scan() {
Expand Down

0 comments on commit 291b441

Please sign in to comment.