Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upstart check for /etc/init/<service>.override #245

Merged
merged 6 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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