-
-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add systemd support (in 3.0.0-rewrite) #384
Add systemd support (in 3.0.0-rewrite) #384
Conversation
@miguelaferreira Thanks! This is great stuff. I've got some notes: I think that in general, I wanted to keep the example.rb recipe as simple as possible, and have the provider make the "default" decisions unless overridden by a variable in the resource, as well as when running the integration tests. There should be very little decision-making in the code at The reason I used There are some syntax failures that prevent the rest of the tests from being run (I'm not certain why the circleci test kitchen suite didn't run either). I had added a reminder in the resource - I think this needs to be handled semi-automatically when on a given platform, but also needs to be flexible enough to allow a user to override it. This should have some accompanying examples in the spec testing, that can make iteration slightly speedier, see https://github.com/miketheman/nginx/blob/3.0.0-rewrite/spec/shared_examples/service.rb and for how I did sysvinit and upstart examples, and then use them in a platform-specific spec test: https://github.com/miketheman/nginx/blob/3.0.0-rewrite/spec/libraries_specs/resource/nginx_service/create/ubuntu_1404_spec.rb Let me know if this makes sense to you, thanks again for working on it! |
@miketheman glad I can help. Let me provide some context with respect to your comments. For some reason, using the opcode-centos-7.1 box, I can't serve a website out of I'll fix the style issues as well (I think that's what you mean by syntax failures, right?). I agree with determining the user automatically depending on the platform. For that I can create a helper method and then use it in the resource definition. Does it sound good to you? I'll update the spec test as well. I'll start with the detection of the user name based on the platform, and then copy whatever you did for sysvinit and upstart. I'll update the PR soonish (most likely this week). |
Not certain why /tmp would behave differently just yet - I'll try to take a
Yes. Once those pass, the spec tests should be executed. You can run these
I think it does - there's already a helper module to add methods in
Sounds good! -M
|
SELinux is probably the cause of this. nginx will run in a limited http context, which I think blocks access to |
7bb5940
to
cdc31cd
Compare
@evaryont It doesn't seem to be SELinux. It's in permissive mode, and I don't find any denied action in the audit log. |
@miketheman I've just pushed a new commit to this PR. I've reverted the changes in the example recipe to keep is simple, as you request. The consequence is that I can't run the respective kitchen test on centos 7. I've added a helper method to determine the user based on the platform. That method is used in the resource definition, and tested in the helpers_sepc.rb. However, the way I managed to do it produces a RuboCop violation. If follow RuboCop's recommendation, then several rspec tests start failing. I've added ChefSpec tests for the centos platform, just like what you had already for debian. The tests for debian were already failing, and so are the ones for centos. Without my changes rake reports this:
With my changes the numbers are higher, but the asserts that fail for the tests I added are the same as the existing ones:
|
@miketheman any progress on this? |
@@ -14,7 +14,7 @@ class NginxService < Chef::Resource::LWRPBase | |||
attribute :error_log_level, kind_of: String, default: 'warn' | |||
attribute :run_group, kind_of: String, default: nil | |||
# @todo Determine what user is correct per-platform | |||
attribute :run_user, kind_of: String, default: 'www-data' | |||
attribute :run_user, kind_of: String, default: lazy { |r| r.user_for_platform } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you fix the rubocop with the following?:
lazy { user_for_platform }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
b364daa
to
871ec04
Compare
Just a thought, wouldn't it be nicer to use systemd's own instance support? You would install the actual .service file once and create symlinks like [Unit]
Description=The nginx HTTP and reverse proxy server for %i
[Service]
PIDFile=/run/%i.pid
ExecStart=/usr/sbin/nginx -c /etc/%i/nginx.conf Please also provide a way to disable this entirely. systemd, nginx, and keys with passphrases do not play well together AT ALL. Trust me, I've tried really hard. With v2, I've had to use chef-rewind to force the service to |
Reviewed 16 of 17 files at r1, 1 of 1 files at r2. .kitchen.yml, line 16 [r2] (raw file): .rubocop.yml, line 3 [r2] (raw file): metadata.rb, line 10 [r2] (raw file): libraries/helpers.rb, line 21 [r2] (raw file): libraries/helpers.rb, line 31 [r2] (raw file): libraries/provider_nginx_service_systemd.rb, line 15 [r2] (raw file): spec/libraries_specs/resource/nginx_service/create/centos_7_spec.rb, line 18 [r2] (raw file): templates/default/systemd/nginx.erb, line 9 [r2] (raw file): templates/default/systemd/nginx.erb, line 10 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 6 [r2] (raw file): I find that these guards are great for a single platform-specific resource, and the test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 16 [r2] (raw file): It would be good to change this Comments from the review on Reviewable.io |
@miguelaferreira I tried using reviewable.io for this changest - hope it makes sense. It was pretty cool and reduced the "17 emails, one per change" problem. |
You can drop .service files under /etc but you won't be able to disable them on boot without deleting them entirely. Generally speaking, you should put them under /lib/systemd/system and create symlinks under /etc. |
871ec04
to
70eb1b7
Compare
@chewi When I implemented this I didn't know systemd supported something like parametric service definitions. I agree that it would indeed be a nice implementation. However, I don't really think that's an issue with the PR. I mean, it could be a better implementation but the current implementation isn't bad. Could this be something to refactor afterwards? Review status: 12 of 17 files reviewed at latest revision, 13 unresolved discussions, some commit checks failed. .rubocop.yml, line 3 [r2] (raw file): metadata.rb, line 10 [r2] (raw file): libraries/helpers.rb, line 21 [r2] (raw file): libraries/helpers.rb, line 31 [r2] (raw file): libraries/provider_nginx_service_systemd.rb, line 15 [r2] (raw file): spec/libraries_specs/resource/nginx_service/create/centos_7_spec.rb, line 18 [r2] (raw file): templates/default/systemd/nginx.erb, line 10 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 6 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 16 [r2] (raw file): Comments from the review on Reviewable.io |
spec/libraries_specs/resource/nginx_service/create/centos_7_spec.rb, line 18 [r2] (raw file): Comments from the review on Reviewable.io |
Reviewed 3 of 17 files at r1, 1 of 3 files at r3, 3 of 3 files at r4. .rubocop.yml, line 3 [r2] (raw file): metadata.rb, line 10 [r2] (raw file): libraries/provider_nginx_service_systemd.rb, line 15 [r2] (raw file):
libraries/provider_nginx_service_systemd.rb, line 23 [r4] (raw file): templates/default/systemd/nginx.erb, line 10 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 6 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 16 [r2] (raw file): Comments from the review on Reviewable.io |
@miguelaferreira I don't think it'd be a massive change but it's cool. I wasn't sure how much of a hurry you were in to get this merged. |
3c20464
to
b2d3e7b
Compare
@chewi this PR has bene open for too long, and I'm not keen in maintaining long lived branches. A change like what you propose would require me to start testing everything from top to bottom, all over again. I simply don't have the time/focus to do that anymore. |
b2d3e7b
to
feaf433
Compare
feaf433
to
d584ece
Compare
@miketheman At this point, I'm happy with my contribution. All tests RSpec and ServerSpec are passing. |
Review status: 10 of 21 files reviewed at latest revision, 9 unresolved discussions. .rubocop.yml, line 3 [r2] (raw file): metadata.rb, line 10 [r2] (raw file): templates/default/systemd/nginx.erb, line 10 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 6 [r2] (raw file): test/fixtures/cookbooks/nginx_service_test/recipes/nginx_repo.rb, line 16 [r2] (raw file): Comments from the review on Reviewable.io |
@miguelaferreira Thanks, and sorry for the delay - I've been attempting to figure out how to get systemd properly working in the docker-based CI, and spent far too much time going down rabbit holes with no resolution. I have a few more commits to add to this branch before merging, and then will be very happy to add the hard work you've put in here to the codebase. Reviewed 1 of 17 files at r1, 10 of 11 files at r5, 1 of 1 files at r6, 3 of 3 files at r7. Comments from Reviewable |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR adds a nginx service systemd provider.
I've tested the provider on a Centos 7 box. In order to make it work I've had to converge the box with
yum-epel
on it, change the site root dir in theexample
recipe (tmp wouldn't work) and always set therun_user
attribute ofnginx_service
tonginx
.I've ran all the kitchen tests for the Centos 7 platform. All but the
service_single_upstream
test case passed. The failing text can be fixed by checking the platform and on Centos 7 include theyum-epel
recipe instead of adding theapt
repository.