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 2 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
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
3 changes: 3 additions & 0 deletions integration-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ trap "rv=\$?; docker rm -vf $id; exit \$rv" INT TERM EXIT
# Give httpd time to start up, adding 1 second to see if it helps with intermittent CI failures
[[ $os != "arch" ]] && docker_exec "/goss/$os/goss-linux-$arch" -g "/goss/goss-wait.yaml" validate -r 10s -s 100ms && sleep 1

# Disable apache2 service on boot for "precise"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be moved to the docker file.

Aside from that, this PR looks great!

[[ $os == "precise" ]] && docker_exec bash -c "echo manual > /etc/init/apache2.override"

#out=$(docker exec "$container_name" bash -c "time /goss/$os/goss-linux-$arch -g /goss/$os/goss.yaml validate")
out=$(docker_exec "/goss/$os/goss-linux-$arch" --vars "/goss/vars.yaml" -g "/goss/$os/goss.yaml" validate)
echo "$out"
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