├── .delivery └── project.toml ├── .foodcritic ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .kitchen.dokken.yml ├── .kitchen.yml ├── .travis.yml ├── Berksfile ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── LICENSE ├── README.md ├── TESTING.md ├── chefignore ├── libraries ├── helpers.rb ├── helpers_debian.rb ├── helpers_rhel.rb ├── httpd_config.rb ├── httpd_config_debian.rb ├── httpd_config_rhel.rb ├── httpd_module.rb ├── httpd_module_debian.rb ├── httpd_module_rhel.rb ├── httpd_service.rb ├── httpd_service_debian.rb ├── httpd_service_debian_systemd.rb ├── httpd_service_debian_sysvinit.rb ├── httpd_service_rhel.rb ├── httpd_service_rhel_systemd.rb ├── httpd_service_rhel_sysvinit.rb ├── info_module_packages.rb ├── info_mpm_config_parameter.rb └── info_service_packages.rb ├── metadata.rb ├── spec ├── helpers │ ├── module_amazon_2_2_spec.rb │ ├── module_amazon_2_4_spec.rb │ ├── module_debian_2_2_spec.rb │ ├── module_debian_2_4_spec.rb │ ├── module_invalid_spec.rb │ ├── module_rhel_6_2_2_spec.rb │ ├── module_rhel_7_2_4_spec.rb │ ├── mpm_config_parameter_spec.rb │ └── service_package_name_spec.rb └── spec_helper.rb ├── templates └── default │ ├── 2.2 │ ├── mods │ │ └── mpm.conf.erb │ ├── scripts │ │ └── a2enmod.erb │ └── sysvinit │ │ ├── debian-7 │ │ └── apache2.erb │ │ ├── el-5 │ │ └── httpd.erb │ │ ├── el-6 │ │ └── httpd.erb │ │ ├── ubuntu-10.04 │ │ └── apache2.erb │ │ └── ubuntu-12.04 │ │ └── apache2.erb │ ├── 2.4 │ ├── mods │ │ └── rhel │ │ │ └── mpm.conf.erb │ ├── scripts │ │ └── a2enmod.erb │ └── sysvinit │ │ ├── el-6 │ │ └── httpd.erb │ │ └── ubuntu-14.04 │ │ └── apache2.erb │ ├── envvars.erb │ ├── httpd.conf.erb │ ├── magic.erb │ ├── module_load.erb │ ├── mpm.conf.erb │ ├── rhel │ └── sysconfig │ │ ├── httpd-2.2.erb │ │ └── httpd-2.4.erb │ └── systemd │ ├── httpd.conf.erb │ └── httpd.service.erb └── test ├── cookbooks ├── hello_world_test │ ├── metadata.rb │ ├── recipes │ │ ├── default-docker.rb │ │ └── default.rb │ └── templates │ │ └── default │ │ └── hello.erb ├── httpd_config_test │ ├── metadata.rb │ ├── recipes │ │ └── default.rb │ └── templates │ │ └── default │ │ ├── hello.conf.erb │ │ └── sensitive.conf.erb ├── httpd_module_test │ ├── metadata.rb │ └── recipes │ │ └── default.rb └── httpd_service_test │ ├── attributes │ └── default.rb │ ├── metadata.rb │ ├── recipes │ ├── actions.rb │ ├── multi.rb │ └── single.rb │ └── templates │ └── default │ └── new-listener.erb └── integration ├── config ├── debian_spec.rb └── rhel_spec.rb ├── hello_world_test └── hello_spec.rb ├── module22 ├── debian_spec.rb └── rhel_spec.rb ├── module24 ├── debian_spec.rb └── rhel_spec.rb ├── service22-actions └── actions_spec.rb ├── service22-multi └── assert_functioning_spec.rb ├── service22-single └── assert_functioning_spec.rb ├── service24-actions └── actions_spec.rb ├── service24-multi └── assert_functioning_spec.rb └── service24-single └── assert_functioning_spec.rb /.delivery/project.toml: -------------------------------------------------------------------------------- 1 | remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" 2 | -------------------------------------------------------------------------------- /.foodcritic: -------------------------------------------------------------------------------- 1 | ~FC023 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Cookbook version 2 | [Version of the cookbook where you are encountering the issue] 3 | 4 | ### Chef-client version 5 | [Version of chef-client in your environment] 6 | 7 | ### Platform Details 8 | [Operating system distribution and release version. Cloud provider if running in the cloud] 9 | 10 | ### Scenario: 11 | [What you are trying to achieve and you can't?] 12 | 13 | ### Steps to Reproduce: 14 | [If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?] 15 | 16 | ### Expected Result: 17 | [What are you expecting to happen as the consequence of above reproduction steps?] 18 | 19 | ### Actual Result: 20 | [What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.] 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | [Describe what this change achieves] 4 | 5 | ### Issues Resolved 6 | 7 | [List any existing issues this PR resolves] 8 | 9 | ### Check List 10 | 11 | - [ ] All tests pass. See 12 | - [ ] New functionality includes testing. 13 | - [ ] New functionality has been documented in the README if applicable 14 | - [ ] All commits have been signed for the Developer Certificate of Origin. See 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | coverage 4 | InstalledFiles 5 | lib/bundler/man 6 | pkg 7 | rdoc 8 | spec/reports 9 | test/tmp 10 | test/version_tmp 11 | tmp 12 | _Store 13 | *~ 14 | *# 15 | .#* 16 | \#*# 17 | .*.sw[a-z] 18 | *.un~ 19 | *.tmp 20 | *.bk 21 | *.bkup 22 | 23 | # ruby/bundler files 24 | .ruby-version 25 | .ruby-gemset 26 | .rvmrc 27 | Gemfile.lock 28 | .bundle 29 | *.gem 30 | 31 | # YARD artifacts 32 | .yardoc 33 | _yardoc 34 | doc/ 35 | .idea 36 | 37 | # chef stuff 38 | Berksfile.lock 39 | .kitchen 40 | .kitchen.local.yml 41 | vendor/ 42 | .coverage/ 43 | .zero-knife.rb 44 | Policyfile.lock.json 45 | Cheffile.lock 46 | .librarian/ 47 | 48 | # vagrant stuff 49 | .vagrant/ 50 | .vagrant.d/ 51 | .kitchen/ 52 | -------------------------------------------------------------------------------- /.kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true # because Docker and SystemD/Upstart 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: 7 | name: dokken 8 | 9 | provisioner: 10 | name: dokken 11 | deprecations_as_errors: true 12 | 13 | verifier: 14 | name: inspec 15 | 16 | platforms: 17 | - name: amazonlinux 18 | driver: 19 | image: dokken/amazonlinux 20 | pid_one_command: /sbin/init 21 | 22 | - name: debian-8 23 | driver: 24 | image: dokken/debian-8 25 | pid_one_command: /bin/systemd 26 | intermediate_instructions: 27 | - RUN /usr/bin/apt-get update 28 | 29 | - name: debian-9 30 | driver: 31 | image: dokken/debian-9 32 | pid_one_command: /bin/systemd 33 | intermediate_instructions: 34 | - RUN /usr/bin/apt-get update 35 | 36 | - name: centos-6 37 | driver: 38 | image: dokken/centos-6 39 | pid_one_command: /sbin/init 40 | 41 | - name: centos-7 42 | driver: 43 | image: dokken/centos-7 44 | pid_one_command: /usr/lib/systemd/systemd 45 | 46 | - name: fedora-latest 47 | driver: 48 | image: dokken/fedora-latest 49 | pid_one_command: /usr/lib/systemd/systemd 50 | 51 | - name: ubuntu-14.04 52 | driver: 53 | image: dokken/ubuntu-14.04 54 | pid_one_command: /sbin/init 55 | intermediate_instructions: 56 | - RUN /usr/bin/apt-get update 57 | 58 | - name: ubuntu-16.04 59 | driver: 60 | image: dokken/ubuntu-16.04 61 | pid_one_command: /bin/systemd 62 | intermediate_instructions: 63 | - RUN /usr/bin/apt-get update 64 | 65 | - name: opensuse-leap 66 | driver: 67 | image: dokken/opensuse-leap 68 | pid_one_command: /bin/systemd 69 | 70 | suites: 71 | # 72 | # config 73 | # 74 | - name: config 75 | run_list: 76 | - recipe[httpd_config_test] 77 | 78 | # 79 | # modules 80 | # 81 | - name: module22 82 | run_list: 83 | - recipe[httpd_module_test] 84 | includes: [ 85 | 'centos-6' 86 | ] 87 | attributes: 88 | httpd: 89 | version: '2.2' 90 | 91 | - name: module24 92 | run_list: 93 | - recipe[httpd_module_test] 94 | includes: [ 95 | 'centos-7', 96 | 'debian-8', 97 | 'debian-9', 98 | 'fedora-latest', 99 | 'ubuntu-14.04', 100 | 'ubuntu-16.04', 101 | 'opensuse-leap' 102 | ] 103 | attributes: 104 | httpd: 105 | version: '2.4' 106 | 107 | # 108 | # service22-single 109 | # 110 | - name: service22-single 111 | run_list: 112 | - recipe[httpd_service_test::single] 113 | includes: [ 114 | 'centos-6' 115 | ] 116 | attributes: 117 | httpd: 118 | version: '2.2' 119 | 120 | # 121 | # service22-multi 122 | # 123 | - name: service22-multi 124 | run_list: 125 | - recipe[httpd_service_test::multi] 126 | includes: [ 127 | 'centos-6' 128 | ] 129 | attributes: 130 | httpd: 131 | contact: 'bob@computers.biz' 132 | version: '2.2' 133 | service_name: 'multi' 134 | listen_ports: [ '81', '444' ] 135 | run_user: 'bob' 136 | run_group: 'bob' 137 | timeout: '1234' 138 | keepalive: false 139 | keepaliverequests: '5678' 140 | keepalivetimeout: '8765' 141 | mpm: 'prefork' 142 | startservers: '20' 143 | minspareservers: '20' 144 | maxspareservers: '40' 145 | log_level: 'warn' 146 | maxkeepaliverequests: '2001' 147 | 148 | # 149 | # service22-actions 150 | # 151 | - name: service22-actions 152 | run_list: 153 | - recipe[httpd_service_test::actions] 154 | includes: [ 155 | 'centos-6' 156 | ] 157 | attributes: 158 | httpd: 159 | version: '2.2' 160 | 161 | # 162 | # service24-single 163 | # 164 | - name: service24-single 165 | driver: 166 | run_list: 167 | - recipe[httpd_service_test::single] 168 | includes: [ 169 | 'centos-7', 170 | 'fedora-latest', 171 | 'debian-8', 172 | 'debian-9', 173 | 'ubuntu-14.04', 174 | 'ubuntu-16.04', 175 | 'opensuse-leap' 176 | ] 177 | attributes: 178 | httpd: 179 | version: '2.4' 180 | 181 | # 182 | # service24-multi-docker 183 | # 184 | - name: service24-multi 185 | run_list: 186 | - recipe[httpd_service_test::multi] 187 | includes: [ 188 | 'centos-7', 189 | 'debian-8', 190 | 'debian-9', 191 | 'fedora-latest', 192 | 'ubuntu-14.04', 193 | 'ubuntu-16.04', 194 | 'opensuse-leap' 195 | ] 196 | attributes: 197 | httpd: 198 | version: '2.4' 199 | service_name: 'multi' 200 | listen_ports: [ '81', '444' ] 201 | log_level: 'warn' 202 | run_user: 'bob' 203 | run_group: 'bob' 204 | contact: 'alice@computers.biz' 205 | timeout: '1234' 206 | keepalive: false 207 | keepaliverequests: '5678' 208 | keepalivetimeout: '8765' 209 | mpm: 'prefork' 210 | startservers: '20' 211 | minspareservers: '20' 212 | maxspareservers: '40' 213 | maxkeepaliverequests: '2001' 214 | 215 | # 216 | # service24-actions 217 | # 218 | - name: service24-actions 219 | driver: 220 | run_list: 221 | - recipe[httpd_service_test::actions] 222 | includes: [ 223 | 'centos-7', 224 | 'debian-8', 225 | 'debian-9', 226 | 'fedora-latest', 227 | 'ubuntu-14.04', 228 | 'ubuntu-16.04', 229 | 'opensuse-leap' 230 | ] 231 | attributes: 232 | httpd: 233 | version: '2.4' 234 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: vagrant 3 | 4 | provisioner: 5 | name: chef_zero 6 | deprecations_as_errors: true 7 | 8 | verifier: 9 | name: inspec 10 | 11 | platforms: 12 | - name: amazonlinux 13 | driver_config: 14 | box: mvbcoding/awslinux 15 | - name: centos-6 16 | - name: centos-7 17 | - name: debian-8 18 | - name: debian-9 19 | - name: fedora-28 20 | - name: freebsd-11 21 | - name: opensuse-leap-42 22 | - name: ubuntu-14.04 23 | - name: ubuntu-16.04 24 | - name: ubuntu-18.04 25 | 26 | suites: 27 | # 28 | # config 29 | # 30 | - name: config 31 | run_list: 32 | - recipe[httpd_config_test] 33 | 34 | # 35 | # modules 36 | # 37 | - name: module22 38 | run_list: 39 | - recipe[httpd_module_test] 40 | includes: [ 41 | 'centos-6' 42 | ] 43 | attributes: 44 | httpd: 45 | version: '2.2' 46 | 47 | - name: module24 48 | run_list: 49 | - recipe[httpd_module_test] 50 | includes: [ 51 | 'centos-7', 52 | 'debian-8', 53 | 'fedora-28', 54 | 'ubuntu-14.04', 55 | 'ubuntu-16.04', 56 | 'freebsd-11', 57 | 'opensuse-leap-42' 58 | ] 59 | attributes: 60 | httpd: 61 | version: '2.4' 62 | 63 | # 64 | # service22-single 65 | # 66 | - name: service22-single 67 | run_list: 68 | - recipe[httpd_service_test::single] 69 | includes: [ 70 | 'centos-6' 71 | ] 72 | attributes: 73 | httpd: 74 | version: '2.2' 75 | 76 | # 77 | # service22-multi 78 | # 79 | - name: service22-multi 80 | run_list: 81 | - recipe[httpd_service_test::multi] 82 | includes: [ 83 | 'centos-6' 84 | ] 85 | attributes: 86 | httpd: 87 | contact: 'bob@computers.biz' 88 | version: '2.2' 89 | service_name: 'multi' 90 | listen_ports: [ '81', '444' ] 91 | run_user: 'bob' 92 | run_group: 'bob' 93 | timeout: '1234' 94 | keepalive: false 95 | keepaliverequests: '5678' 96 | keepalivetimeout: '8765' 97 | mpm: 'prefork' 98 | startservers: '20' 99 | minspareservers: '20' 100 | maxspareservers: '40' 101 | log_level: 'warn' 102 | maxkeepaliverequests: '2001' 103 | 104 | # 105 | # service22-actions 106 | # 107 | - name: service22-actions 108 | run_list: 109 | - recipe[httpd_service_test::actions] 110 | includes: [ 111 | 'centos-6' 112 | ] 113 | attributes: 114 | httpd: 115 | version: '2.2' 116 | 117 | # 118 | # service24-single 119 | # 120 | - name: service24-single 121 | driver: 122 | run_list: 123 | - recipe[httpd_service_test::single] 124 | includes: [ 125 | 'centos-7', 126 | 'fedora-28', 127 | 'debian-8', 128 | 'ubuntu-14.04', 129 | 'ubuntu-16.04', 130 | 'freebsd-11', 131 | 'opensuse-leap-42' 132 | ] 133 | attributes: 134 | httpd: 135 | version: '2.4' 136 | 137 | # 138 | # service24-multi-docker 139 | # 140 | - name: service24-multi 141 | run_list: 142 | - recipe[httpd_service_test::multi] 143 | includes: [ 144 | 'centos-7', 145 | 'debian-8', 146 | 'fedora-28', 147 | 'ubuntu-14.04', 148 | 'ubuntu-16.04', 149 | 'freebsd-11', 150 | 'opensuse-leap-42' 151 | ] 152 | attributes: 153 | httpd: 154 | version: '2.4' 155 | service_name: 'multi' 156 | listen_ports: [ '81', '444' ] 157 | log_level: 'warn' 158 | run_user: 'bob' 159 | run_group: 'bob' 160 | contact: 'alice@computers.biz' 161 | timeout: '1234' 162 | keepalive: false 163 | keepaliverequests: '5678' 164 | keepalivetimeout: '8765' 165 | mpm: 'prefork' 166 | startservers: '20' 167 | minspareservers: '20' 168 | maxspareservers: '40' 169 | maxkeepaliverequests: '2001' 170 | # 171 | # service24-actions 172 | # 173 | - name: service24-actions 174 | driver: 175 | run_list: 176 | - recipe[httpd_service_test::actions] 177 | includes: [ 178 | 'centos-7', 179 | 'debian-8', 180 | 'fedora-28', 181 | 'ubuntu-14.04', 182 | 'ubuntu-16.04', 183 | 'freebsd-11', 184 | 'opensuse-leap-42' 185 | ] 186 | attributes: 187 | httpd: 188 | version: '2.4' 189 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | addons: 5 | apt: 6 | sources: 7 | - chef-current-trusty 8 | packages: 9 | - chefdk 10 | 11 | # Don't `bundle install` which takes about 1.5 mins 12 | install: echo "skip bundle install" 13 | 14 | branches: 15 | only: 16 | - master 17 | 18 | services: docker 19 | 20 | env: 21 | matrix: 22 | - INSTANCE=config-centos-6 23 | - INSTANCE=config-centos-7 24 | - INSTANCE=config-fedora-latest 25 | - INSTANCE=config-debian-8 26 | - INSTANCE=config-debian-9 27 | - INSTANCE=config-ubuntu-1404 28 | - INSTANCE=config-ubuntu-1604 29 | - INSTANCE=module22-centos-6 30 | - INSTANCE=module24-centos-7 31 | - INSTANCE=module24-fedora-latest 32 | - INSTANCE=module24-debian-8 33 | - INSTANCE=module24-debian-9 34 | - INSTANCE=module24-ubuntu-1404 35 | - INSTANCE=module24-ubuntu-1604 36 | #- INSTANCE=module24-opensuse-leap 37 | - INSTANCE=service22-single-centos-6 38 | - INSTANCE=service22-multi-centos-6 39 | - INSTANCE=service22-actions-centos-6 40 | - INSTANCE=service24-single-centos-7 41 | - INSTANCE=service24-single-fedora-latest 42 | - INSTANCE=service24-single-ubuntu-1404 43 | - INSTANCE=service24-single-ubuntu-1604 44 | - INSTANCE=service24-single-debian-8 45 | - INSTANCE=service24-single-debian-9 46 | #- INSTANCE=service24-single-opensuse-leap 47 | - INSTANCE=service24-multi-centos-7 48 | - INSTANCE=service24-multi-fedora-latest 49 | - INSTANCE=service24-multi-debian-8 50 | - INSTANCE=service24-multi-ubuntu-1404 51 | - INSTANCE=service24-multi-ubuntu-1604 52 | #- INSTANCE=service24-multi-opensuse-leap 53 | - INSTANCE=service24-actions-centos-7 54 | - INSTANCE=service24-actions-fedora-latest 55 | - INSTANCE=service24-actions-ubuntu-1404 56 | - INSTANCE=service24-actions-ubuntu-1604 57 | - INSTANCE=service24-actions-debian-8 58 | - INSTANCE=service24-actions-debian-9 59 | #- INSTANCE=service24-actions-opensuse-leap 60 | 61 | before_script: 62 | - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) 63 | - eval "$(chef shell-init bash)" 64 | - chef --version 65 | - cookstyle --version 66 | - foodcritic --version 67 | 68 | script: KITCHEN_LOCAL_YAML=.kitchen.dokken.yml kitchen verify ${INSTANCE} 69 | 70 | matrix: 71 | include: 72 | - script: 73 | - chef exec delivery local all 74 | env: UNIT_AND_LINT=1 75 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'selinux' 7 | cookbook 'freebsd' 8 | end 9 | 10 | cookbook 'httpd_config_test', path: 'test/cookbooks/httpd_config_test' 11 | cookbook 'httpd_module_test', path: 'test/cookbooks/httpd_module_test' 12 | cookbook 'httpd_service_test', path: 'test/cookbooks/httpd_service_test' 13 | cookbook 'hello_world_test', path: 'test/cookbooks/hello_world_test' 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # httpd Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the httpd cookbook. 4 | 5 | ## 0.6.2 (2018-02-16) 6 | 7 | - Allow sensitive flag for httpd_config. 8 | 9 | ## 0.6.1 (2017-10-20) 10 | 11 | - Fix a failure in the systemd template 12 | 13 | ## 0.6.0 (2017-10-20) 14 | 15 | - Remove Debian 6 helpers and simplify Ubuntu helper to support non-LTS ubuntu releases like 17.04 16 | - Remove the platform priority map logic which isn't needed in modern Chef releases 17 | - Add a missing service name variable in the systemd service resource, which will help us eventually support SUSE systemd setup 18 | - Remove opensuse from the readme for now since we're not actually testing it and there's still issues 19 | - Add support / testing for Debian 9 20 | - Improve debian check logic in the systemd unit file to support derivatives of Debian/Ubuntu 21 | 22 | ## 0.5.1 (2017-10-19) 23 | 24 | - Don't delete directory mods-available with delete action. 25 | 26 | ## 0.5.0 (2017-08-23) 27 | 28 | ### Breaking changes 29 | 30 | - Remove support for OmniOS / SmartOS, which didn't actually work before 31 | - Remove support for EOL CentOS 5 / Ubuntu 12.04 32 | - Remove compat_resource and instead require Chef 12.7+ 33 | - Service creation has been moved from the :start action to the :create action to follow user exceptions. Existing cookbooks using the service resource will need to be updated to use the create action in addition to the start action. 34 | 35 | ### Other Changes 36 | 37 | - The service resource have been DRYed up 38 | - Use a SPDX compliant license string to resolve FoodCritic warnings 39 | - Switch from Rakefile testing to Delivery local mode 40 | - Add support for Amazon Linux 2017 and simplify Amazon detection so we don't have to repeat this next year 41 | - Remove Chef 12.0 compatibility code to simplify init system detection 42 | - Resolve all CHEF-19 deprecation warnings 43 | 44 | ## 0.4.5 (2017-02-13) 45 | 46 | - Resolve Issue #104 with use of security module on RHEL 7.2 47 | 48 | ## 0.4.4 (2016-09-27) 49 | 50 | - Explicitly using new_resource.version in guard clause Centos/RHEL 51 | - Add net-tools to docker configuration 52 | 53 | ## 0.4.3 (2016-09-27) 54 | 55 | - Explicitly using new_resource.version in guard clause Ubuntu 56 | 57 | ## 0.4.2 (2016-09-27) 58 | 59 | - Release reflecting new dep on compat_resource 12.14.6 60 | 61 | ## 0.4.1 (2016-09-23) 62 | 63 | - Fix incompatibilities with the new releases of compat_resource 64 | - Require a more recent compat_resource cookbook to resolve notification issues 65 | - Switch linting to cookstyle 66 | - Fix documentation for httpd_config in the README 67 | - Resolve Foodcritic warnings 68 | - Fix systemd start timeout on ubuntu 16.04 69 | - Avoid node.set deprecation notices in the specs 70 | 71 | ## 0.4.0 (2016-05-31) 72 | 73 | - Removed support for end of life platforms: Ubuntu 10.04, 13.04, 13.10, 14.10 and Suse 12.X 74 | - Added support for Amazon 2016.X 75 | - Added support for opensuse / opensuseleap 76 | - Added support for modern Fedora releases and changed the code so we don't have to perform a new release every time Fedora ships 77 | - Moved systemd unit files to /etc/system instead of /usr/lib/systemd 78 | - Resolved nil deprecation notices in the various providers 79 | - Removed the installation of net-tools, which is only required for integration testing. Moved this to the actual test recipe instead 80 | - Updated kitchen-dokken config to use the latest Chef client and additional platforms 81 | - Added back a standard .kitchen.yml file for local testing 82 | - Fixed the test suites in Test Kitchen to reflect what Apache versions actually exist on platforms 83 | - Added a Gemfile for testing dependencies 84 | - Removed the Guardfile 85 | - Updated .gitignore and chefignore files 86 | - Added a .foodcritic file to disable FC005 and FC023 87 | - Added a Rakefile for simplied testing 88 | - Updated the specs to test on more recent platforms 89 | - Converted integration tests to inspec 90 | - Added initial, yet incomplete, support for Debian 8 / Ubuntu 16.04\. Service management is still lacking and will ship in a future release 91 | - Removed smartos / omnios as tested platforms 92 | 93 | ## 0.3.6 (2016-04-27) 94 | 95 | - fix some of the copious warnings about 'invalid default value' #63 [@cmenning](https://github.com/cmenning) 96 | - Added package name to httpd_module and fixed httpd_version to match resource attribute parameter #62 [@ikari7789](https://github.com/ikari7789) 97 | - Fix delete action for RHEL that was not removing config files correctly #74 [@darrylb-github](https://github.com/darrylb-github) 98 | 99 | ## 0.3.5 (2016-03-21) 100 | 101 | - bug fix for #66, resolving run directories on reboot on rhel family systems using systemd [@gitjoey](https://github.com/gitjoey) and [@odoell](https://github.com/odoell) 102 | 103 | ## 0.3.4 (2016-01-26) 104 | 105 | - bug fix for #56, ambiguous version method in sysvinit manager 106 | 107 | ## 0.3.3 (2015-11-30) 108 | 109 | - bug fix for 32 bit support on RHEL platforms 110 | 111 | ## 0.3.2 (2015-10-28) 112 | 113 | - depending on compat_resource >= 12.5.11 114 | 115 | ## 0.3.1 (2015-10-28) 116 | 117 | - Fixed bug in rhel sysvinit provider 118 | - style fixes 119 | 120 | ## 0.3.0 (2015-10-08) 121 | 122 | - Heavy refactoring, converting to 12.5 resources with 12.x backcompat 123 | - Removed fugly resource titles, which explodes ChefSpec. 124 | - Commented out a ton of specs, still getting various clone warnings. 125 | 126 | ## 0.2.19 (2015-09-15) 127 | 128 | - Updating for Amazon Linux 2015.03 129 | 130 | ## 0.2.18 (2015-06-30) 131 | 132 | - Fixes for correct Provider Resolver behavior and more 12.4.0 fixes 133 | 134 | ## 0.2.17 (2015-06-28) 135 | 136 | - Fixing IfModule by including .load before .conf 137 | 138 | ## 0.2.16 (2015-06-26) 139 | 140 | - Dropping Chef 11 support 141 | - fix the priority map dsl method 142 | 143 | ## 0.2.15 (2015-06-26) 144 | 145 | - Fixing up provider resolution code to work properly with 12.4 146 | 147 | ## 0.2.14 (2015-06-05) 148 | 149 | - Fixing up mod_php filename for debian based distros 150 | 151 | ## v0.2.12 (2015-05-11) 152 | 153 | - Fixing 'provides' bug that was breaking 12.3 154 | 155 | ## v0.2.11 (2015-04-11) 156 | 157 | - Fix config file load ordering 158 | 159 | ## v0.2.10 (2015-04-06) 160 | 161 | - Various README fixes 162 | - Fixing action :delete for httpd_config rhel provider 163 | 164 | ## v0.2.9 (2015-04-04) 165 | 166 | - Adding CONTRIBUTING.md 167 | - Adding issues and source urls to metadata 168 | 169 | ## v0.2.8 (2015-03-20) 170 | 171 | - Fixing backwards compatibility with Chef 11 172 | 173 | ## v0.2.7 (2015-03-16) 174 | 175 | - Updating resources and providers to use "provides" keyword instead of the old provider_mapping file 176 | 177 | ## v0.2.6 (2015-01-20) 178 | 179 | - Fixed type mismatch bug for listen_addresses parameter 180 | - Fixing up php-zts for el5/6 181 | 182 | ## v0.2.5 (2015-01-20) 183 | 184 | - Fixing mpm_worker config rendering 185 | 186 | ## v0.2.4 (2015-01-19) 187 | 188 | - Refactoring helper methods out of resource classes. Fixing up tests. 189 | 190 | ## v0.2.3 (2015-01-17) 191 | 192 | - Fixing httpd_module 'php' on rhel family 193 | 194 | ## v0.2.2 (2015-01-12) 195 | 196 | - Adding license and description metadata 197 | 198 | ## v0.2.1 (2015-01-12) 199 | 200 | - Adding platform support metadata 201 | 202 | ## v0.2.0 (2014-12-31) 203 | 204 | - Providers now avoid "system" httpd service for default instance 205 | - Refactoring helper libraries 206 | - Refactoring package info and mpm DSLs 207 | - Adding more platform support 208 | - Refactoring specs.. removing everything but centos-5 for now 209 | 210 | ## v0.1.7 (2014-12-19) 211 | 212 | - Reverting 0.1.6 changes 213 | 214 | ## v0.1.6 (2014-12-19) 215 | 216 | - Using "include" instead of "extend" for helper methods 217 | 218 | ## v0.1.5 (2014-08-24) 219 | 220 | - Adding a modules parameter to httpd_service resource. It now loads a base set of modules by default 221 | 222 | ## v0.1.4 (2014-08-23) 223 | 224 | - Renaming magic to mime.types 225 | 226 | ## v0.1.3 (2014-08-22) 227 | 228 | - Fixing notifications by using LWRP DSL actions 229 | 230 | ## v0.1.2 (2014-08-22) 231 | 232 | - Fixing up maxkeepaliverequests in template 233 | 234 | ## v0.1.1 (2014-08-22) 235 | 236 | - Fixing up maxkeepaliverequests parameter 237 | 238 | ## v0.1.0 (2014-08-22) 239 | 240 | - Initial Beta release. Let the bug hunts begin! 241 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please refer to 2 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # This gemfile provides additional gems for testing and releasing this cookbook 2 | # It is meant to be installed on top of ChefDK which provides the majority 3 | # of the necessary gems for testing this cookbook 4 | # 5 | # Run 'chef exec bundle install' to install these dependencies 6 | 7 | source 'https://rubygems.org' 8 | 9 | gem 'community_cookbook_releaser' 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTTPD Cookbook 2 | 3 | [![Build Status](https://travis-ci.org/chef-cookbooks/httpd.svg?branch=master)](https://travis-ci.org/chef-cookbooks/httpd) [![Cookbook Version](https://img.shields.io/cookbook/v/httpd.svg)](https://supermarket.chef.io/cookbooks/httpd) 4 | 5 | The HTTPD Cookbook is a Library Cookbook that provides resource primitives for use in recipes. It is designed to be an example to reference for creating highly re-usable cross platform cookbooks. 6 | 7 | # DEPRECATED 8 | 9 | This cookbook has been deprecated in favor of the traditional apache2 cookbook 10 | 11 | ## Scope 12 | 13 | This cookbook is concerned with [The Apache HTTP Server](http://httpd.apache.org/), particularly those shipped with F/OSS Unix and Linux distributions. It does not address other httpd server implementations like Lighttpd, Nginx, or IIS. 14 | 15 | ## Requirements 16 | 17 | - Chef 12.7 or higher 18 | - Network accessible package repositories 19 | 20 | ## Platform Support 21 | 22 | The following platforms have been tested with Test Kitchen: 23 | 24 | ``` 25 | |----------------+-----+-----| 26 | | | 2.2 | 2.4 | 27 | |----------------+-----+-----| 28 | | amazon linux | | X | 29 | |----------------+-----+-----| 30 | | debian-8 | | X | 31 | |----------------+-----+-----| 32 | | debian-9 | | X | 33 | |----------------+-----+-----| 34 | | ubuntu-14.04 | | X | 35 | |----------------+-----+-----| 36 | | ubuntu-16.04 | | X | 37 | |----------------+-----+-----| 38 | | centos-6 | X | | 39 | |----------------+-----+-----| 40 | | centos-7 | | X | 41 | |----------------+-----+-----| 42 | | fedora | | X | 43 | |----------------+-----+-----| 44 | ``` 45 | 46 | ## Cookbook Dependencies 47 | 48 | - none 49 | 50 | ## Usage 51 | 52 | Place a dependency on the httpd cookbook in your cookbook's metadata.rb 53 | 54 | ```ruby 55 | depends 'httpd' 56 | ``` 57 | 58 | Then, in a recipe: 59 | 60 | ```ruby 61 | httpd_service 'default' do 62 | action [:create, :start] 63 | end 64 | 65 | httpd_config 'default' do 66 | source 'mysite.cnf.erb' 67 | notifies :restart, 'httpd_service[default]' 68 | action :create 69 | end 70 | ``` 71 | 72 | ## Resources Overview 73 | 74 | ### httpd_service 75 | 76 | The `httpd_service` does minimal configuration to get the service up and running. Its parameters can select and tune the multi-processing module, along with a small selection of server-wide configuration options such as listen_ports and run_user. 77 | 78 | The `:create` action handles package installation, support directories, socket files, and other operating system level concerns. The internal configuration file contains just enough to get the service up and running, then loads extra configuration from a conf.d directory. Further configurations are managed with the `httpd_config` resource. 79 | 80 | The `:start`, `:stop`, `:restart`, and `:reload` actions use the appropriate provider for the platform to respectively start, stop, restart, and reload the service on the machine. You should omit the `:start` action in recipes designed to build containers. 81 | 82 | `httpd_service` supports multiple Apache instances on a single machine, enabling advanced Apache configuration in scenarios where multiple servers need different loaded modules and global configurations. 83 | 84 | #### Examples 85 | 86 | ```ruby 87 | httpd_service 'default' do 88 | action :create 89 | end 90 | 91 | httpd_service 'instance-1' do 92 | listen_ports ['81', '82'] 93 | action :create 94 | end 95 | 96 | httpd_service 'an websites' do 97 | instance_name 'bob' 98 | servername 'www.computers.biz' 99 | version '2.4' 100 | mpm 'event' 101 | threadlimit '4096' 102 | listen_ports ['1234'] 103 | action :create 104 | end 105 | ``` 106 | 107 | #### Properties 108 | 109 | Most of the parameters on the `httpd_service` resource map to their CamelCase equivalents found at 110 | 111 | - `contact` - The email address rendered into the main configuration file as the ServerAdmin directive. 112 | - `hostname_lookups` - Enables DNS lookups on client IP addresses. Can be 'on' 'off' or 'double'. Defaults to 'off'. 113 | - `instance` - A string name to identify the `httpd_service` instance. By convention, this will result in configuration, log, and support directories being created and used in the form '/etc/instance-name', '/var/log/instance-name', etc. If set to 'default', the platform native defaults are used. 114 | - `keepalive` - Enables HTTP persistent connections. Values can be true or false. 115 | - `keepalivetimeout` - Amount of time the server will wait for subsequent requests on a persistent connection. 116 | - `listen_addresses` - IP addresses that the server listens to. Defaults to ['0.0.0.0']. 117 | - `listen_ports` - Ports that the server listens to. Defaults to ['80']. 118 | - `log_level` - Controls the verbosity of the ErrorLog. Defaults to 'warn'. 119 | - `maxclients` - Maximum number of connections that will be processed simultaneously. Valid only with prefork and worker MPMs. 120 | - `maxconnectionsperchild` - Limit on the number of connections that an individual child server will handle during its life. Valid with Apache 2.4 prefork, worker and event MPMs. 121 | - `maxkeepaliverequests` - Number of requests allowed on a persistent connection. Defaults to 100. 122 | - `maxrequestsperchild` - The Apache 2.2 version of maxconnectionsperchild. Still supported as of 2.4 123 | - `maxrequestworkers` - Maximum number of connections that will be processed simultaneously. Valid on prefork, worker, and event MPMs. 124 | - `maxspareservers` - Maximum number of idle child server processes. Valid only for prefork MPM. 125 | - `maxsparethreads` - Maximum number of idle threads. Valid only for worker and event MPMs. 126 | - `minspareservers` - Minimum number of idle child server processes. Valid only for preform MPM. 127 | - `minsparethreads` - Minimum number of idle threads available to handle request spikes. Valid only for worker and event MPMs. 128 | - `modules` - A list of initial Apache modules to be loaded inside the httpd_service instance. Defaults to Debian standard on 2.2 and 2.4. 129 | - `mpm` - The Multi-Processing Module to use for the `httpd_service` instance. Values can be 'prefork', 'worker', and 'event'. Defaults to 'worker' for Apache 2.2 and 'event' for Apache 2.4. 130 | - `package_name` - Name of the server package to install on the machine using the system package manager. Defaults to 'apache2' on Debian and 'httpd' on RHEL. 131 | - `run_group` - System group to start the `httpd_service` as. Defaults to 'www-data' on Debian and 'apache' on RHEL. 132 | - `run_user` - System user to start the `httpd_service` as. Defaults to 'www-data' on Debian and 'apache' on RHEL. 133 | - `servername` - Hostname and port that the server uses to identify itself. Syntax: [scheme://]fully-qualified-domain-name[:port]. Defaults to node['hostname']. 134 | - `startservers` - Number of child server processes created at startup. Valid for prefork, worker, and event MPMs. Default value differs from MPM to MPM. 135 | - `threadlimit` - Sets the upper limit on the configurable number of threads per child process. Valid on worker and event MPMs. 136 | - `threadsperchild` - Number of threads created by each child process. Valid on worker and event MPMs. 137 | - `timeout` - Amount of time the server will wait for certain events before failing a request. Defaults to '400' 138 | - `version` - Apache software version to use. Available options are '2.2', and '2.4', depending on platform. Defaults to latest available. 139 | 140 | ### httpd_module 141 | 142 | The `httpd_module` resource is responsible ensuring that an Apache module is installed on the system, as well as ensuring a load configuration snippet is dropped off at the appropriate location. 143 | 144 | #### Examples 145 | 146 | ```ruby 147 | httpd_module 'ssl' do 148 | action :create 149 | end 150 | 151 | httpd_module 'el dap' do 152 | module_name 'ldap' 153 | action :create 154 | end 155 | 156 | httpd_module 'auth_pgsql' do 157 | instance 'instance-2' 158 | action :create 159 | end 160 | ``` 161 | 162 | #### Properties 163 | 164 | - `filename` - The filename of the shared object to be rendered into the load config snippet. This can usually be omitted, and defaults to a generated value looked up in an internal map. 165 | - `httpd_version` - The version of the `httpd_service` this module is meant to be installed for. Useful on platforms that support multiple Apache versions. Defaults to the platform default. 166 | - `instance` - The `httpd_service` name to drop the load snippet off for. Defaults to 'default'. 167 | - `module_name` - The module name to install. Defaults to the `httpd_module` name. 168 | - `package_name` - The package name the module is found in. By default, this is looked up in an internal map. 169 | 170 | ### httpd_config 171 | 172 | The `httpd_config` resource is responsible for creating and deleting site specific configuration files on the system. There are slight differences in the resource implementation on platforms. The `httpd_config` resource is a thin wrapper around the core Chef template resource. Instead of a path parameter, `httpd_config` uses the instance parameter to calculate where the config is dropped off. 173 | 174 | Check the [Apache HTTP Server Project documentation](http://httpd.apache.org/docs/) for configuration specifics based on Apache version. 175 | 176 | #### Examples 177 | 178 | ```ruby 179 | httpd_config 'mysite' do 180 | source 'mysite.erb' 181 | action :create 182 | end 183 | 184 | httpd_config 'computers dot biz ssl_config' do 185 | config_name 'ssl-config' 186 | instance 'computers_dot_biz' 187 | source 'ssl_config.erb' 188 | action :create 189 | end 190 | ``` 191 | 192 | #### Properties 193 | 194 | - `config_name` - The name of the config on disk 195 | - `cookbook` - The cookbook that the source template is found in. Defaults to the current cookbook. 196 | - `httpd_version` - Used to calculate the configuration's disk path. Defaults to the platform's native Apache version. 197 | - `instance` - The `httpd_service` instance the config is meant for. Defaults to 'default' 198 | - `source` - The ERB format template source used to render the file. 199 | - `variables` - A hash of variables passed to the underlying template resource 200 | 201 | ## Maintainers 202 | 203 | This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our [team documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/COOKBOOK_TEAM.MD). To learn more about contributing to cookbooks like this see our [contributing documentation](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD), or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the [Chef Community Slack](http://community-slack.chef.io/) 204 | 205 | ## License 206 | 207 | **Copyright:** 2008-2017, Chef Software, Inc. 208 | 209 | ``` 210 | Licensed under the Apache License, Version 2.0 (the "License"); 211 | you may not use this file except in compliance with the License. 212 | You may obtain a copy of the License at 213 | 214 | http://www.apache.org/licenses/LICENSE-2.0 215 | 216 | Unless required by applicable law or agreed to in writing, software 217 | distributed under the License is distributed on an "AS IS" BASIS, 218 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 219 | See the License for the specific language governing permissions and 220 | limitations under the License. 221 | ``` 222 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | Please refer to 2 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD 3 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a chef-server or supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | examples/* 55 | Guardfile 56 | Procfile 57 | .kitchen* 58 | .rubocop.yml 59 | spec/* 60 | Rakefile 61 | .travis.yml 62 | .foodcritic 63 | .codeclimate.yml 64 | 65 | # SCM # 66 | ####### 67 | .git 68 | */.git 69 | .gitignore 70 | .gitmodules 71 | .gitconfig 72 | .gitattributes 73 | .svn 74 | */.bzr/* 75 | */.hg/* 76 | */.svn/* 77 | 78 | # Berkshelf # 79 | ############# 80 | Berksfile 81 | Berksfile.lock 82 | cookbooks/* 83 | tmp 84 | 85 | # Policyfile # 86 | ############## 87 | Policyfile.rb 88 | Policyfile.lock.json 89 | 90 | # Cookbooks # 91 | ############# 92 | CONTRIBUTING* 93 | CHANGELOG* 94 | TESTING* 95 | 96 | # Strainer # 97 | ############ 98 | Colanderfile 99 | Strainerfile 100 | .colander 101 | .strainer 102 | 103 | # Vagrant # 104 | ########### 105 | .vagrant 106 | Vagrantfile 107 | -------------------------------------------------------------------------------- /libraries/helpers.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | module Helpers 3 | def default_apache_version 4 | return '2.2' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 7 5 | return '2.2' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6 6 | return '2.4' if node['platform_family'] == 'debian' && node['platform_version'].to_i >= 8 7 | return '2.4' if node['platform_family'] == 'fedora' 8 | return '2.4' if node['platform_family'] == 'freebsd' 9 | return '2.4' if node['platform_family'] == 'suse' 10 | return '2.4' if node['platform_family'] == 'rhel' && node['platform_version'].to_i >= 7 11 | return '2.4' if node['platform'] == 'amazon' 12 | return '2.4' if node['platform'] == 'ubuntu' 13 | end 14 | 15 | def default_maxclients 16 | default_value_for(version, mpm, :maxconnectionsperchild) 17 | end 18 | 19 | def default_maxconnectionsperchild 20 | default_value_for(version, mpm, :maxconnectionsperchild) 21 | end 22 | 23 | def default_maxrequestsperchild 24 | default_value_for(version, mpm, :maxrequestsperchild) 25 | end 26 | 27 | def default_maxrequestworkers 28 | default_value_for(version, mpm, :maxrequestworkers) 29 | end 30 | 31 | def default_maxspareservers 32 | default_value_for(version, mpm, :maxspareservers) 33 | end 34 | 35 | def default_maxsparethreads 36 | default_value_for(version, mpm, :maxsparethreads) 37 | end 38 | 39 | def default_minspareservers 40 | default_value_for(version, mpm, :minspareservers) 41 | end 42 | 43 | def default_minsparethreads 44 | default_value_for(version, mpm, :minsparethreads) 45 | end 46 | 47 | def default_startservers 48 | default_value_for(version, mpm, :startservers) 49 | end 50 | 51 | def default_threadlimit 52 | default_value_for(version, mpm, :threadlimit) 53 | end 54 | 55 | def default_threadsperchild 56 | default_value_for(version, mpm, :threadsperchild) 57 | end 58 | 59 | def default_modules 60 | return %w( 61 | alias autoindex dir 62 | env mime negotiation 63 | setenvif status auth_basic 64 | deflate authz_default 65 | authz_user authz_groupfile 66 | authn_file authz_host 67 | reqtimeout 68 | ) if version == '2.2' 69 | 70 | return %w( 71 | authz_core authz_host authn_core 72 | auth_basic access_compat authn_file 73 | authz_user alias dir autoindex 74 | env mime negotiation setenvif 75 | filter deflate status 76 | ) if version == '2.4' 77 | end 78 | 79 | def default_mpm 80 | version == '2.4' ? 'event' : 'worker' 81 | end 82 | 83 | def default_package_name 84 | package_name_for_service( 85 | node['platform'], 86 | node['platform_family'], 87 | node['platform_version'], 88 | version 89 | ) 90 | end 91 | 92 | def default_run_group 93 | case node['platform_family'] 94 | when 'debian' 95 | 'www-data' 96 | when 'suse' 97 | 'www' 98 | else 99 | 'apache' 100 | end 101 | end 102 | 103 | def default_run_user 104 | case node['platform_family'] 105 | when 'debian' 106 | 'www-data' 107 | when 'suse' 108 | 'wwwrun' 109 | else 110 | 'apache' 111 | end 112 | end 113 | 114 | def config_file_relative_path 115 | case node['platform_family'] 116 | when 'debian' 117 | 'apache2.conf' 118 | else 119 | 'conf/httpd.conf' 120 | end 121 | end 122 | end 123 | end 124 | -------------------------------------------------------------------------------- /libraries/helpers_debian.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | module Helpers 3 | module Debian 4 | # version 5 | def apache_version 6 | version 7 | end 8 | 9 | # support multiple instances 10 | def apache_name 11 | "apache2-#{instance}" 12 | end 13 | 14 | def a2enmod_name 15 | "a2enmod-#{name}" 16 | end 17 | 18 | def a2dismod_name 19 | "a2dismod-#{name}" 20 | end 21 | 22 | def a2ensite_name 23 | "a2ensite-#{name}" 24 | end 25 | 26 | def a2dissite_name 27 | "a2dissite-#{name}" 28 | end 29 | 30 | def module_path 31 | "/usr/lib/apache2/modules/#{filename}" 32 | end 33 | 34 | # service things 35 | def includes 36 | return unless apache_version.to_f < 2.4 37 | [ 38 | 'mods-enabled/*.load', 39 | 'conf.d/*.conf', 40 | 'mods-enabled/*.conf', 41 | ] 42 | end 43 | 44 | def include_optionals 45 | return unless apache_version.to_f >= 2.4 46 | [ 47 | 'mods-enabled/*.load', 48 | 'conf-enabled/*.conf', 49 | 'mods-enabled/*.conf', 50 | 'sites-enabled/*.conf', 51 | ] 52 | end 53 | 54 | # calculate platform_and_version from node attributes 55 | def platform_and_version 56 | return "debian-#{node['platform_version'].to_i}" if node['platform'] == 'debian' 57 | return "ubuntu-#{node['platform_version']}" if node['platform'] == 'ubuntu' 58 | end 59 | 60 | def pid_file 61 | return "/var/run/#{apache_name}.pid" if apache_version.to_f < 2.4 62 | "/var/run/apache2/#{apache_name}.pid" 63 | end 64 | 65 | def run_dir 66 | return "/var/run/#{apache_name}" if apache_version.to_f < 2.4 67 | '/var/run/apache2' 68 | end 69 | 70 | def lock_file 71 | return "/var/lock/#{apache_name}/accept.lock" if apache_version.to_f < 2.4 72 | nil 73 | end 74 | 75 | def mutex 76 | return nil if apache_version.to_f < 2.4 77 | "file:/var/lock/#{apache_name} default" 78 | end 79 | 80 | def requires_mpm_packages? 81 | platform?('ubuntu') && node['platform_version'].to_f < 16.04 ? true : false 82 | end 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /libraries/helpers_rhel.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | module Helpers 3 | module Rhel 4 | def apache_name 5 | "httpd-#{instance}" 6 | end 7 | 8 | def libarch 9 | return 'lib64' if node['kernel']['machine'] == 'x86_64' 10 | return 'lib' if node['kernel']['machine'] == 'i686' 11 | end 12 | 13 | def module_path 14 | if platform_family?('suse') 15 | "/usr/#{libarch}/apache2/#{filename}" 16 | else 17 | "/usr/#{libarch}/httpd/modules/#{filename}" 18 | end 19 | end 20 | 21 | # suse compiles in modules and fails to start if you try to load them 22 | # like they're shared modules 23 | def built_in_module?(name) 24 | true if platform_family?('suse') && 25 | %w(systemd unixd http so access_compat core mpm_event mpm_prefork mpm_worker).include?(name) 26 | end 27 | 28 | def http_binary_name 29 | platform_family?('suse') ? 'httpd2' : 'httpd' 30 | end 31 | 32 | def elversion 33 | return 6 if node['platform'] == 'amazon' 34 | return 7 if node['platform_family'] == 'fedora' 35 | node['platform_version'].to_i 36 | end 37 | 38 | def pid_file 39 | "/var/run/#{apache_name}/httpd.pid" 40 | end 41 | 42 | def includes 43 | return unless version.to_f < 2.4 44 | [ 45 | 'conf.d/*.load', 46 | 'conf.d/*.conf', 47 | ] 48 | end 49 | 50 | def include_optionals 51 | return unless version.to_f >= 2.4 52 | [ 53 | 'conf.d/*.load', 54 | 'conf.modules.d/*.load', 55 | 'conf.d/*.conf', 56 | 'conf.modules.d/*.conf', 57 | ] 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /libraries/httpd_config.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdConfig < Chef::Resource 3 | property :config_name, String, name_property: true 4 | property :cookbook, [String, nil], default: nil 5 | property :httpd_version, String, default: lazy { default_apache_version } 6 | property :instance, String, default: 'default' 7 | property :source, [String, nil], default: nil 8 | property :variables, [Hash], default: {} 9 | 10 | include HttpdCookbook::Helpers 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /libraries/httpd_config_debian.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdConfigDebian < HttpdConfig 3 | use_automatic_resource_name 4 | provides :httpd_config, platform_family: 'debian' 5 | 6 | action :create do 7 | if new_resource.httpd_version.to_f < 2.4 8 | directory "/etc/#{apache_name}/conf.d" do 9 | owner 'root' 10 | group 'root' 11 | mode '0755' 12 | recursive true 13 | action :create 14 | end 15 | 16 | template "/etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf" do 17 | owner 'root' 18 | group 'root' 19 | mode '0644' 20 | variables(new_resource.variables) 21 | source new_resource.source 22 | cookbook new_resource.cookbook 23 | sensitive new_resource.sensitive if new_resource.sensitive 24 | action :create 25 | end 26 | else 27 | directory "/etc/#{apache_name}/conf-available" do 28 | owner 'root' 29 | group 'root' 30 | mode '0755' 31 | recursive true 32 | action :create 33 | end 34 | 35 | template "/etc/#{apache_name}/conf-available/#{new_resource.config_name}.conf" do 36 | owner 'root' 37 | group 'root' 38 | mode '0644' 39 | variables(new_resource.variables) 40 | source new_resource.source 41 | cookbook new_resource.cookbook 42 | sensitive new_resource.sensitive if new_resource.sensitive 43 | action :create 44 | end 45 | 46 | directory "/etc/#{apache_name}/conf-enabled" do 47 | owner 'root' 48 | group 'root' 49 | mode '0755' 50 | recursive true 51 | action :create 52 | end 53 | 54 | link "/etc/#{apache_name}/conf-enabled/#{new_resource.config_name}.conf" do 55 | to "/etc/#{apache_name}/conf-available/#{new_resource.config_name}.conf" 56 | action :create 57 | end 58 | end 59 | end 60 | 61 | action :delete do 62 | if new_resource.httpd_version.to_f < 2.4 63 | file "/etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf" do 64 | action :delete 65 | end 66 | else 67 | file "/etc/#{apache_name}/conf-available/#{new_resource.config_name}.conf" do 68 | action :delete 69 | end 70 | 71 | link "/etc/#{apache_name}/conf-enabled/#{new_resource.config_name}.conf" do 72 | to "/etc/#{apache_name}/conf-available/#{new_resource.config_name}.conf" 73 | action :delete 74 | end 75 | end 76 | end 77 | 78 | include HttpdCookbook::Helpers::Debian 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /libraries/httpd_config_rhel.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdConfigRhel < HttpdConfig 3 | use_automatic_resource_name 4 | provides :httpd_config, platform_family: %w(rhel fedora suse amazon) 5 | 6 | action :create do 7 | directory "/etc/#{apache_name}/conf.d" do 8 | owner 'root' 9 | group 'root' 10 | mode '0755' 11 | recursive true 12 | action :create 13 | end 14 | 15 | template "/etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf" do 16 | owner 'root' 17 | group 'root' 18 | mode '0644' 19 | variables(new_resource.variables) 20 | source new_resource.source 21 | cookbook new_resource.cookbook 22 | sensitive new_resource.sensitive if new_resource.sensitive 23 | action :create 24 | end 25 | end 26 | 27 | action :delete do 28 | file "/etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf" do 29 | action :delete 30 | end 31 | end 32 | 33 | include HttpdCookbook::Helpers::Rhel 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /libraries/httpd_module.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdModule < Chef::Resource 3 | ##################### 4 | # Resource properties 5 | ##################### 6 | property :filename, String, default: lazy { default_filename } 7 | property :httpd_version, String, default: lazy { default_apache_version } 8 | property :instance, String, default: 'default' 9 | property :module_name, String, name_property: true 10 | property :package_name, String, default: lazy { default_package_name } 11 | property :symbolname, default: lazy { default_symbolname } 12 | include HttpdCookbook::Helpers 13 | 14 | ################ 15 | # Helper Methods 16 | ################ 17 | def default_filename 18 | case node['platform_family'] 19 | when 'debian' 20 | return 'libphp5.so' if module_name == 'php5' 21 | when 'rhel' 22 | return 'libmodnss.so' if module_name == 'nss' 23 | return 'mod_rev.so' if module_name == 'revocator' 24 | return 'libphp5.so' if module_name == 'php' 25 | return 'libphp5-zts.so' if module_name == 'php-zts' 26 | end 27 | "mod_#{module_name}.so" 28 | end 29 | 30 | def default_package_name 31 | package_name_for_module( 32 | module_name, 33 | httpd_version, 34 | node['platform'], 35 | node['platform_family'], 36 | node['platform_version'] 37 | ) 38 | end 39 | 40 | def default_symbolname 41 | return 'php5_module' if module_name == 'php' 42 | return 'php5_module' if module_name == 'php-zts' 43 | "#{module_name}_module" 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /libraries/httpd_module_debian.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdModuleDebian < HttpdModule 3 | use_automatic_resource_name 4 | 5 | provides :httpd_module, platform_family: 'debian' 6 | 7 | action :create do 8 | package new_resource.package_name do 9 | action :install 10 | end 11 | 12 | directory "/etc/#{apache_name}/mods-available" do 13 | owner 'root' 14 | group 'root' 15 | mode '0755' 16 | recursive true 17 | action :create 18 | end 19 | 20 | directory "/etc/#{apache_name}/mods-enabled" do 21 | owner 'root' 22 | group 'root' 23 | mode '0755' 24 | recursive true 25 | action :create 26 | end 27 | 28 | template "/etc/#{apache_name}/mods-available/#{new_resource.module_name}.load" do 29 | source 'module_load.erb' 30 | owner 'root' 31 | group 'root' 32 | mode '0644' 33 | variables( 34 | module_name: new_resource.symbolname, 35 | module_path: module_path 36 | ) 37 | cookbook 'httpd' 38 | action :create 39 | end 40 | 41 | link "/etc/#{apache_name}/mods-enabled/#{new_resource.module_name}.load" do 42 | to "/etc/#{apache_name}/mods-available/#{new_resource.module_name}.load" 43 | action :create 44 | end 45 | end 46 | 47 | action :delete do 48 | file "/etc/#{apache_name}/mods-available/#{new_resource.module_name}.load" do 49 | action :delete 50 | end 51 | 52 | link "/etc/#{apache_name}/mods-enabled/#{new_resource.module_name}.load" do 53 | action :delete 54 | end 55 | end 56 | 57 | include HttpdCookbook::Helpers::Debian 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /libraries/httpd_module_rhel.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdModuleRhel < HttpdModule 3 | use_automatic_resource_name 4 | provides :httpd_module, platform_family: %w(rhel fedora suse amazon) 5 | 6 | action :create do 7 | package new_resource.package_name do 8 | action :install 9 | end 10 | 11 | # 2.2 vs 2.4 12 | if new_resource.httpd_version.to_f < 2.4 13 | directory "/etc/#{apache_name}/conf.d" do 14 | owner 'root' 15 | group 'root' 16 | recursive true 17 | action :create 18 | end 19 | 20 | template "/etc/#{apache_name}/conf.d/#{new_resource.module_name}.load" do 21 | source 'module_load.erb' 22 | owner 'root' 23 | group 'root' 24 | mode '0644' 25 | variables( 26 | module_name: new_resource.symbolname, 27 | module_path: module_path 28 | ) 29 | cookbook 'httpd' 30 | action :create 31 | end 32 | elsif !built_in_module?(new_resource.module_name) # don't load built-ins on opensuse 33 | directory "/etc/#{apache_name}/conf.modules.d" do 34 | owner 'root' 35 | group 'root' 36 | recursive true 37 | action :create 38 | end 39 | 40 | template "/etc/#{apache_name}/conf.modules.d/#{new_resource.module_name}.load" do 41 | source 'module_load.erb' 42 | owner 'root' 43 | group 'root' 44 | mode '0644' 45 | variables( 46 | module_name: new_resource.symbolname, 47 | module_path: module_path 48 | ) 49 | cookbook 'httpd' 50 | action :create 51 | end 52 | end 53 | end 54 | 55 | action :delete do 56 | if new_resource.httpd_version.to_f < 2.4 57 | file "/etc/#{apache_name}/conf.d/#{new_resource.module_name}.load" do 58 | action :delete 59 | end 60 | else 61 | file "/etc/#{apache_name}/conf.modules.d/#{new_resource.module_name}.load" do 62 | action :delete 63 | end 64 | end 65 | end 66 | 67 | include HttpdCookbook::Helpers::Rhel 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /libraries/httpd_service.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdService < Chef::Resource 3 | property :contact, String, default: 'webmaster@localhost' 4 | property :hostname_lookups, String, default: 'off' 5 | property :instance, String, name_property: true 6 | property :keepalive, [TrueClass, FalseClass], default: true 7 | property :keepalivetimeout, String, default: '5' 8 | property :listen_addresses, [String, Array], default: ['0.0.0.0'] 9 | property :listen_ports, [String, Array], default: %w(80) 10 | property :log_level, String, default: 'warn' 11 | property :version, String, default: lazy { default_apache_version } 12 | property :maxclients, [String, nil], default: lazy { default_maxclients } 13 | property :maxconnectionsperchild, [String, nil], default: lazy { default_maxconnectionsperchild } 14 | property :maxkeepaliverequests, [String], default: '100' 15 | property :maxrequestsperchild, [String, nil], default: lazy { default_maxrequestsperchild } 16 | property :maxrequestworkers, [String, nil], default: lazy { default_maxrequestworkers } 17 | property :maxspareservers, [String, nil], default: lazy { default_maxspareservers } 18 | property :maxsparethreads, [String, nil], default: lazy { default_maxsparethreads } 19 | property :minspareservers, [String, nil], default: lazy { default_minspareservers } 20 | property :minsparethreads, [String, nil], default: lazy { default_minsparethreads } 21 | property :modules, Array, default: lazy { default_modules } 22 | property :mpm, String, default: lazy { default_mpm } 23 | property :package_name, String, default: lazy { default_package_name } 24 | property :run_group, String, default: lazy { default_run_group } 25 | property :run_user, String, default: lazy { default_run_user } 26 | property :servername, String, default: lazy { node['hostname'] } 27 | property :startservers, String, default: lazy { default_startservers } 28 | property :threadlimit, [String, nil], default: lazy { default_threadlimit } 29 | property :threadsperchild, [String, nil], default: lazy { default_threadsperchild } 30 | property :timeout, String, default: '400' 31 | 32 | include HttpdCookbook::Helpers 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /libraries/httpd_service_debian.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceDebian < HttpdService 3 | action :create do 4 | # We need to dynamically render the resource name into the title in 5 | # order to ensure uniqueness. This avoids cloning via 6 | # CHEF-3694 and allows ChefSpec to work properly. 7 | 8 | package new_resource.package_name do 9 | action :install 10 | end 11 | 12 | # In provider subclass 13 | create_stop_system_service 14 | 15 | # support directories 16 | directory "/var/cache/#{apache_name}" do 17 | owner 'root' 18 | group 'root' 19 | mode '0755' 20 | action :create 21 | end 22 | 23 | directory "/var/log/#{apache_name}" do 24 | owner 'root' 25 | group 'adm' 26 | mode '0755' 27 | action :create 28 | end 29 | 30 | # The init scripts that ship with 2.2 and 2.4 on 31 | # debian/ubuntu behave differently. 2.2 places in /var/run/apache-name/, 32 | # and 2.4 stores pids as /var/run/apache2/apache2-service_name 33 | if new_resource.version.to_f < 2.4 34 | directory "/var/run/#{apache_name}" do 35 | owner 'root' 36 | group 'adm' 37 | mode '0755' 38 | action :create 39 | end 40 | else 41 | directory '/var/run/apache2' do 42 | owner 'root' 43 | group 'adm' 44 | mode '0755' 45 | action :create 46 | end 47 | end 48 | 49 | # configuration directories 50 | directory "/etc/#{apache_name}" do 51 | owner 'root' 52 | group 'root' 53 | mode '0755' 54 | recursive true 55 | action :create 56 | end 57 | 58 | if apache_version.to_f < 2.4 59 | directory "/etc/#{apache_name}/conf.d" do 60 | owner 'root' 61 | group 'root' 62 | mode '0755' 63 | action :create 64 | end 65 | else 66 | directory "/etc/#{apache_name}/conf-available" do 67 | owner 'root' 68 | group 'root' 69 | mode '0755' 70 | action :create 71 | end 72 | 73 | directory "/etc/#{apache_name}/conf-enabled" do 74 | owner 'root' 75 | group 'root' 76 | mode '0755' 77 | action :create 78 | end 79 | 80 | directory "/var/lock/#{apache_name}" do 81 | owner new_resource.run_user 82 | group new_resource.run_group 83 | mode '0755' 84 | action :create 85 | end 86 | end 87 | 88 | directory "/etc/#{apache_name}/mods-available" do 89 | owner 'root' 90 | group 'root' 91 | mode '0755' 92 | action :create 93 | end 94 | 95 | directory "/etc/#{apache_name}/mods-enabled" do 96 | owner 'root' 97 | group 'root' 98 | mode '0755' 99 | action :create 100 | end 101 | 102 | directory "/etc/#{apache_name}/sites-available" do 103 | owner 'root' 104 | group 'root' 105 | mode '0755' 106 | action :create 107 | end 108 | 109 | directory "/etc/#{apache_name}/sites-enabled" do 110 | owner 'root' 111 | group 'root' 112 | mode '0755' 113 | action :create 114 | end 115 | 116 | # envvars 117 | template "/etc/#{apache_name}/envvars" do 118 | source 'envvars.erb' 119 | owner 'root' 120 | group 'root' 121 | mode '0644' 122 | variables( 123 | run_user: new_resource.run_user, 124 | run_group: new_resource.run_group, 125 | pid_file: pid_file, 126 | run_dir: run_dir, 127 | lock_dir: "/var/lock/#{apache_name}", 128 | log_dir: "/var/log/#{apache_name}" 129 | ) 130 | cookbook 'httpd' 131 | action :create 132 | end 133 | 134 | # utility scripts 135 | template '/usr/sbin/a2enmod' do 136 | source "#{apache_version}/scripts/a2enmod.erb" 137 | owner 'root' 138 | group 'root' 139 | mode '0755' 140 | cookbook 'httpd' 141 | action :create 142 | end 143 | 144 | %w( a2enmod_name a2dismod_name a2ensite_name a2dissite_name ).each do |dir| 145 | link "/usr/sbin/#{dir}" do 146 | to '/usr/sbin/a2enmod' 147 | owner 'root' 148 | group 'root' 149 | not_if "test -f /usr/sbin/#{dir}" 150 | action :create 151 | end 152 | end 153 | 154 | # configuration files 155 | template "/etc/#{apache_name}/mime.types" do 156 | source 'magic.erb' 157 | owner 'root' 158 | group 'root' 159 | mode '0644' 160 | cookbook 'httpd' 161 | action :create 162 | end 163 | 164 | file "/etc/#{apache_name}/ports.conf" do 165 | action :delete 166 | end 167 | 168 | template "/etc/#{apache_name}/apache2.conf" do 169 | source 'httpd.conf.erb' 170 | owner 'root' 171 | group 'root' 172 | mode '0644' 173 | variables( 174 | config: new_resource, 175 | error_log: "/var/log/#{apache_name}/error_log", 176 | include_optionals: include_optionals, 177 | includes: includes, 178 | lock_file: lock_file, 179 | mutex: mutex, 180 | pid_file: pid_file, 181 | run_group: new_resource.run_group, 182 | run_user: new_resource.run_user, 183 | server_root: "/etc/#{apache_name}", 184 | servername: new_resource.servername 185 | ) 186 | cookbook 'httpd' 187 | action :create 188 | end 189 | 190 | # mpm configuration 191 | # 192 | # With Apache 2.2, only one mpm package can be installed 193 | # at any given moment. Installing one will uninstall the 194 | # others. Therefore, all service instances on debian 7, or 195 | # ubuntu below 14.04 will need to have the same MPM per 196 | # machine or container or things can get weird. 197 | package "apache2-mpm-#{new_resource.mpm}" do 198 | action :install 199 | only_if { requires_mpm_packages? } 200 | end 201 | 202 | # older apache has mpm statically compiled into binaries 203 | 204 | httpd_module "mpm_#{new_resource.mpm}" do 205 | instance new_resource.instance 206 | httpd_version new_resource.version 207 | package_name new_resource.package_name 208 | not_if { new_resource.version.to_f < 2.4 } 209 | action :create 210 | end 211 | 212 | # MPM configuration 213 | httpd_config "mpm_#{new_resource.mpm}" do 214 | instance new_resource.instance 215 | source 'mpm.conf.erb' 216 | variables( 217 | maxclients: new_resource.maxclients, 218 | maxconnectionsperchild: new_resource.maxconnectionsperchild, 219 | maxrequestsperchild: new_resource.maxrequestsperchild, 220 | maxrequestworkers: new_resource.maxrequestworkers, 221 | maxspareservers: new_resource.maxspareservers, 222 | maxsparethreads: new_resource.maxsparethreads, 223 | minspareservers: new_resource.minspareservers, 224 | minsparethreads: new_resource.minsparethreads, 225 | mpm: new_resource.mpm, 226 | startservers: new_resource.startservers, 227 | threadlimit: new_resource.threadlimit, 228 | threadsperchild: new_resource.threadsperchild 229 | ) 230 | cookbook 'httpd' 231 | action :create 232 | end 233 | 234 | # make sure there is only one MPM loaded 235 | case new_resource.mpm 236 | when 'prefork' 237 | httpd_config 'mpm_worker' do 238 | instance new_resource.instance 239 | action :delete 240 | end 241 | 242 | httpd_config 'mpm_event' do 243 | instance new_resource.instance 244 | action :delete 245 | end 246 | when 'worker' 247 | httpd_config 'mpm_prefork' do 248 | instance new_resource.instance 249 | action :delete 250 | end 251 | 252 | httpd_config 'mpm_event' do 253 | instance new_resource.instance 254 | action :delete 255 | end 256 | when 'event' 257 | httpd_config 'mpm_prefork' do 258 | instance new_resource.instance 259 | action :delete 260 | end 261 | 262 | httpd_config 'mpm_worker' do 263 | instance new_resource.instance 264 | action :delete 265 | end 266 | end 267 | 268 | # Install core modules 269 | new_resource.modules.each do |mod| 270 | httpd_module mod do 271 | instance new_resource.instance 272 | httpd_version new_resource.version 273 | package_name new_resource.package_name 274 | action :create 275 | end 276 | end 277 | 278 | # generate the sysvinit or systemd service (defined in subclass) 279 | create_setup_service 280 | end 281 | 282 | action :delete do 283 | delete_stop_service 284 | 285 | # NOTE: Users typically provide minimal attributes in a resource block 286 | # calling the :delete action. Do not expect the user to set the version 287 | # attribute. Instead, clean up files created for all possible versions. 288 | 289 | # FIXME: template[/usr/sbin/a2enmod], and directory[/var/run/apache2] are 290 | # shared by all httpd_service resources and never get cleaned up. 291 | 292 | [a2enmod_name, a2dismod_name, a2ensite_name, a2dissite_name].each do |dir| 293 | link "/usr/sbin/#{dir}" do 294 | action :delete 295 | end 296 | end 297 | 298 | %W(/etc/#{apache_name} 299 | /var/cache/#{apache_name} 300 | /var/lock/#{apache_name} 301 | /var/log/#{apache_name} 302 | /var/run/#{apache_name}).each do |dir| 303 | directory dir do 304 | recursive true 305 | action :delete 306 | end 307 | end 308 | end 309 | 310 | include HttpdCookbook::Helpers::Debian 311 | end 312 | end 313 | -------------------------------------------------------------------------------- /libraries/httpd_service_debian_systemd.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceDebianSystemd < HttpdServiceDebian 3 | use_automatic_resource_name 4 | 5 | provides :httpd_service, platform_family: %w(debian) do 6 | Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) 7 | end 8 | 9 | action :start do 10 | service apache_name do 11 | supports restart: true, reload: true, status: true 12 | provider Chef::Provider::Service::Init::Systemd 13 | action [:start, :enable] 14 | end 15 | end 16 | 17 | action :stop do 18 | service apache_name do 19 | supports restart: true, reload: true, status: true 20 | provider Chef::Provider::Service::Init::Systemd 21 | action :stop 22 | end 23 | end 24 | 25 | action :restart do 26 | service apache_name do 27 | supports restart: true, reload: true, status: true 28 | provider Chef::Provider::Service::Init::Systemd 29 | action :restart 30 | end 31 | end 32 | 33 | action :reload do 34 | service apache_name do 35 | supports restart: true, reload: true, status: true 36 | provider Chef::Provider::Service::Init::Systemd 37 | action :reload 38 | end 39 | end 40 | 41 | action_class.class_eval do 42 | def create_stop_system_service 43 | service 'apache2' do 44 | provider Chef::Provider::Service::Init::Systemd 45 | action [:stop, :disable] 46 | end 47 | end 48 | 49 | def create_setup_service 50 | directory "/run/#{apache_name}" do 51 | owner 'root' 52 | group 'root' 53 | mode '0755' 54 | recursive true 55 | action :create 56 | end 57 | 58 | template "/etc/systemd/system/#{apache_name}.service" do 59 | source 'systemd/httpd.service.erb' 60 | owner 'root' 61 | group 'root' 62 | mode '0644' 63 | cookbook 'httpd' 64 | variables( 65 | binary_name: 'apache2', 66 | apache_name: apache_name, 67 | config_relative_path: config_file_relative_path 68 | ) 69 | action :create 70 | end 71 | 72 | directory "/etc/systemd/system/#{apache_name}.service.d" do 73 | owner 'root' 74 | group 'root' 75 | mode '0755' 76 | recursive true 77 | action :create 78 | end 79 | 80 | template "/usr/lib/tmpfiles.d/#{apache_name}.conf" do 81 | source 'systemd/httpd.conf.erb' 82 | owner 'root' 83 | group 'root' 84 | mode '0644' 85 | cookbook 'httpd' 86 | variables( 87 | apache_name: apache_name, 88 | run_user: new_resource.run_user, 89 | run_group: new_resource.run_group 90 | ) 91 | end 92 | end 93 | 94 | def delete_stop_service 95 | service apache_name do 96 | supports restart: true, reload: true, status: true 97 | provider Chef::Provider::Service::Init::Systemd 98 | action [:stop, :disable] 99 | end 100 | 101 | %W(/etc/systemd/system/#{apache_name}.service.d 102 | /run/#{apache_name}).each do |path| 103 | directory path do 104 | recursive true 105 | action :delete 106 | end 107 | end 108 | 109 | %W(/usr/lib/tmpfiles.d/#{apache_name}.conf 110 | /etc/systemd/system/#{apache_name}.service).each do |path| 111 | file path do 112 | action :delete 113 | end 114 | end 115 | end 116 | end 117 | end 118 | end 119 | -------------------------------------------------------------------------------- /libraries/httpd_service_debian_sysvinit.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceDebianSysvinit < HttpdServiceDebian 3 | use_automatic_resource_name 4 | provides :httpd_service, platform_family: 'debian' 5 | 6 | action :start do 7 | # service management 8 | service apache_name do 9 | supports restart: true, reload: true, status: true 10 | provider Chef::Provider::Service::Init::Debian 11 | action [:start, :enable] 12 | end 13 | end 14 | 15 | action :stop do 16 | service apache_name do 17 | supports restart: true, reload: true, status: true 18 | provider Chef::Provider::Service::Init::Debian 19 | action :stop 20 | end 21 | end 22 | 23 | action :restart do 24 | service apache_name do 25 | supports restart: true, reload: true, status: true 26 | provider Chef::Provider::Service::Init::Debian 27 | action :restart 28 | end 29 | end 30 | 31 | action :reload do 32 | service apache_name do 33 | supports restart: true, reload: true, status: true 34 | provider Chef::Provider::Service::Init::Debian 35 | action :reload 36 | end 37 | end 38 | 39 | action_class do 40 | def create_stop_system_service 41 | service 'apache2' do 42 | provider Chef::Provider::Service::Init::Debian 43 | supports restart: true, status: true 44 | action [:stop, :disable] 45 | end 46 | end 47 | 48 | def create_setup_service 49 | # init script 50 | template "/etc/init.d/#{apache_name}" do 51 | source "#{apache_version}/sysvinit/#{platform_and_version}/apache2.erb" 52 | owner 'root' 53 | group 'root' 54 | mode '0755' 55 | variables(apache_name: apache_name) 56 | cookbook 'httpd' 57 | action :create 58 | end 59 | end 60 | 61 | def delete_stop_service 62 | service apache_name do 63 | supports restart: true, reload: true, status: true 64 | provider Chef::Provider::Service::Init::Debian 65 | only_if { ::File.exist?("/etc/init.d/#{apache_name}") } 66 | action [:disable, :stop] 67 | end 68 | 69 | file "/etc/init.d/#{apache_name}" do 70 | action :delete 71 | end 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /libraries/httpd_service_rhel.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceRhel < HttpdService 3 | action :create do 4 | # FIXME: make into resource parameters 5 | lock_file = nil 6 | mutex = nil 7 | 8 | # 9 | # Chef resources 10 | # 11 | # software installation 12 | package new_resource.package_name 13 | 14 | # Defined in subclass 15 | create_stop_system_service 16 | 17 | # achieve parity with modules statically compiled into 18 | # debian and ubuntu 19 | if new_resource.version.to_f < 2.4 20 | %w( log_config logio ).each do |m| 21 | httpd_module m do 22 | httpd_version new_resource.version 23 | instance new_resource.instance 24 | action :create 25 | end 26 | end 27 | else 28 | %w( log_config logio unixd version watchdog ).each do |m| 29 | httpd_module m do 30 | httpd_version new_resource.version 31 | instance new_resource.instance 32 | action :create 33 | end 34 | end 35 | end 36 | 37 | # httpd binary symlinks 38 | link "/usr/sbin/#{apache_name}" do 39 | to "/usr/sbin/#{http_binary_name}" 40 | action :create 41 | not_if { apache_name == 'httpd' } 42 | end 43 | 44 | # MPM loading 45 | if new_resource.version.to_f < 2.4 46 | link "/usr/sbin/#{apache_name}.worker" do 47 | to '/usr/sbin/httpd.worker' 48 | action :create 49 | not_if { apache_name == 'httpd' } 50 | end 51 | 52 | link "/usr/sbin/#{apache_name}.event" do 53 | to '/usr/sbin/httpd.event' 54 | action :create 55 | not_if { apache_name == 'httpd' } 56 | end 57 | else 58 | httpd_module "mpm_#{new_resource.mpm}" do 59 | httpd_version new_resource.version 60 | instance new_resource.instance 61 | action :create 62 | end 63 | end 64 | 65 | # MPM configuration 66 | httpd_config "mpm_#{new_resource.mpm}" do 67 | instance new_resource.instance 68 | source 'mpm.conf.erb' 69 | variables( 70 | maxclients: new_resource.maxclients, 71 | maxconnectionsperchild: new_resource.maxconnectionsperchild, 72 | maxrequestsperchild: new_resource.maxrequestsperchild, 73 | maxrequestworkers: new_resource.maxrequestworkers, 74 | maxspareservers: new_resource.maxspareservers, 75 | maxsparethreads: new_resource.maxsparethreads, 76 | minspareservers: new_resource.minspareservers, 77 | minsparethreads: new_resource.minsparethreads, 78 | mpm: new_resource.mpm, 79 | startservers: new_resource.startservers, 80 | threadlimit: new_resource.threadlimit, 81 | threadsperchild: new_resource.threadsperchild 82 | ) 83 | cookbook 'httpd' 84 | action :create 85 | end 86 | 87 | # configuration directories 88 | directory "/etc/#{apache_name}" do 89 | user 'root' 90 | group 'root' 91 | mode '0755' 92 | recursive true 93 | action :create 94 | end 95 | 96 | directory "/etc/#{apache_name}/conf" do 97 | user 'root' 98 | group 'root' 99 | mode '0755' 100 | recursive true 101 | action :create 102 | end 103 | 104 | directory "/etc/#{apache_name}/conf.d" do 105 | path "/etc/#{apache_name}/conf.d" 106 | user 'root' 107 | group 'root' 108 | mode '0755' 109 | recursive true 110 | action :create 111 | end 112 | 113 | directory "/etc/#{apache_name}/conf.modules.d" do 114 | user 'root' 115 | group 'root' 116 | mode '0755' 117 | recursive true 118 | only_if { new_resource.version.to_f >= 2.4 } 119 | action :create 120 | end 121 | 122 | # support directories 123 | directory "/usr/#{libarch}/httpd/modules" do 124 | user 'root' 125 | group 'root' 126 | mode '0755' 127 | recursive true 128 | action :create 129 | end 130 | 131 | directory "/var/log/#{apache_name}" do 132 | user 'root' 133 | group 'root' 134 | mode '0755' 135 | recursive true 136 | action :create 137 | end 138 | 139 | link "/etc/#{apache_name}/logs" do 140 | to "../../var/log/#{apache_name}" 141 | action :create 142 | end 143 | 144 | link "/etc/#{apache_name}/modules" do 145 | to "../../usr/#{libarch}/httpd/modules" 146 | action :create 147 | end 148 | 149 | # /var/run 150 | directory "/var/run/#{apache_name}" do 151 | user 'root' 152 | group 'root' 153 | mode '0755' 154 | recursive true 155 | action :create 156 | end 157 | 158 | link "/etc/#{apache_name}/run" do 159 | to "../../var/run/#{apache_name}" 160 | action :create 161 | end 162 | 163 | # configuration files 164 | template "/etc/#{apache_name}/conf/mime.types" do 165 | source 'magic.erb' 166 | owner 'root' 167 | group 'root' 168 | mode '0644' 169 | cookbook 'httpd' 170 | action :create 171 | end 172 | 173 | template "/etc/#{apache_name}/conf/httpd.conf" do 174 | source 'httpd.conf.erb' 175 | owner 'root' 176 | group 'root' 177 | mode '0644' 178 | variables( 179 | config: new_resource, 180 | error_log: "/var/log/#{apache_name}/error_log", 181 | include_optionals: include_optionals, 182 | includes: includes, 183 | lock_file: lock_file, 184 | mutex: mutex, 185 | pid_file: pid_file, 186 | run_group: new_resource.run_group, 187 | run_user: new_resource.run_user, 188 | server_root: "/etc/#{apache_name}", 189 | servername: new_resource.servername 190 | ) 191 | cookbook 'httpd' 192 | action :create 193 | end 194 | 195 | # Install core modules 196 | new_resource.modules.each do |mod| 197 | httpd_module mod do 198 | instance new_resource.instance 199 | httpd_version new_resource.version 200 | action :create 201 | end 202 | end 203 | 204 | # generate the sysvinit or systemd service (defined in subclass) 205 | create_setup_service 206 | end 207 | 208 | action :delete do 209 | delete_stop_service 210 | 211 | # NOTE: Users typically provide minimal attributes in a resource block 212 | # calling the :delete action. Do not expect the user to set the version 213 | # attribute. Instead, clean up files created for all possible versions. 214 | 215 | %W(/usr/sbin/#{apache_name} 216 | /usr/sbin/#{apache_name}.worker 217 | /usr/sbin/#{apache_name}.event).each do |path| 218 | link path do 219 | action :delete 220 | end 221 | end 222 | 223 | # configuration directories and logs 224 | %W(/etc/#{apache_name} 225 | /var/log/#{apache_name} 226 | /var/run/#{apache_name}).each do |dir| 227 | directory dir do 228 | recursive true 229 | action :delete 230 | end 231 | end 232 | end 233 | 234 | include HttpdCookbook::Helpers::Rhel 235 | end 236 | end 237 | -------------------------------------------------------------------------------- /libraries/httpd_service_rhel_systemd.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceRhelSystemd < HttpdServiceRhel 3 | use_automatic_resource_name 4 | 5 | provides :httpd_service, platform_family: %w(rhel fedora suse) do 6 | Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) 7 | end 8 | 9 | action :start do 10 | service apache_name do 11 | supports restart: true, reload: true, status: true 12 | provider Chef::Provider::Service::Init::Systemd 13 | action [:start, :enable] 14 | end 15 | end 16 | 17 | action :stop do 18 | service apache_name do 19 | supports restart: true, reload: true, status: true 20 | provider Chef::Provider::Service::Init::Systemd 21 | action :stop 22 | end 23 | end 24 | 25 | action :restart do 26 | service apache_name do 27 | supports restart: true, reload: true, status: true 28 | provider Chef::Provider::Service::Init::Systemd 29 | action :restart 30 | end 31 | end 32 | 33 | action :reload do 34 | service apache_name do 35 | supports restart: true, reload: true, status: true 36 | provider Chef::Provider::Service::Init::Systemd 37 | action :reload 38 | end 39 | end 40 | 41 | action_class do 42 | def create_stop_system_service 43 | service apache_name do 44 | provider Chef::Provider::Service::Init::Systemd 45 | action [:stop, :disable] 46 | end 47 | end 48 | 49 | def create_setup_service 50 | httpd_module 'systemd' do 51 | httpd_version new_resource.version 52 | instance new_resource.instance 53 | notifies :reload, "service[#{apache_name}]" 54 | action :create 55 | end 56 | 57 | directory "/run/#{apache_name}" do 58 | owner 'root' 59 | group 'root' 60 | mode '0755' 61 | recursive true 62 | action :create 63 | end 64 | 65 | template "/etc/systemd/system/#{apache_name}.service" do 66 | source 'systemd/httpd.service.erb' 67 | owner 'root' 68 | group 'root' 69 | mode '0644' 70 | cookbook 'httpd' 71 | variables( 72 | binary_name: apache_name, 73 | apache_name: apache_name, 74 | config_relative_path: config_file_relative_path 75 | ) 76 | action :create 77 | end 78 | 79 | directory "/etc/systemd/system/#{apache_name}.service.d" do 80 | owner 'root' 81 | group 'root' 82 | mode '0755' 83 | recursive true 84 | action :create 85 | end 86 | 87 | template "/usr/lib/tmpfiles.d/#{apache_name}.conf" do 88 | source 'systemd/httpd.conf.erb' 89 | owner 'root' 90 | group 'root' 91 | mode '0644' 92 | cookbook 'httpd' 93 | variables( 94 | apache_name: apache_name, 95 | run_user: new_resource.run_user, 96 | run_group: new_resource.run_group 97 | ) 98 | end 99 | 100 | service apache_name do 101 | supports restart: true, reload: true, status: true 102 | provider Chef::Provider::Service::Init::Systemd 103 | action :nothing 104 | end 105 | end 106 | 107 | def delete_stop_service 108 | service apache_name do 109 | supports restart: true, reload: true, status: true 110 | provider Chef::Provider::Service::Init::Systemd 111 | action [:stop, :disable] 112 | end 113 | 114 | %W(/etc/systemd/system/#{apache_name}.service.d 115 | /run/#{apache_name}).each do |path| 116 | directory path do 117 | recursive true 118 | action :delete 119 | end 120 | end 121 | 122 | %W(/usr/lib/tmpfiles.d/#{apache_name}.conf 123 | /etc/systemd/system/#{apache_name}.service).each do |path| 124 | file path do 125 | action :delete 126 | end 127 | end 128 | end 129 | end 130 | end 131 | end 132 | -------------------------------------------------------------------------------- /libraries/httpd_service_rhel_sysvinit.rb: -------------------------------------------------------------------------------- 1 | module HttpdCookbook 2 | class HttpdServiceRhelSysvinit < HttpdServiceRhel 3 | use_automatic_resource_name 4 | 5 | provides :httpd_service, platform_family: %w(rhel fedora suse amazon) do 6 | Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) 7 | end 8 | 9 | action :start do 10 | service apache_name do 11 | supports status: true 12 | provider Chef::Provider::Service::Init::Redhat 13 | action [:start, :enable] 14 | end 15 | end 16 | 17 | action :stop do 18 | service apache_name do 19 | supports status: true 20 | provider Chef::Provider::Service::Init::Redhat 21 | action :stop 22 | end 23 | end 24 | 25 | action :restart do 26 | service apache_name do 27 | supports restart: true 28 | provider Chef::Provider::Service::Init::Redhat 29 | action :restart 30 | end 31 | end 32 | 33 | action :reload do 34 | service apache_name do 35 | supports reload: true 36 | provider Chef::Provider::Service::Init::Redhat 37 | action :reload 38 | end 39 | end 40 | 41 | action_class do 42 | def create_stop_system_service 43 | service 'httpd' do 44 | supports status: true 45 | provider Chef::Provider::Service::Init::Redhat 46 | action [:stop, :disable] 47 | end 48 | end 49 | 50 | def create_setup_service 51 | template "/etc/init.d/#{apache_name}" do 52 | source "#{new_resource.version}/sysvinit/el-#{elversion}/httpd.erb" 53 | owner 'root' 54 | group 'root' 55 | mode '0755' 56 | variables(apache_name: apache_name) 57 | cookbook 'httpd' 58 | action :create 59 | end 60 | 61 | template "/etc/sysconfig/#{apache_name}" do 62 | source "rhel/sysconfig/httpd-#{new_resource.version}.erb" 63 | owner 'root' 64 | group 'root' 65 | mode '0644' 66 | variables( 67 | apache_name: apache_name, 68 | mpm: new_resource.mpm, 69 | pid_file: pid_file 70 | ) 71 | cookbook 'httpd' 72 | notifies :restart, "service[#{apache_name}]" 73 | action :create 74 | end 75 | 76 | service apache_name do 77 | supports status: true, restart: true 78 | restart_command "/sbin/service #{apache_name} condrestart" 79 | provider Chef::Provider::Service::Init::Redhat 80 | action :nothing 81 | end 82 | end 83 | 84 | def delete_stop_service 85 | service apache_name do 86 | supports status: true 87 | provider Chef::Provider::Service::Init::Redhat 88 | only_if { ::File.exist?("/etc/init.d/#{apache_name}") } 89 | action [:stop, :disable] 90 | end 91 | 92 | %W(/etc/init.d/#{apache_name} 93 | /etc/sysconfig/#{apache_name}).each do |path| 94 | file path do 95 | action :delete 96 | end 97 | end 98 | end 99 | end 100 | end 101 | end 102 | -------------------------------------------------------------------------------- /libraries/info_mpm_config_parameter.rb: -------------------------------------------------------------------------------- 1 | # DSL bits 2 | module HttpdCookbook 3 | module Helpers 4 | module MPMConfigParameterDSL 5 | # 6 | # Define the configuration parameter value for any criteria: mpm_model, 7 | # httpd_version, etc. 8 | # 9 | # @example define parameters for httpd version 2.4 when using the mpm 10 | # 'event' model. 11 | # 12 | # config :for => { :httpd_version => '2.4', :mpm_model => 'event' }, 13 | # :are => { 14 | # :minspareservers => '5', 15 | # :maxspareservers => '10' 16 | # } 17 | # When defining the criteria you can specify as little or as much 18 | # criteria you need. Not specifying the field means that field allows 19 | # any value. 20 | # 21 | # @example Setting the the maxclients for all versions of httpd that are 22 | # using 23 | # 24 | # @note the order that these configs are defined are important. The first 25 | # one to match will return that value. So that ensure the more specific 26 | # settings are defined first and the more general ones defined later. 27 | # 28 | def config(options) 29 | options[:are].each do |parameter, value| 30 | key = options[:for].merge(parameter: parameter) 31 | 32 | configuration[key] = value 33 | end 34 | end 35 | 36 | def configuration 37 | @configuration ||= {} 38 | end 39 | 40 | # 41 | # Given a key, which is a hash of criteria (i.e. httpd_version, 42 | # mpm_model, parameter), this method will return for you the 43 | # configuration parameter value. `Nil` is returned if no preset value 44 | # for the parameter exists 45 | # 46 | # @example Searching for the 'maxclients' value for httpd version 2.2 47 | # when using the 'prefork' mpm model 48 | # 49 | # MPMConfigInfo.find(:parameter => :maxclients, :httpd_version => '2.2', :mpm_model => 'prefork') 50 | # 51 | def find(key) 52 | # require 'pry' ; binding.pry 53 | found_key = configuration.keys.find { |lock| key.merge(lock) == key } 54 | configuration[found_key] 55 | end 56 | end 57 | end 58 | end 59 | 60 | # Info bits 61 | module HttpdCookbook 62 | module Helpers 63 | class MPMConfigInfo 64 | extend MPMConfigParameterDSL 65 | 66 | # http://httpd.apache.org/docs/2.2/mod/mpm_common.html 67 | # http://httpd.apache.org/docs/2.4/mod/mpm_common.html 68 | 69 | config for: { httpd_version: '2.2', mpm_model: 'prefork' }, 70 | are: { 71 | startservers: '5', 72 | minspareservers: '5', 73 | maxspareservers: '10', 74 | maxclients: '150', 75 | maxrequestsperchild: '0', 76 | minsparethreads: nil, 77 | maxsparethreads: nil, 78 | threadlimit: nil, 79 | threadsperchild: nil, 80 | maxrequestworkers: nil, 81 | maxconnectionsperchild: nil, 82 | } 83 | 84 | config for: { httpd_version: '2.2', mpm_model: 'worker' }, 85 | are: { 86 | startservers: '2', 87 | minspareservers: nil, 88 | maxspareservers: nil, 89 | maxclients: '150', 90 | maxrequestsperchild: '0', 91 | minsparethreads: '25', 92 | maxsparethreads: '75', 93 | threadlimit: '64', 94 | threadsperchild: '25', 95 | maxrequestworkers: nil, 96 | maxconnectionsperchild: nil, 97 | } 98 | 99 | config for: { httpd_version: '2.2', mpm_model: 'event' }, 100 | are: { 101 | startservers: '2', 102 | minspareservers: nil, 103 | maxspareservers: nil, 104 | maxclients: '150', 105 | maxrequestsperchild: '0', 106 | minsparethreads: '25', 107 | maxsparethreads: '75', 108 | threadlimit: '64', 109 | threadsperchild: '25', 110 | maxrequestworkers: nil, 111 | maxconnectionsperchild: nil, 112 | } 113 | 114 | config for: { httpd_version: '2.4', mpm_model: 'prefork' }, 115 | are: { 116 | startservers: '5', 117 | minspareservers: '5', 118 | maxspareservers: '10', 119 | maxclients: nil, 120 | maxrequestsperchild: nil, 121 | minsparethreads: nil, 122 | maxsparethreads: nil, 123 | threadlimit: nil, 124 | threadsperchild: nil, 125 | maxrequestworkers: '150', 126 | maxconnectionsperchild: '0', 127 | } 128 | 129 | config for: { httpd_version: '2.4', mpm_model: 'worker' }, 130 | are: { 131 | startservers: '2', 132 | minspareservers: nil, 133 | maxspareservers: nil, 134 | maxclients: nil, 135 | maxrequestsperchild: nil, 136 | minsparethreads: '25', 137 | maxsparethreads: '75', 138 | threadlimit: '64', 139 | threadsperchild: '25', 140 | maxrequestworkers: '150', 141 | maxconnectionsperchild: '0', 142 | } 143 | 144 | config for: { httpd_version: '2.4', mpm_model: 'event' }, 145 | are: { 146 | startservers: '2', 147 | minspareservers: nil, 148 | maxspareservers: nil, 149 | maxclients: nil, 150 | maxrequestsperchild: nil, 151 | minsparethreads: '25', 152 | maxsparethreads: '75', 153 | threadlimit: '64', 154 | threadsperchild: '25', 155 | maxrequestworkers: '150', 156 | maxconnectionsperchild: '0', 157 | } 158 | end 159 | 160 | def default_value_for(version, mpm, parameter) 161 | MPMConfigInfo.find httpd_version: version, mpm_model: mpm, parameter: parameter 162 | end 163 | end 164 | end 165 | -------------------------------------------------------------------------------- /libraries/info_service_packages.rb: -------------------------------------------------------------------------------- 1 | # DSL bits 2 | module HttpdCookbook 3 | module Helpers 4 | module ServicePackageDSL 5 | def pkgname(options) 6 | configuration[options[:for]] = options[:is] 7 | end 8 | 9 | def configuration 10 | @configuration ||= {} 11 | end 12 | 13 | def find(key) 14 | # require 'pry' ; binding.pry 15 | found_key = configuration.keys.find { |lock| key.merge(lock) == key } 16 | configuration[found_key] 17 | end 18 | end 19 | end 20 | end 21 | 22 | # Info bits 23 | module HttpdCookbook 24 | module Helpers 25 | class ServicePackageInfo 26 | extend ServicePackageDSL 27 | 28 | pkgname for: { platform: 'amazon', httpd_version: '2.2' }, is: 'httpd' 29 | pkgname for: { platform: 'amazon', httpd_version: '2.4' }, is: 'httpd24' 30 | pkgname for: { platform: 'fedora', httpd_version: '2.4' }, is: 'httpd' 31 | pkgname for: { platform_family: 'debian', httpd_version: '2.2' }, is: 'apache2' 32 | pkgname for: { platform_family: 'debian', httpd_version: '2.4' }, is: 'apache2' 33 | pkgname for: { platform_family: 'rhel', httpd_version: '2.2' }, is: 'httpd' 34 | pkgname for: { platform_family: 'rhel', httpd_version: '2.4' }, is: 'httpd' 35 | pkgname for: { platform_family: 'suse', httpd_version: '2.4' }, is: 'apache2' 36 | pkgname for: { platform_family: 'freebsd', httpd_version: '2.4' }, is: 'apache24' 37 | 38 | # require 'pry' ; binding.pry 39 | end 40 | 41 | def package_name_for_service(platform, platform_family, platform_version, httpd_version) 42 | ServicePackageInfo.find( 43 | platform: platform, 44 | platform_family: platform_family, 45 | platform_version: platform_version, 46 | httpd_version: httpd_version 47 | ) 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'httpd' 2 | version '0.6.2' 3 | maintainer 'Chef Software, Inc.' 4 | maintainer_email 'cookbooks@chef.io' 5 | license 'Apache-2.0' 6 | description 'Provides httpd_service, httpd_config, and httpd_module resources' 7 | 8 | supports 'amazon' 9 | supports 'redhat' 10 | supports 'centos' 11 | supports 'scientific' 12 | supports 'oracle' 13 | supports 'fedora' 14 | supports 'debian' 15 | supports 'ubuntu' 16 | supports 'suse' 17 | supports 'opensuse' 18 | supports 'opensuseleap' 19 | 20 | source_url 'https://github.com/chef-cookbooks/httpd' 21 | issues_url 'https://github.com/chef-cookbooks/httpd/issues' 22 | chef_version '>= 12.7' if respond_to?(:chef_version) 23 | -------------------------------------------------------------------------------- /spec/helpers/module_amazon_2_2_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.2 on amazon' do 9 | amazon_2_2_core = %w( 10 | actions alias asis auth_basic auth_digest authn_alias authn_anon 11 | authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm 12 | authz_default authz_groupfile authz_host authz_owner authz_user 13 | autoindex cache cern_meta cgi cgid dav dav_fs dbd deflate dir 14 | disk_cache dumpio env expires ext_filter file_cache filter headers 15 | ident include info ldap log_config log_forensic logio mime 16 | mime_magic negotiation proxy proxy proxy_ajp proxy_balancer 17 | proxy_connect proxy_ftp proxy_http proxy_scgi reqtimeout rewrite 18 | setenvif speling status substitute suexec unique_id userdir 19 | usertrack version vhost_alias 20 | ) 21 | 22 | amazon_2_2_other = %w( 23 | perl-devel auth_kerb auth_mysql auth_pgsql authz_ldap dav_svn 24 | fcgid geoip nss perl proxy_html python security ssl wsgi 25 | ) 26 | 27 | amazon_2_2_core.each do |m| 28 | it 'returns the proper package name' do 29 | expect( 30 | package_name_for_module(m, '2.2', 'amazon', 'rhel', '2014.03') 31 | ).to eq('httpd') 32 | end 33 | end 34 | 35 | amazon_2_2_other.each do |m| 36 | it 'returns the proper package name' do 37 | expect( 38 | package_name_for_module(m, '2.2', 'amazon', 'rhel', '2014.03') 39 | ).to eq("mod_#{m}") 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /spec/helpers/module_amazon_2_4_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.4 on amazon' do 9 | amazon_2_4_core = %w( 10 | access_compat actions alias allowmethods asis auth_basic 11 | auth_digest authn_anon authn_core authn_dbd authn_dbm authn_file 12 | authn_socache authz_core authz_dbd authz_dbm authz_groupfile 13 | authz_host authz_owner authz_user autoindex buffer cache cache_disk 14 | cache_socache cgi cgid charset_lite data dav dav_fs dav_lock dbd 15 | deflate dialup dir dumpio echo env expires ext_filter file_cache 16 | filter headers heartbeat heartmonitor include info 17 | lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic 18 | lbmethod_heartbeat log_config log_debug log_forensic logio lua 19 | macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation 20 | proxy proxy_ajp proxy_balancer proxy_connect proxy_express 21 | proxy_fcgi proxy_fdpass proxy_ftp proxy_http proxy_scgi 22 | proxy_wstunnel ratelimit reflector remoteip reqtimeout request 23 | rewrite sed setenvif slotmem_plain slotmem_shm socache_dbm 24 | socache_memcache socache_shmcb speling status substitute suexec 25 | unique_id unixd userdir usertrack version vhost_alias watchdog 26 | ) 27 | 28 | amazon_2_4_other = %w( 29 | auth_kerb fcgid geoip ldap nss perl proxy_html security session 30 | ssl wsgi wsgi_py27 31 | ) 32 | 33 | amazon_2_4_core.each do |m| 34 | it 'returns the proper package name' do 35 | expect( 36 | package_name_for_module(m, '2.4', 'amazon', 'rhel', '2014.03') 37 | ).to eq('httpd24') 38 | end 39 | end 40 | 41 | amazon_2_4_other.each do |m| 42 | it 'returns the proper package name' do 43 | expect( 44 | package_name_for_module(m, '2.4', 'amazon', 'rhel', '2014.03') 45 | ).to eq("mod24_#{m}") 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/helpers/module_debian_2_2_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.2 on debian 7, 10.04, and 12.04' do 9 | debian_2_2_core = %w( 10 | actions alias asis auth_basic auth_digest authn_alias authn_anon 11 | authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm 12 | authz_default authz_groupfile authz_host authz_owner authz_user 13 | autoindex cache cern_meta cgid cgi charset_lite dav_fs dav_lock dav 14 | dbd deflate dir disk_cache dumpio env expires ext_filter file_cache 15 | filter headers ident imagemap include info ldap log_forensic mem_cache 16 | mime_magic mime negotiation proxy_ajp proxy_balancer proxy_connect 17 | proxy_ftp proxy_http proxy_scgi proxy reqtimeout rewrite setenvif 18 | speling ssl status substitute suexec unique_id userdir usertrack 19 | vhost_alias 20 | ) 21 | 22 | debian_2_2_other = %w( 23 | apparmor apreq2 auth_cas auth_kerb auth_memcookie auth_mysql 24 | auth_ntlm_winbind auth_openid auth_pam auth_pgsql auth_plain 25 | auth_pubtkt auth_radius auth_sys_group auth_tkt authn_sasl authn_webid 26 | authn_yubikey authnz_external authz_unixgroup bw dacs defensible dnssd 27 | encoding evasive fcgid fcgid_dbg geoip gnutls jk layout ldap_userdir 28 | ldap_userdir_dbg lisp log_sql log_sql_dbi log_sql_mysql log_sql_ssl 29 | macro mime_xattr modsecurity mono musicindex neko nss ocamlnet parser3 30 | passenger perl2 perl2_dev perl2_doc php5 php5filter proxy_html python 31 | python_doc qos random removeip rivet rivet_doc rpaf ruby ruid2 ruwsgi 32 | ruwsgi_dbg scgi shib2 spamhaus speedycgi suphp upload_progress uwsgi 33 | uwsgi_dbg vhost_hash_alias vhost_ldap wsgi wsgi_py3 xsendfile 34 | ) 35 | 36 | debian_2_2_core.each do |m| 37 | it 'returns the proper package name' do 38 | expect( 39 | package_name_for_module(m, '2.2', 'debian', 'debian', '7.2') 40 | ).to eq('apache2') 41 | expect( 42 | package_name_for_module(m, '2.2', 'debian', 'debian', '10.04') 43 | ).to eq('apache2') 44 | expect( 45 | package_name_for_module(m, '2.2', 'debian', 'debian', '12.04') 46 | ).to eq('apache2') 47 | end 48 | end 49 | 50 | debian_2_2_other.each do |m| 51 | it 'returns the proper package name' do 52 | expect( 53 | package_name_for_module(m, '2.2', 'debian', 'debian', '7.2') 54 | ).to eq("libapache2-mod-#{m.tr('_', '-')}") 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /spec/helpers/module_debian_2_4_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.4 on ubuntu 14.04' do 9 | debian_2_4_core = %w( 10 | access_compat actions alias allowmethods asis auth_basic 11 | auth_digest auth_form authn_anon authn_core authn_dbd authn_dbm 12 | authn_file authn_socache authnz_ldap authz_core authz_dbd authz_dbm 13 | authz_groupfile authz_host authz_owner authz_user autoindex buffer 14 | cache cache_disk cache_socache cgi cgid charset_lite data dav 15 | dav_fs dav_lock dbd deflate dialup dir dumpio echo env expires 16 | ext_filter file_cache filter headers heartbeat heartmonitor include 17 | info lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic 18 | lbmethod_heartbeat ldap log_debug log_forensic macro mime mime_magic 19 | mpm_event mpm_prefork mpm_worker negotiation proxy proxy_ajp 20 | proxy_balancer proxy_connect proxy_express proxy_fcgi proxy_fdpass 21 | proxy_ftp proxy_html proxy_http proxy_scgi proxy_wstunnel ratelimit 22 | reflector remoteip reqtimeout request rewrite sed session 23 | session_cookie session_crypto session_dbd setenvif slotmem_plain 24 | slotmem_shm socache_dbm socache_memcache socache_shmcb speling ssl 25 | status substitute suexec unique_id userdir usertrack vhost_alias 26 | xml2enc 27 | ) 28 | 29 | debian_2_4_other = %w( 30 | apparmor auth_mysql auth_pgsql auth_plain perl2 perl2_dev 31 | perl2_doc php5 python python_doc wsgi reload_perl fastcgi 32 | authcassimple_perl authcookie_perl authenntlm_perl apreq2 auth_cas 33 | auth_kerb auth_mellon auth_memcookie auth_ntlm_winbind auth_openid 34 | auth_pubtkt auth_radius auth_tkt authn_sasl authn_webid 35 | authn_yubikey authnz_external authz_unixgroup axis2c bw dacs 36 | defensible dnssd encoding evasive fcgid fcgid_dbg geoip gnutls jk 37 | ldap_userdir ldap_userdir_dbg lisp log_slow log_sql log_sql_dbi 38 | log_sql_mysql log_sql_ssl mapcache mime_xattr mono musicindex neko 39 | netcgi_apache nss parser3 passenger php5filter qos removeip rivet 40 | rivet_doc rpaf ruid2 ruwsgi ruwsgi_dbg scgi security2 shib2 41 | spamhaus suphp svn upload_progress uwsgi uwsgi_dbg vhost_ldap 42 | watchcat webauth webauthldap webkdc wsgi_py3 xsendfile modsecurity 43 | mpm_itk request_perl sitecontrol_perl svn webauth webkdc 44 | ) 45 | 46 | debian_2_4_core.each do |m| 47 | it 'returns the proper package name' do 48 | expect( 49 | package_name_for_module(m, '2.4', 'ubuntu', 'debian', '14.04') 50 | ).to eq('apache2') 51 | end 52 | end 53 | 54 | debian_2_4_other.each do |m| 55 | it 'returns the proper package name' do 56 | expect( 57 | package_name_for_module(m, '2.4', 'ubuntu', 'debian', '14.04') 58 | ).to eq("libapache2-mod-#{m.tr('_', '-')}") 59 | end 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /spec/helpers/module_invalid_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | it 'returns nil when looking up an invalid package' do 9 | expect( 10 | package_name_for_module('asdasd', '2.2', 'debian', 'debian', '7.2') 11 | ).to eq(nil) 12 | end 13 | 14 | it 'returns nil when looking up an invalid version' do 15 | expect( 16 | package_name_for_module('asdasd', '2.4', 'debian', 'debian', '7.2') 17 | ).to eq(nil) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/helpers/module_rhel_6_2_2_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.2 on rhel 6' do 9 | rhel_6_2_2_core = %w( 10 | actions alias asis auth_basic auth_digest authn_alias authn_anon 11 | authn_dbd authn_dbm authn_default authn_file authnz_ldap authz_dbm 12 | authz_default authz_groupfile authz_host authz_owner authz_user 13 | autoindex cache cern_meta cgi cgid dav dav_fs dbd deflate dir 14 | disk_cache dumpio env expires ext_filter filter headers ident 15 | include info ldap log_config log_forensic logio mime mime_magic 16 | negotiation proxy proxy proxy_ajp proxy_balancer proxy_connect 17 | proxy_ftp proxy_http proxy_scgi reqtimeout rewrite setenvif speling 18 | status substitute suexec unique_id userdir usertrack version 19 | vhost_alias 20 | ) 21 | 22 | rhel_6_2_2_other = %w( 23 | auth_kerb auth_mysql auth_pgsql authz_ldap 24 | dav_svn dnssd nss perl revocator revocator ssl wsgi 25 | ) 26 | 27 | rhel_6_2_2_core.each do |m| 28 | it 'returns the proper package name' do 29 | expect( 30 | package_name_for_module(m, '2.2', 'centos', 'rhel', '6.5') 31 | ).to eq('httpd') 32 | end 33 | end 34 | 35 | rhel_6_2_2_other.each do |m| 36 | it 'returns the proper package name' do 37 | expect( 38 | package_name_for_module(m, '2.2', 'centos', 'rhel', '6.5') 39 | ).to eq("mod_#{m}") 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /spec/helpers/module_rhel_7_2_4_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_module_packages' 2 | 3 | describe 'looking up module package name' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'for apache 2.4 on rhel 7' do 9 | rhel_7_2_4_core = %w( 10 | access_compat actions alias allowmethods asis auth_basic 11 | auth_digest authn_anon authn_core authn_dbd authn_dbm authn_file 12 | authn_socache authz_core authz_dbd authz_dbm authz_groupfile 13 | authz_host authz_owner authz_user autoindex buffer cache cache_disk 14 | cache_socache cgi cgid charset_lite data dav dav_fs dav_lock dbd 15 | deflate dialup dir dumpio echo env expires ext_filter file_cache 16 | filter headers heartbeat heartmonitor include info 17 | lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic 18 | lbmethod_heartbeat log_config log_debug log_forensic logio lua 19 | macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation 20 | proxy proxy_ajp proxy_balancer proxy_connect proxy_express 21 | proxy_fcgi proxy_fdpass proxy_ftp proxy_http proxy_scgi 22 | proxy_wstunnel ratelimit reflector remoteip reqtimeout request 23 | rewrite sed setenvif slotmem_plain slotmem_shm socache_dbm 24 | socache_memcache socache_shmcb speling status substitute suexec 25 | systemd unique_id unixd userdir usertrack version vhost_alias watchdog 26 | ) 27 | 28 | rhel_7_2_4_other = %w( 29 | auth_kerb dav_svn fcgid ldap nss proxy_html revocator security 30 | session ssl wsgi 31 | ) 32 | 33 | rhel_7_2_4_core.each do |m| 34 | it 'returns the proper package name' do 35 | expect( 36 | package_name_for_module(m, '2.4', 'centos', 'rhel', '7.0') 37 | ).to eq('httpd') 38 | end 39 | end 40 | 41 | rhel_7_2_4_other.each do |m| 42 | it 'returns the proper package name' do 43 | expect( 44 | package_name_for_module(m, '2.4', 'centos', 'rhel', '7.0') 45 | ).to eq("mod_#{m}") 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/helpers/service_package_name_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../libraries/info_service_packages' 2 | 3 | describe 'package_name_for_service' do 4 | before do 5 | extend HttpdCookbook::Helpers 6 | end 7 | 8 | context 'when on centos' do 9 | context 'version 6' do 10 | it 'returns the correct package_name' do 11 | expect( 12 | package_name_for_service('centos', 'rhel', '6.4', '2.2') 13 | ).to eq('httpd') 14 | end 15 | end 16 | end 17 | 18 | context 'when on centos' do 19 | context 'version 7' do 20 | it 'returns the correct package_name' do 21 | expect( 22 | package_name_for_service('centos', 'rhel', '7.0', '2.4') 23 | ).to eq('httpd') 24 | end 25 | end 26 | end 27 | 28 | # TODO: Fill these out more 29 | end 30 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true # Use color in STDOUT 6 | config.formatter = :documentation # Use the specified formatter 7 | config.log_level = :error # Avoid deprecation notice SPAM 8 | end 9 | -------------------------------------------------------------------------------- /templates/default/2.2/mods/mpm.conf.erb: -------------------------------------------------------------------------------- 1 | _module> 2 | <% if @startservers %> 3 | StartServers <%= @startservers %> 4 | <% end %> 5 | <% if @minspareservers %> 6 | MinSpareServers <%= @minspareservers %> 7 | <% end %> 8 | <% if @maxspareservers %> 9 | MaxSpareServers <%= @maxspareservers %> 10 | <% end %> 11 | <% if @maxclients %> 12 | MaxClients <%= @maxclients %> 13 | <% end %> 14 | <% if @maxrequestsperchild %> 15 | MaxRequestsPerChild <%= @maxrequestsperchild %> 16 | <% end %> 17 | <% if @minsparethreads %> 18 | MinSpareThreads <%= @minsparethreads %> 19 | <% end %> 20 | <% if @maxsparethreads %> 21 | MaxSpareThreads <%= @maxsparethreads %> 22 | <% end %> 23 | <% if @threadlimit %> 24 | ThreadLimit <%= @threadlimit %> 25 | <% end %> 26 | <% if @threadsperchild %> 27 | ThreadsPerChild <%= @threadsperchild %> 28 | <% end %> 29 | <% if @maxrequestworkers %> 30 | MaxRequestWorkers <%= @maxrequestworkers %> 31 | <% end %> 32 | <% if @maxconnectionsperchild %> 33 | MaxConnectionsPerChild <%= @maxconnectionsperchild %> 34 | <% end %> 35 | 36 | -------------------------------------------------------------------------------- /templates/default/2.2/scripts/a2enmod.erb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | # 3 | # a2enmod by Stefan Fritsch 4 | # Licensed under Apache License 2.0 5 | 6 | use strict; 7 | use Cwd 'realpath'; 8 | use File::Spec; 9 | use File::Basename; 10 | use Getopt::Long; 11 | 12 | my $quiet; 13 | my $force; 14 | Getopt::Long::Configure('bundling'); 15 | GetOptions( 16 | 'quiet|q' => \$quiet, 17 | 'force|f' => \$force 18 | ) or exit 2; 19 | 20 | my $basename = basename($0); 21 | $basename =~ /^a2(en|dis)(mod|site)((?:-.+)?)$/ 22 | or die "$basename call name unknown\n"; 23 | my $act = $1; 24 | my $obj = $2; 25 | my $dir_suffix = $3; 26 | 27 | my $env_file = $ENV{APACHE_ENVVARS} 28 | || ( 29 | $ENV{APACHE_CONFDIR} 30 | ? "$ENV{APACHE_CONFDIR}/envvars" 31 | : "/etc/apache2$dir_suffix/envvars" 32 | ); 33 | $ENV{LANG}='C'; 34 | read_env_file($env_file); 35 | 36 | $act .= 'able'; 37 | my ( $name, $dir, $sffx, $reload ); 38 | if ( $obj eq 'mod' ) { 39 | $obj = 'module'; 40 | $dir = 'mods'; 41 | $sffx = '.load'; 42 | $reload = 'restart'; 43 | } 44 | else { 45 | $dir = 'sites'; 46 | $sffx = ''; 47 | $reload = 'reload'; 48 | } 49 | $name = ucfirst($obj); 50 | 51 | my $confdir = $ENV{APACHE_CONFDIR} || "/etc/apache2$dir_suffix"; 52 | my $availdir = $ENV{ uc("APACHE_${dir}_AVAILABLE") } || "$confdir/$dir-available"; 53 | my $enabldir = $ENV{ uc("APACHE_${dir}_ENABLED") } || "$confdir/$dir-enabled"; 54 | 55 | my $choicedir = $act eq 'enable' ? $availdir : $enabldir; 56 | my $linkdir = File::Spec->abs2rel( $availdir, $enabldir ); 57 | 58 | my $request_reload = 0; 59 | 60 | my $rc = 0; 61 | 62 | if ( !scalar @ARGV ) { 63 | my @choices = myglob('*'); 64 | print "Your choices are: @choices\n"; 65 | print "Which ${obj}(s) do you want to $act (wildcards ok)?\n"; 66 | my $input = <>; 67 | @ARGV = split /\s+/, $input; 68 | 69 | } 70 | 71 | my @objs; 72 | foreach my $arg (@ARGV) { 73 | my @glob = myglob($arg); 74 | if ( !@glob ) { 75 | error("No $obj found matching $arg!\n"); 76 | $rc = 1; 77 | } 78 | else { 79 | push @objs, @glob; 80 | } 81 | } 82 | 83 | foreach my $acton (@objs) { 84 | doit($acton) or $rc = 1; 85 | } 86 | 87 | info("To activate the new configuration, you need to run:\n service apache2 $reload\n") 88 | if $request_reload; 89 | 90 | exit($rc); 91 | 92 | ############################################################################## 93 | 94 | sub myglob { 95 | my $arg = shift; 96 | 97 | my @glob = map { 98 | s{^$choicedir/}{}; 99 | s{$sffx$}{}; 100 | s{^000-default$}{default}; 101 | $_ 102 | } glob("$choicedir/$arg$sffx"); 103 | 104 | # use same rules as apache's Include directive 105 | @glob = grep( /^[[:alnum:]][-._[:alnum:]]*$/, @glob ); 106 | @glob = grep( !/\.dpkg/, @glob ); 107 | 108 | return @glob; 109 | } 110 | 111 | sub doit { 112 | my $acton = shift; 113 | 114 | my $prio = ""; 115 | if ( $obj eq 'site' && $acton eq 'default' ) { 116 | $prio = '000-'; 117 | } 118 | 119 | my ( $conftgt, $conflink ); 120 | if ( $obj eq 'module' ) { 121 | if ( $acton eq 'cgi' && threaded() ) { 122 | print "Your MPM seems to be threaded. Selecting cgid instead of cgi.\n"; 123 | $acton = 'cgid'; 124 | } 125 | 126 | $conftgt = "$availdir/$acton.conf"; 127 | if ( -e $conftgt ) { 128 | $conflink = "$enabldir/$acton.conf"; 129 | } 130 | } 131 | 132 | my $tgt = "$availdir/$acton$sffx"; 133 | my $link = "$enabldir/$prio$acton$sffx"; 134 | 135 | if ( !-e $tgt ) { 136 | if ( -l $link && !-e $link ) { 137 | if ( $act eq 'disable' ) { 138 | info("removing dangling symlink $link\n"); 139 | unlink($link); 140 | return 1; 141 | } 142 | else { 143 | error("$link is a dangling symlink!\n"); 144 | } 145 | } 146 | 147 | error("$name $acton does not exist!\n"); 148 | return 0; 149 | } 150 | 151 | # handle module dependencies 152 | if ( $obj eq 'module' ) { 153 | if ( $act eq 'enable' ) { 154 | my $depends = qx{grep "# Depends:" "$availdir/$acton.load"|cut -f2 -d:}; 155 | $depends =~ s,^[\s\n]+,,; 156 | $depends =~ s,[\s\n]+$,,; 157 | do_deps( $acton, split( /[\n\s]+/, $depends ) ) or return 0; 158 | } 159 | else { 160 | my @depends = qx{egrep "# Depends:.*${acton}( |\$)" $enabldir/*.load}; 161 | @depends = grep {s{^.*?/([^/]*?)\.load:.*}{$1}s} @depends; 162 | if ( scalar @depends ) { 163 | if ($force) { 164 | do_deps( $acton, @depends ) or return 0; 165 | } 166 | else { 167 | error( 168 | "The following modules depend on $acton ", 169 | "and need to be disabled first: @depends\n" 170 | ); 171 | return 0; 172 | } 173 | } 174 | } 175 | } 176 | 177 | if ( $act eq 'enable' ) { 178 | my $check = check_link( $tgt, $link ); 179 | if ( $check eq 'ok' ) { 180 | if ($conflink) { 181 | 182 | # handle .conf file 183 | my $confcheck = check_link( $conftgt, $conflink ); 184 | if ( $confcheck eq 'ok' ) { 185 | info("$name $acton already enabled\n"); 186 | return 1; 187 | } 188 | elsif ( $confcheck eq 'missing' ) { 189 | print "Enabling config file $acton.conf.\n"; 190 | add_link( $conftgt, $conflink ) or return 0; 191 | } 192 | else { 193 | error("Config file $acton.conf not properly enabled: $confcheck\n"); 194 | return 0; 195 | } 196 | } 197 | else { 198 | info("$name $acton already enabled\n"); 199 | return 1; 200 | } 201 | } 202 | elsif ( $check eq 'missing' ) { 203 | if ($conflink) { 204 | 205 | # handle .conf file 206 | my $confcheck = check_link( $conftgt, $conflink ); 207 | if ( $confcheck eq 'missing' ) { 208 | add_link( $conftgt, $conflink ) or return 0; 209 | } 210 | elsif ( $confcheck ne 'ok' ) { 211 | error("Config file $acton.conf not properly enabled: $confcheck\n"); 212 | return 0; 213 | } 214 | } 215 | 216 | print "Enabling $obj $acton.\n"; 217 | if ( $acton eq 'ssl' ) { 218 | info("See /usr/share/doc/apache2.2-common/README.Debian.gz on " . 219 | "how to configure SSL and create self-signed certificates.\n"); 220 | } 221 | return add_link( $tgt, $link ); 222 | } 223 | else { 224 | error("$name $acton not properly enabled: $check\n"); 225 | return 0; 226 | } 227 | } 228 | else { 229 | if ( -e $link || -l $link ) { 230 | remove_link($link); 231 | if ( $conflink && -e $conflink ) { 232 | remove_link($conflink); 233 | } 234 | print "$name $acton disabled.\n"; 235 | } 236 | elsif ( $conflink && -e $conflink ) { 237 | print "Disabling stale config file $acton.conf.\n"; 238 | remove_link($conflink); 239 | } 240 | else { 241 | info("$name $acton already disabled\n"); 242 | return 1; 243 | } 244 | } 245 | 246 | return 1; 247 | } 248 | 249 | sub do_deps { 250 | my $acton = shift; 251 | foreach my $d (@_) { 252 | info("Considering dependency $d for $acton:\n"); 253 | if ( !doit($d) ) { 254 | error("Could not $act dependency $d for $acton, aborting\n"); 255 | return 0; 256 | } 257 | } 258 | return 1; 259 | } 260 | 261 | sub add_link { 262 | my ( $tgt, $link ) = @_; 263 | 264 | # create relative link 265 | if ( !symlink( File::Spec->abs2rel( $tgt, dirname($link) ), $link ) ) { 266 | die("Could not create $link: $!\n"); 267 | } 268 | $request_reload = 1; 269 | return 1; 270 | } 271 | 272 | sub check_link { 273 | my ( $tgt, $link ) = @_; 274 | 275 | if ( !-e $link ) { 276 | if ( -l $link ) { 277 | 278 | # points to nowhere 279 | info("Removing dangling link $link"); 280 | unlink($link) or die "Could not remove $link\n"; 281 | } 282 | return 'missing'; 283 | } 284 | 285 | if ( -e $link && !-l $link ) { 286 | return "$link is a real file, not touching it"; 287 | } 288 | if ( realpath($link) ne realpath($tgt) ) { 289 | return "$link exists but does not point to $tgt, not touching it"; 290 | } 291 | return 'ok'; 292 | } 293 | 294 | sub remove_link { 295 | my ($link) = @_; 296 | 297 | if ( -l $link ) { 298 | unlink($link) or die "Could not remove $link: $!\n"; 299 | } 300 | elsif ( -e $link ) { 301 | error("$link is not a symbolic link, not deleting\n"); 302 | return 0; 303 | } 304 | $request_reload = 1; 305 | return 1; 306 | } 307 | 308 | sub threaded { 309 | my $result = ""; 310 | $result = qx{/usr/sbin/apache2 -V | grep 'threaded'} if -x '/usr/sbin/apache2'; 311 | if ( $result =~ / no/ ) { 312 | return 0; 313 | } 314 | else { 315 | return 1; 316 | } 317 | } 318 | 319 | sub info { 320 | print @_ if !$quiet; 321 | } 322 | 323 | sub error { 324 | print STDERR 'ERROR: ', @_; 325 | } 326 | 327 | sub read_env_file { 328 | my $file = shift; 329 | 330 | -r $file or return; 331 | my @lines = qx{env - sh -c '. $file && env'}; 332 | if ($?) { 333 | die "Could not read $file\n"; 334 | } 335 | 336 | foreach my $l (@lines) { 337 | chomp $l; 338 | $l =~ /^(.*)?=(.*)$/ or die "Could not parse $file\n"; 339 | $ENV{$1} = $2; 340 | } 341 | } 342 | -------------------------------------------------------------------------------- /templates/default/2.2/sysvinit/debian-7/apache2.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: <%= @apache_name %> 4 | # Required-Start: $local_fs $remote_fs $network $syslog $named 5 | # Required-Stop: $local_fs $remote_fs $network $syslog $named 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # X-Interactive: true 9 | # Short-Description: Start/stop apache2 web server 10 | ### END INIT INFO 11 | 12 | set -e 13 | 14 | SCRIPTNAME="${0##*/}" 15 | SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}" 16 | if [ -n "$APACHE_CONFDIR" ] ; then 17 | if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then 18 | DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}" 19 | else 20 | DIR_SUFFIX= 21 | fi 22 | elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then 23 | DIR_SUFFIX="-${SCRIPTNAME##apache2-}" 24 | APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX 25 | else 26 | DIR_SUFFIX= 27 | APACHE_CONFDIR=/etc/apache2 28 | fi 29 | if [ -z "$APACHE_ENVVARS" ] ; then 30 | APACHE_ENVVARS=$APACHE_CONFDIR/envvars 31 | fi 32 | export APACHE_CONFDIR APACHE_ENVVARS 33 | 34 | ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin" 35 | if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then 36 | ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR" 37 | fi 38 | if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then 39 | ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS" 40 | fi 41 | 42 | 43 | #edit /etc/default/apache2 to change this. 44 | HTCACHECLEAN_RUN=auto 45 | HTCACHECLEAN_MODE=daemon 46 | HTCACHECLEAN_SIZE=300M 47 | HTCACHECLEAN_DAEMON_INTERVAL=120 48 | HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache 49 | HTCACHECLEAN_OPTIONS="" 50 | 51 | APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD) 52 | if [ -z "$APACHE_HTTPD" ] ; then 53 | APACHE_HTTPD=/usr/sbin/apache2 54 | fi 55 | if [ ! -x $APACHE_HTTPD ] ; then 56 | echo "No apache MPM package installed" 57 | exit 0 58 | fi 59 | 60 | . /lib/lsb/init-functions 61 | 62 | test -f /etc/default/rcS && . /etc/default/rcS 63 | 64 | if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then 65 | . /etc/default/apache2$DIR_SUFFIX 66 | elif [ -f /etc/default/apache2 ] ; then 67 | . /etc/default/apache2 68 | fi 69 | 70 | APACHE2CTL="$ENV /usr/sbin/apache2ctl" 71 | HTCACHECLEAN="$ENV /usr/sbin/htcacheclean" 72 | 73 | PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 74 | if [ -z "$PIDFILE" ] ; then 75 | echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2 76 | exit 2 77 | fi 78 | 79 | 80 | check_htcacheclean() { 81 | [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1 82 | 83 | [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0 84 | 85 | MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED) 86 | [ "$HTCACHECLEAN_RUN" = "auto" \ 87 | -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \ 88 | return 0 89 | 90 | return 1 91 | } 92 | 93 | start_htcacheclean() { 94 | if [ ! -d "$HTCACHECLEAN_PATH" ] ; then 95 | echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2 96 | return 1 97 | fi 98 | $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \ 99 | -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE 100 | } 101 | 102 | stop_htcacheclean() { 103 | pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || echo ...not running 104 | } 105 | 106 | pidof_apache() { 107 | # if there is actually an apache2 process whose pid is in PIDFILE, 108 | # print it and return 0. 109 | if [ -e "$PIDFILE" ]; then 110 | if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then 111 | return 0 112 | fi 113 | fi 114 | return 1 115 | } 116 | 117 | apache_stop() { 118 | if $APACHE2CTL configtest > /dev/null 2>&1; then 119 | # if the config is ok than we just stop normaly 120 | $APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 || true 121 | else 122 | # if we are here something is broken and we need to try 123 | # to exit as nice and clean as possible 124 | PID=$(pidof_apache) || true 125 | 126 | if [ "${PID}" ]; then 127 | # in this case it is everything nice and dandy and we kill apache2 128 | echo 129 | log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!" 130 | kill $PID 131 | elif [ "$(pidof apache2)" ]; then 132 | if [ "$VERBOSE" != no ]; then 133 | echo " ... failed!" 134 | echo "You may still have some apache2 processes running. There are" 135 | echo "processes named 'apache2' which do not match your pid file," 136 | echo "and in the name of safety, we've left them alone. Please review" 137 | echo "the situation by hand." 138 | fi 139 | return 1 140 | fi 141 | fi 142 | } 143 | 144 | apache_wait_stop() { 145 | # running ? 146 | PIDTMP=$(pidof_apache) || true 147 | if kill -0 "${PIDTMP:-}" 2> /dev/null; then 148 | PID=$PIDTMP 149 | fi 150 | 151 | apache_stop 152 | 153 | # wait until really stopped 154 | if [ -n "${PID:-}" ]; then 155 | i=0 156 | while kill -0 "${PID:-}" 2> /dev/null; do 157 | if [ $i = '60' ]; then 158 | break; 159 | else 160 | if [ $i = '0' ]; then 161 | echo -n " ... waiting " 162 | else 163 | echo -n "." 164 | fi 165 | i=$(($i+1)) 166 | sleep 1 167 | fi 168 | done 169 | fi 170 | } 171 | 172 | case $1 in 173 | start) 174 | log_daemon_msg "Starting web server" "apache2" 175 | if $APACHE2CTL start; then 176 | if check_htcacheclean ; then 177 | log_progress_msg htcacheclean 178 | start_htcacheclean || log_end_msg 1 179 | fi 180 | log_end_msg 0 181 | else 182 | log_end_msg 1 183 | fi 184 | ;; 185 | stop) 186 | if check_htcacheclean ; then 187 | log_daemon_msg "Stopping web server" "htcacheclean" 188 | stop_htcacheclean 189 | log_progress_msg "apache2" 190 | else 191 | log_daemon_msg "Stopping web server" "apache2" 192 | fi 193 | if apache_wait_stop; then 194 | log_end_msg 0 195 | else 196 | log_end_msg 1 197 | fi 198 | ;; 199 | graceful-stop) 200 | if check_htcacheclean ; then 201 | log_daemon_msg "Stopping web server" "htcacheclean" 202 | stop_htcacheclean 203 | log_progress_msg "apache2" 204 | else 205 | log_daemon_msg "Stopping web server" "apache2" 206 | fi 207 | if $APACHE2CTL graceful-stop; then 208 | log_end_msg 0 209 | else 210 | log_end_msg 1 211 | fi 212 | ;; 213 | reload | force-reload | graceful) 214 | log_daemon_msg "Reloading web server config" 215 | if pidof_apache > /dev/null ; then 216 | log_progress_msg "apache2" 217 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 218 | log_end_msg 1 219 | $APACHE2CTL configtest || true 220 | exit 1 221 | fi 222 | if $APACHE2CTL graceful $2 ; then 223 | log_end_msg 0 224 | else 225 | log_end_msg 1 226 | fi 227 | else 228 | log_progress_msg "apache2 not running" 229 | log_end_msg 0 230 | fi 231 | ;; 232 | restart) 233 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 234 | $APACHE2CTL configtest || true 235 | log_end_msg 1 236 | exit 1 237 | fi 238 | if check_htcacheclean ; then 239 | log_daemon_msg "Restarting web server" "htcacheclean" 240 | stop_htcacheclean 241 | log_progress_msg apache2 242 | else 243 | log_daemon_msg "Restarting web server" "apache2" 244 | fi 245 | PID=$(pidof_apache) || true 246 | if ! apache_wait_stop; then 247 | log_end_msg 1 || true 248 | fi 249 | if $APACHE2CTL start; then 250 | if check_htcacheclean ; then 251 | start_htcacheclean || log_end_msg 1 252 | fi 253 | log_end_msg 0 254 | else 255 | log_end_msg 1 256 | fi 257 | ;; 258 | start-htcacheclean) 259 | log_daemon_msg "Starting htcacheclean" 260 | start_htcacheclean || log_end_msg 1 261 | log_end_msg 0 262 | ;; 263 | stop-htcacheclean) 264 | log_daemon_msg "Stopping htcacheclean" 265 | stop_htcacheclean 266 | log_end_msg 0 267 | ;; 268 | status) 269 | PID=$(pidof_apache) || true 270 | if [ -n "$PID" ]; then 271 | echo "Apache2$DIR_SUFFIX is running (pid $PID)." 272 | exit 0 273 | else 274 | echo "Apache2$DIR_SUFFIX is NOT running." 275 | if [ -e "$PIDFILE" ]; then 276 | exit 1 277 | else 278 | exit 3 279 | fi 280 | fi 281 | ;; 282 | *) 283 | log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}" 284 | exit 1 285 | ;; 286 | esac 287 | -------------------------------------------------------------------------------- /templates/default/2.2/sysvinit/el-5/httpd.erb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # <%= @apache_name %> Startup script for the Apache HTTP Server 4 | # 5 | # chkconfig: - 85 15 6 | # description: Apache is a World Wide Web server. It is used to serve \ 7 | # HTML files and CGI. 8 | # processname: <%= @apache_name %> 9 | # config: /etc/<%= @apache_name %>/conf/httpd.conf 10 | # config: /etc/sysconfig/<%= @apache_name %> 11 | # pidfile: /var/run/<%= @apache_name %>.pid 12 | 13 | # Source function library. 14 | . /etc/rc.d/init.d/functions 15 | 16 | if [ -f /etc/sysconfig/<%= @apache_name %> ]; then 17 | . /etc/sysconfig/<%= @apache_name %> 18 | fi 19 | 20 | # Start httpd in the C locale by default. 21 | HTTPD_LANG=${HTTPD_LANG-"C"} 22 | 23 | # This will prevent initlog from swallowing up a pass-phrase prompt if 24 | # mod_ssl needs a pass-phrase from the user. 25 | INITLOG_ARGS="" 26 | 27 | # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 28 | # with the thread-based "worker" MPM; BE WARNED that some modules may not 29 | # work correctly with a thread-based MPM; notably PHP will refuse to start. 30 | 31 | # Path to the apachectl script, server binary, and short-form for messages. 32 | apachectl=/usr/sbin/apachectl 33 | httpd=${HTTPD-/usr/sbin/httpd} 34 | prog=httpd 35 | pidfile=${PIDFILE-/var/run/httpd.pid} 36 | lockfile=${LOCKFILE-/var/lock/subsys/httpd} 37 | RETVAL=0 38 | STOP_TIMEOUT=${STOP_TIMEOUT-10} 39 | 40 | # check for 1.3 configuration 41 | check13 () { 42 | CONFFILE=/etc/httpd/conf/httpd.conf 43 | GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|" 44 | GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|" 45 | GONE="${GONE}AccessConfig|ResourceConfig)" 46 | if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then 47 | echo 48 | echo 1>&2 " Apache 1.3 configuration directives found" 49 | echo 1>&2 " please read /usr/share/doc/httpd-2.2.3/migration.html" 50 | failure "Apache 1.3 config directives test" 51 | echo 52 | exit 1 53 | fi 54 | } 55 | 56 | # The semantics of these two functions differ from the way apachectl does 57 | # things -- attempting to start while running is a failure, and shutdown 58 | # when not running is also a failure. So we just do it the way init scripts 59 | # are expected to behave here. 60 | start() { 61 | echo -n $"Starting $prog: " 62 | check13 || exit 1 63 | LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 64 | RETVAL=$? 65 | echo 66 | [ $RETVAL = 0 ] && touch ${lockfile} 67 | return $RETVAL 68 | } 69 | 70 | # When stopping httpd a delay (of default 10 second) is required 71 | # before SIGKILLing the httpd parent; this gives enough time for the 72 | # httpd parent to SIGKILL any errant children. 73 | stop() { 74 | echo -n $"Stopping $prog: " 75 | killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd 76 | RETVAL=$? 77 | echo 78 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 79 | } 80 | reload() { 81 | echo -n $"Reloading $prog: " 82 | if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 83 | RETVAL=6 84 | echo $"not reloading due to configuration syntax error" 85 | failure $"not reloading $httpd due to configuration syntax error" 86 | else 87 | # Force LSB behaviour from killproc 88 | LSB=1 killproc -p ${pidfile} $httpd -HUP 89 | RETVAL=$? 90 | if [ $RETVAL -eq 7 ]; then 91 | failure $"httpd shutdown" 92 | fi 93 | fi 94 | echo 95 | } 96 | 97 | # See how we were called. 98 | case "$1" in 99 | start) 100 | start 101 | ;; 102 | stop) 103 | stop 104 | ;; 105 | status) 106 | status -p ${pidfile} $httpd 107 | RETVAL=$? 108 | ;; 109 | restart) 110 | stop 111 | start 112 | ;; 113 | condrestart|try-restart) 114 | if status -p ${pidfile} $httpd >&/dev/null; then 115 | stop 116 | start 117 | fi 118 | ;; 119 | force-reload|reload) 120 | reload 121 | ;; 122 | graceful|help|configtest|fullstatus) 123 | $apachectl $@ 124 | RETVAL=$? 125 | ;; 126 | *) 127 | echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" 128 | RETVAL=2 129 | esac 130 | 131 | exit $RETVAL 132 | -------------------------------------------------------------------------------- /templates/default/2.2/sysvinit/el-6/httpd.erb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # <%= @apache_name %> Startup script for the Apache HTTP Server 4 | # 5 | # chkconfig: - 85 15 6 | # description: The Apache HTTP Server is an efficient and extensible \ 7 | # server implementing the current HTTP standards. 8 | # processname: <%= @apache_name %> 9 | # config: /etc/<%= @apache_name %>/conf/httpd.conf 10 | # config: /etc/sysconfig/<%= @apache_name %> 11 | # pidfile: /var/run/<%= @apache_name %>/httpd.pid 12 | # 13 | ### BEGIN INIT INFO 14 | # Provides: <%= @apache_name %> 15 | # Required-Start: $local_fs $remote_fs $network $named 16 | # Required-Stop: $local_fs $remote_fs $network 17 | # Should-Start: distcache 18 | # Short-Description: start and stop Apache HTTP Server 19 | # Description: The Apache HTTP Server is an extensible server 20 | # implementing the current HTTP standards. 21 | ### END INIT INFO 22 | 23 | # Source function library. 24 | . /etc/rc.d/init.d/functions 25 | 26 | if [ -f /etc/sysconfig/<%= @apache_name %> ]; then 27 | . /etc/sysconfig/<%= @apache_name %> 28 | fi 29 | 30 | # Start httpd in the C locale by default. 31 | HTTPD_LANG=${HTTPD_LANG-"C"} 32 | 33 | # This will prevent initlog from swallowing up a pass-phrase prompt if 34 | # mod_ssl needs a pass-phrase from the user. 35 | INITLOG_ARGS="" 36 | 37 | # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 38 | # with the thread-based "worker" MPM; BE WARNED that some modules may not 39 | # work correctly with a thread-based MPM; notably PHP will refuse to start. 40 | 41 | # Path to the apachectl script, server binary, and short-form for messages. 42 | apachectl=/usr/sbin/apachectl 43 | httpd=${HTTPD-/usr/sbin/httpd} 44 | prog=httpd 45 | pidfile=${PIDFILE-/var/run/httpd/httpd.pid} 46 | lockfile=${LOCKFILE-/var/lock/subsys/httpd} 47 | RETVAL=0 48 | STOP_TIMEOUT=${STOP_TIMEOUT-10} 49 | 50 | # The semantics of these two functions differ from the way apachectl does 51 | # things -- attempting to start while running is a failure, and shutdown 52 | # when not running is also a failure. So we just do it the way init scripts 53 | # are expected to behave here. 54 | start() { 55 | echo -n $"Starting $prog: " 56 | LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 57 | RETVAL=$? 58 | echo 59 | [ $RETVAL = 0 ] && touch ${lockfile} 60 | return $RETVAL 61 | } 62 | 63 | # When stopping httpd, a delay (of default 10 second) is required 64 | # before SIGKILLing the httpd parent; this gives enough time for the 65 | # httpd parent to SIGKILL any errant children. 66 | stop() { 67 | echo -n $"Stopping $prog: " 68 | killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd 69 | RETVAL=$? 70 | echo 71 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 72 | } 73 | reload() { 74 | echo -n $"Reloading $prog: " 75 | if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then 76 | RETVAL=6 77 | echo $"not reloading due to configuration syntax error" 78 | failure $"not reloading $httpd due to configuration syntax error" 79 | else 80 | # Force LSB behaviour from killproc 81 | LSB=1 killproc -p ${pidfile} $httpd -HUP 82 | RETVAL=$? 83 | if [ $RETVAL -eq 7 ]; then 84 | failure $"httpd shutdown" 85 | fi 86 | fi 87 | echo 88 | } 89 | 90 | # See how we were called. 91 | case "$1" in 92 | start) 93 | start 94 | ;; 95 | stop) 96 | stop 97 | ;; 98 | status) 99 | status -p ${pidfile} $httpd 100 | RETVAL=$? 101 | ;; 102 | restart) 103 | stop 104 | start 105 | ;; 106 | condrestart|try-restart) 107 | if status -p ${pidfile} $httpd >&/dev/null; then 108 | stop 109 | start 110 | fi 111 | ;; 112 | force-reload|reload) 113 | reload 114 | ;; 115 | graceful|help|configtest|fullstatus) 116 | $apachectl $@ 117 | RETVAL=$? 118 | ;; 119 | *) 120 | echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" 121 | RETVAL=2 122 | esac 123 | 124 | exit $RETVAL 125 | -------------------------------------------------------------------------------- /templates/default/2.2/sysvinit/ubuntu-10.04/apache2.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: <%= @apache_name %> 4 | # Required-Start: $local_fs $remote_fs $network $syslog $named 5 | # Required-Stop: $local_fs $remote_fs $network $syslog $named 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # X-Interactive: true 9 | # Short-Description: Start/stop apache2 web server 10 | ### END INIT INFO 11 | 12 | set -e 13 | 14 | SCRIPTNAME="${0##*/}" 15 | SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}" 16 | if [ -n "$APACHE_CONFDIR" ] ; then 17 | if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then 18 | DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}" 19 | else 20 | DIR_SUFFIX= 21 | fi 22 | elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then 23 | DIR_SUFFIX="-${SCRIPTNAME##apache2-}" 24 | APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX 25 | else 26 | DIR_SUFFIX= 27 | APACHE_CONFDIR=/etc/apache2 28 | fi 29 | if [ -z "$APACHE_ENVVARS" ] ; then 30 | APACHE_ENVVARS=$APACHE_CONFDIR/envvars 31 | fi 32 | export APACHE_CONFDIR APACHE_ENVVARS 33 | 34 | ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin" 35 | if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then 36 | ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR" 37 | fi 38 | if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then 39 | ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS" 40 | fi 41 | 42 | 43 | #edit /etc/default/apache2 to change this. 44 | HTCACHECLEAN_RUN=auto 45 | HTCACHECLEAN_MODE=daemon 46 | HTCACHECLEAN_SIZE=300M 47 | HTCACHECLEAN_DAEMON_INTERVAL=120 48 | HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache 49 | HTCACHECLEAN_OPTIONS="" 50 | 51 | APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD) 52 | if [ -z "$APACHE_HTTPD" ] ; then 53 | APACHE_HTTPD=/usr/sbin/apache2 54 | fi 55 | if [ ! -x $APACHE_HTTPD ] ; then 56 | echo "No apache MPM package installed" 57 | exit 0 58 | fi 59 | 60 | . /lib/lsb/init-functions 61 | 62 | test -f /etc/default/rcS && . /etc/default/rcS 63 | 64 | if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then 65 | . /etc/default/apache2$DIR_SUFFIX 66 | elif [ -f /etc/default/apache2 ] ; then 67 | . /etc/default/apache2 68 | fi 69 | 70 | APACHE2CTL="$ENV /usr/sbin/apache2ctl" 71 | HTCACHECLEAN="$ENV /usr/sbin/htcacheclean" 72 | 73 | PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 74 | if [ -z "$PIDFILE" ] ; then 75 | echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2 76 | exit 2 77 | fi 78 | 79 | 80 | check_htcacheclean() { 81 | [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1 82 | 83 | [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0 84 | 85 | MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED) 86 | [ "$HTCACHECLEAN_RUN" = "auto" \ 87 | -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \ 88 | return 0 89 | 90 | return 1 91 | } 92 | 93 | start_htcacheclean() { 94 | if [ ! -d "$HTCACHECLEAN_PATH" ] ; then 95 | echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2 96 | return 1 97 | fi 98 | $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \ 99 | -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE 100 | } 101 | 102 | stop_htcacheclean() { 103 | pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || echo ...not running 104 | } 105 | 106 | pidof_apache() { 107 | # if there is actually an apache2 process whose pid is in PIDFILE, 108 | # print it and return 0. 109 | if [ -e "$PIDFILE" ]; then 110 | if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then 111 | return 0 112 | fi 113 | fi 114 | return 1 115 | } 116 | 117 | apache_stop() { 118 | if $APACHE2CTL configtest > /dev/null 2>&1; then 119 | # if the config is ok than we just stop normaly 120 | $APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 || true 121 | else 122 | # if we are here something is broken and we need to try 123 | # to exit as nice and clean as possible 124 | PID=$(pidof_apache) || true 125 | 126 | if [ "${PID}" ]; then 127 | # in this case it is everything nice and dandy and we kill apache2 128 | echo 129 | log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!" 130 | kill $PID 131 | elif [ "$(pidof apache2)" ]; then 132 | if [ "$VERBOSE" != no ]; then 133 | echo " ... failed!" 134 | echo "You may still have some apache2 processes running. There are" 135 | echo "processes named 'apache2' which do not match your pid file," 136 | echo "and in the name of safety, we've left them alone. Please review" 137 | echo "the situation by hand." 138 | fi 139 | return 1 140 | fi 141 | fi 142 | } 143 | 144 | apache_wait_stop() { 145 | # running ? 146 | PIDTMP=$(pidof_apache) || true 147 | if kill -0 "${PIDTMP:-}" 2> /dev/null; then 148 | PID=$PIDTMP 149 | fi 150 | 151 | apache_stop 152 | 153 | # wait until really stopped 154 | if [ -n "${PID:-}" ]; then 155 | i=0 156 | while kill -0 "${PID:-}" 2> /dev/null; do 157 | if [ $i = '60' ]; then 158 | break; 159 | else 160 | if [ $i = '0' ]; then 161 | echo -n " ... waiting " 162 | else 163 | echo -n "." 164 | fi 165 | i=$(($i+1)) 166 | sleep 1 167 | fi 168 | done 169 | fi 170 | } 171 | 172 | case $1 in 173 | start) 174 | log_daemon_msg "Starting web server" "apache2" 175 | if $APACHE2CTL start; then 176 | if check_htcacheclean ; then 177 | log_progress_msg htcacheclean 178 | start_htcacheclean || log_end_msg 1 179 | fi 180 | log_end_msg 0 181 | else 182 | log_end_msg 1 183 | fi 184 | ;; 185 | stop) 186 | if check_htcacheclean ; then 187 | log_daemon_msg "Stopping web server" "htcacheclean" 188 | stop_htcacheclean 189 | log_progress_msg "apache2" 190 | else 191 | log_daemon_msg "Stopping web server" "apache2" 192 | fi 193 | if apache_wait_stop; then 194 | log_end_msg 0 195 | else 196 | log_end_msg 1 197 | fi 198 | ;; 199 | graceful-stop) 200 | if check_htcacheclean ; then 201 | log_daemon_msg "Stopping web server" "htcacheclean" 202 | stop_htcacheclean 203 | log_progress_msg "apache2" 204 | else 205 | log_daemon_msg "Stopping web server" "apache2" 206 | fi 207 | if $APACHE2CTL graceful-stop; then 208 | log_end_msg 0 209 | else 210 | log_end_msg 1 211 | fi 212 | ;; 213 | reload | force-reload | graceful) 214 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 215 | $APACHE2CTL configtest || true 216 | log_end_msg 1 217 | exit 1 218 | fi 219 | log_daemon_msg "Reloading web server config" "apache2" 220 | if pidof_apache > /dev/null ; then 221 | if $APACHE2CTL graceful $2 ; then 222 | log_end_msg 0 223 | else 224 | log_end_msg 1 225 | fi 226 | fi 227 | ;; 228 | restart) 229 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 230 | $APACHE2CTL configtest || true 231 | log_end_msg 1 232 | exit 1 233 | fi 234 | if check_htcacheclean ; then 235 | log_daemon_msg "Restarting web server" "htcacheclean" 236 | stop_htcacheclean 237 | log_progress_msg apache2 238 | else 239 | log_daemon_msg "Restarting web server" "apache2" 240 | fi 241 | PID=$(pidof_apache) || true 242 | if ! apache_wait_stop; then 243 | log_end_msg 1 || true 244 | fi 245 | if $APACHE2CTL start; then 246 | if check_htcacheclean ; then 247 | start_htcacheclean || log_end_msg 1 248 | fi 249 | log_end_msg 0 250 | else 251 | log_end_msg 1 252 | fi 253 | ;; 254 | start-htcacheclean) 255 | log_daemon_msg "Starting htcacheclean" 256 | start_htcacheclean || log_end_msg 1 257 | log_end_msg 0 258 | ;; 259 | stop-htcacheclean) 260 | log_daemon_msg "Stopping htcacheclean" 261 | stop_htcacheclean 262 | log_end_msg 0 263 | ;; 264 | status) 265 | PID=$(pidof_apache) || true 266 | if [ -n "$PID" ]; then 267 | echo "Apache2$DIR_SUFFIX is running (pid $PID)." 268 | exit 0 269 | else 270 | echo "Apache2$DIR_SUFFIX is NOT running." 271 | if [ -e "$PIDFILE" ]; then 272 | exit 1 273 | else 274 | exit 3 275 | fi 276 | fi 277 | ;; 278 | *) 279 | log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}" 280 | exit 1 281 | ;; 282 | esac 283 | -------------------------------------------------------------------------------- /templates/default/2.2/sysvinit/ubuntu-12.04/apache2.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: <%= @apache_name %> 4 | # Required-Start: $local_fs $remote_fs $network $syslog $named 5 | # Required-Stop: $local_fs $remote_fs $network $syslog $named 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # X-Interactive: true 9 | # Short-Description: Start/stop apache2 web server 10 | ### END INIT INFO 11 | 12 | set -e 13 | 14 | SCRIPTNAME="${0##*/}" 15 | SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}" 16 | if [ -n "$APACHE_CONFDIR" ] ; then 17 | if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then 18 | DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}" 19 | else 20 | DIR_SUFFIX= 21 | fi 22 | elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then 23 | DIR_SUFFIX="-${SCRIPTNAME##apache2-}" 24 | APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX 25 | else 26 | DIR_SUFFIX= 27 | APACHE_CONFDIR=/etc/apache2 28 | fi 29 | if [ -z "$APACHE_ENVVARS" ] ; then 30 | APACHE_ENVVARS=$APACHE_CONFDIR/envvars 31 | fi 32 | export APACHE_CONFDIR APACHE_ENVVARS 33 | 34 | ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin" 35 | if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then 36 | ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR" 37 | fi 38 | if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then 39 | ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS" 40 | fi 41 | 42 | 43 | #edit /etc/default/apache2 to change this. 44 | HTCACHECLEAN_RUN=auto 45 | HTCACHECLEAN_MODE=daemon 46 | HTCACHECLEAN_SIZE=300M 47 | HTCACHECLEAN_DAEMON_INTERVAL=120 48 | HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_disk_cache 49 | HTCACHECLEAN_OPTIONS="" 50 | 51 | APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD) 52 | if [ -z "$APACHE_HTTPD" ] ; then 53 | APACHE_HTTPD=/usr/sbin/apache2 54 | fi 55 | if [ ! -x $APACHE_HTTPD ] ; then 56 | echo "No apache MPM package installed" 57 | exit 0 58 | fi 59 | 60 | . /lib/lsb/init-functions 61 | 62 | test -f /etc/default/rcS && . /etc/default/rcS 63 | 64 | if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then 65 | . /etc/default/apache2$DIR_SUFFIX 66 | elif [ -f /etc/default/apache2 ] ; then 67 | . /etc/default/apache2 68 | fi 69 | 70 | APACHE2CTL="$ENV /usr/sbin/apache2ctl" 71 | HTCACHECLEAN="$ENV /usr/sbin/htcacheclean" 72 | 73 | PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 74 | if [ -z "$PIDFILE" ] ; then 75 | echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2 76 | exit 2 77 | fi 78 | 79 | 80 | check_htcacheclean() { 81 | [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1 82 | 83 | [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0 84 | 85 | MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED) 86 | [ "$HTCACHECLEAN_RUN" = "auto" \ 87 | -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \ 88 | return 0 89 | 90 | return 1 91 | } 92 | 93 | start_htcacheclean() { 94 | if [ ! -d "$HTCACHECLEAN_PATH" ] ; then 95 | echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2 96 | return 1 97 | fi 98 | $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \ 99 | -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE 100 | } 101 | 102 | stop_htcacheclean() { 103 | pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || echo ...not running 104 | } 105 | 106 | pidof_apache() { 107 | # if there is actually an apache2 process whose pid is in PIDFILE, 108 | # print it and return 0. 109 | if [ -e "$PIDFILE" ]; then 110 | if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then 111 | return 0 112 | fi 113 | fi 114 | return 1 115 | } 116 | 117 | apache_stop() { 118 | if $APACHE2CTL configtest > /dev/null 2>&1; then 119 | # if the config is ok than we just stop normaly 120 | $APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 || true 121 | else 122 | # if we are here something is broken and we need to try 123 | # to exit as nice and clean as possible 124 | PID=$(pidof_apache) || true 125 | 126 | if [ "${PID}" ]; then 127 | # in this case it is everything nice and dandy and we kill apache2 128 | echo 129 | log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!" 130 | kill $PID 131 | elif [ "$(pidof apache2)" ]; then 132 | if [ "$VERBOSE" != no ]; then 133 | echo " ... failed!" 134 | echo "You may still have some apache2 processes running. There are" 135 | echo "processes named 'apache2' which do not match your pid file," 136 | echo "and in the name of safety, we've left them alone. Please review" 137 | echo "the situation by hand." 138 | fi 139 | return 1 140 | fi 141 | fi 142 | } 143 | 144 | apache_wait_stop() { 145 | # running ? 146 | PIDTMP=$(pidof_apache) || true 147 | if kill -0 "${PIDTMP:-}" 2> /dev/null; then 148 | PID=$PIDTMP 149 | fi 150 | 151 | apache_stop 152 | 153 | # wait until really stopped 154 | if [ -n "${PID:-}" ]; then 155 | i=0 156 | while kill -0 "${PID:-}" 2> /dev/null; do 157 | if [ $i = '60' ]; then 158 | break; 159 | else 160 | if [ $i = '0' ]; then 161 | echo -n " ... waiting " 162 | else 163 | echo -n "." 164 | fi 165 | i=$(($i+1)) 166 | sleep 1 167 | fi 168 | done 169 | fi 170 | } 171 | 172 | case $1 in 173 | start) 174 | log_daemon_msg "Starting web server" "apache2" 175 | if $APACHE2CTL start; then 176 | if check_htcacheclean ; then 177 | log_progress_msg htcacheclean 178 | start_htcacheclean || log_end_msg 1 179 | fi 180 | log_end_msg 0 181 | else 182 | log_end_msg 1 183 | fi 184 | ;; 185 | stop) 186 | if check_htcacheclean ; then 187 | log_daemon_msg "Stopping web server" "htcacheclean" 188 | stop_htcacheclean 189 | log_progress_msg "apache2" 190 | else 191 | log_daemon_msg "Stopping web server" "apache2" 192 | fi 193 | if apache_wait_stop; then 194 | log_end_msg 0 195 | else 196 | log_end_msg 1 197 | fi 198 | ;; 199 | graceful-stop) 200 | if check_htcacheclean ; then 201 | log_daemon_msg "Stopping web server" "htcacheclean" 202 | stop_htcacheclean 203 | log_progress_msg "apache2" 204 | else 205 | log_daemon_msg "Stopping web server" "apache2" 206 | fi 207 | if $APACHE2CTL graceful-stop; then 208 | log_end_msg 0 209 | else 210 | log_end_msg 1 211 | fi 212 | ;; 213 | reload | force-reload | graceful) 214 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 215 | $APACHE2CTL configtest || true 216 | log_end_msg 1 217 | exit 1 218 | fi 219 | log_daemon_msg "Reloading web server config" "apache2" 220 | if pidof_apache > /dev/null ; then 221 | if $APACHE2CTL graceful $2 ; then 222 | log_end_msg 0 223 | else 224 | log_end_msg 1 225 | fi 226 | fi 227 | ;; 228 | restart) 229 | if ! $APACHE2CTL configtest > /dev/null 2>&1; then 230 | $APACHE2CTL configtest || true 231 | log_end_msg 1 232 | exit 1 233 | fi 234 | if check_htcacheclean ; then 235 | log_daemon_msg "Restarting web server" "htcacheclean" 236 | stop_htcacheclean 237 | log_progress_msg apache2 238 | else 239 | log_daemon_msg "Restarting web server" "apache2" 240 | fi 241 | PID=$(pidof_apache) || true 242 | if ! apache_wait_stop; then 243 | log_end_msg 1 || true 244 | fi 245 | if $APACHE2CTL start; then 246 | if check_htcacheclean ; then 247 | start_htcacheclean || log_end_msg 1 248 | fi 249 | log_end_msg 0 250 | else 251 | log_end_msg 1 252 | fi 253 | ;; 254 | start-htcacheclean) 255 | log_daemon_msg "Starting htcacheclean" 256 | start_htcacheclean || log_end_msg 1 257 | log_end_msg 0 258 | ;; 259 | stop-htcacheclean) 260 | log_daemon_msg "Stopping htcacheclean" 261 | stop_htcacheclean 262 | log_end_msg 0 263 | ;; 264 | status) 265 | PID=$(pidof_apache) || true 266 | if [ -n "$PID" ]; then 267 | echo "Apache2$DIR_SUFFIX is running (pid $PID)." 268 | exit 0 269 | else 270 | echo "Apache2$DIR_SUFFIX is NOT running." 271 | if [ -e "$PIDFILE" ]; then 272 | exit 1 273 | else 274 | exit 3 275 | fi 276 | fi 277 | ;; 278 | *) 279 | log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}" 280 | exit 1 281 | ;; 282 | esac 283 | -------------------------------------------------------------------------------- /templates/default/2.4/mods/rhel/mpm.conf.erb: -------------------------------------------------------------------------------- 1 | LoadModule mpm_<%= @mpm %>_module modules/mod_mpm_<%= @mpm %>.so 2 | 3 | _module> 4 | <% if @startservers %> 5 | StartServers <%= @startservers %> 6 | <% end %> 7 | <% if @minspareservers %> 8 | MinSpareServers <%= @minspareservers %> 9 | <% end %> 10 | <% if @maxspareservers %> 11 | MaxSpareServers <%= @maxspareservers %> 12 | <% end %> 13 | <% if @maxclients %> 14 | MaxClients <%= @maxclients %> 15 | <% end %> 16 | <% if @maxrequestsperchild %> 17 | MaxRequestsPerChild <%= @maxrequestsperchild %> 18 | <% end %> 19 | <% if @minsparethreads %> 20 | MinSpareThreads <%= @minsparethreads %> 21 | <% end %> 22 | <% if @maxsparethreads %> 23 | MaxSpareThreads <%= @maxsparethreads %> 24 | <% end %> 25 | <% if @threadlimit %> 26 | ThreadLimit <%= @threadlimit %> 27 | <% end %> 28 | <% if @threadsperchild %> 29 | ThreadsPerChild <%= @threadsperchild %> 30 | <% end %> 31 | <% if @maxrequestworkers %> 32 | MaxRequestWorkers <%= @maxrequestworkers %> 33 | <% end %> 34 | <% if @maxconnectionsperchild %> 35 | MaxConnectionsPerChild <%= @maxconnectionsperchild %> 36 | <% end %> 37 | 38 | -------------------------------------------------------------------------------- /templates/default/2.4/sysvinit/el-6/httpd.erb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # 19 | # httpd Startup script for the Apache Web Server 20 | # 21 | # chkconfig: - 85 15 22 | # description: The Apache HTTP Server is an efficient and extensible \ 23 | # server implementing the current HTTP standards. 24 | # processname: httpd 25 | # pidfile: /var/run/httpd.pid 26 | # config: /etc/sysconfig/httpd 27 | # 28 | ### BEGIN INIT INFO 29 | # Provides: httpd 30 | # Required-Start: $local_fs $remote_fs $network $named 31 | # Required-Stop: $local_fs $remote_fs $network 32 | # Should-Start: distcache 33 | # Short-Description: start and stop Apache HTTP Server 34 | # Description: The Apache HTTP Server is an extensible server 35 | # implementing the current HTTP standards. 36 | ### END INIT INFO 37 | 38 | # Source function library. 39 | . /etc/rc.d/init.d/functions 40 | 41 | # What were we called? Multiple instances of the same daemon can be 42 | # created by creating suitably named symlinks to this startup script 43 | prog=$(basename $0 | sed -e 's/^[SK][0-9][0-9]//') 44 | 45 | if [ -f /etc/sysconfig/${prog} ]; then 46 | . /etc/sysconfig/${prog} 47 | fi 48 | 49 | # Start httpd in the C locale by default. 50 | HTTPD_LANG=${HTTPD_LANG-"C"} 51 | 52 | # This will prevent initlog from swallowing up a pass-phrase prompt if 53 | # mod_ssl needs a pass-phrase from the user. 54 | INITLOG_ARGS="" 55 | 56 | # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server 57 | # with the thread-based "worker" MPM; BE WARNED that some modules may not 58 | # work correctly with a thread-based MPM; notably PHP will refuse to start. 59 | 60 | httpd=${HTTPD-/usr/sbin/httpd} 61 | pidfile=${PIDFILE-/var/run/httpd/${prog}.pid} 62 | lockfile=${LOCKFILE-/var/lock/subsys/${prog}} 63 | RETVAL=0 64 | 65 | # check for 1.3 configuration 66 | check13 () { 67 | CONFFILE=/etc/httpd/conf/httpd.conf 68 | GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|" 69 | GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|" 70 | GONE="${GONE}AccessConfig|ResourceConfig)" 71 | if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then 72 | echo 73 | echo 1>&2 " Apache 1.3 configuration directives found" 74 | echo 1>&2 " please read @docdir@/migration.html" 75 | failure "Apache 1.3 config directives test" 76 | echo 77 | exit 1 78 | fi 79 | } 80 | 81 | # The semantics of these two functions differ from the way apachectl does 82 | # things -- attempting to start while running is a failure, and shutdown 83 | # when not running is also a failure. So we just do it the way init scripts 84 | # are expected to behave here. 85 | start() { 86 | echo -n $"Starting $prog: " 87 | check13 || exit 1 88 | LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS 89 | RETVAL=$? 90 | echo 91 | [ $RETVAL = 0 ] && touch ${lockfile} 92 | return $RETVAL 93 | } 94 | stop() { 95 | echo -n $"Stopping $prog: " 96 | killproc -p ${pidfile} -d 10 $httpd 97 | RETVAL=$? 98 | echo 99 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} 100 | } 101 | reload() { 102 | echo -n $"Reloading $prog: " 103 | check13 || exit 1 104 | killproc -p ${pidfile} $httpd -HUP 105 | RETVAL=$? 106 | echo 107 | } 108 | 109 | # See how we were called. 110 | case "$1" in 111 | start) 112 | start 113 | ;; 114 | stop) 115 | stop 116 | ;; 117 | status) 118 | if ! test -f ${pidfile}; then 119 | echo $prog is stopped 120 | RETVAL=3 121 | else 122 | status -p ${pidfile} $httpd 123 | RETVAL=$? 124 | fi 125 | ;; 126 | restart) 127 | stop 128 | start 129 | ;; 130 | condrestart) 131 | if test -f ${pidfile} && status -p ${pidfile} $httpd >&/dev/null; then 132 | stop 133 | start 134 | fi 135 | ;; 136 | reload) 137 | reload 138 | ;; 139 | configtest) 140 | LANG=$HTTPD_LANG $httpd $OPTIONS -t 141 | RETVAL=$? 142 | ;; 143 | graceful) 144 | echo -n $"Gracefully restarting $prog: " 145 | LANG=$HTTPD_LANG $httpd $OPTIONS -k $@ 146 | RETVAL=$? 147 | echo 148 | ;; 149 | *) 150 | echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|graceful|help|configtest}" 151 | exit 1 152 | esac 153 | 154 | exit $RETVAL 155 | 156 | -------------------------------------------------------------------------------- /templates/default/2.4/sysvinit/ubuntu-14.04/apache2.erb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: <%= @apache_name %> 4 | # Required-Start: $local_fs $remote_fs $network $syslog $named 5 | # Required-Stop: $local_fs $remote_fs $network $syslog $named 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # X-Interactive: true 9 | # Short-Description: Start/stop apache2 web server 10 | # Description: Start the web server and associated helpers 11 | # This script will start apache2, and possibly all associated instances. 12 | # Moreover, it will set-up temporary directories and helper tools such as 13 | # htcacheclean when required by the configuration. 14 | ### END INIT INFO 15 | 16 | # set -x 17 | 18 | DESC="web server" 19 | NAME=apache2 20 | DAEMON=/usr/sbin/$NAME 21 | 22 | SCRIPTNAME="${0##*/}" 23 | SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}" 24 | if [ -n "$APACHE_CONFDIR" ] ; then 25 | if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then 26 | DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}" 27 | else 28 | DIR_SUFFIX= 29 | fi 30 | elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then 31 | DIR_SUFFIX="-${SCRIPTNAME##apache2-}" 32 | APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX 33 | else 34 | DIR_SUFFIX= 35 | APACHE_CONFDIR=/etc/apache2 36 | fi 37 | if [ -z "$APACHE_ENVVARS" ] ; then 38 | APACHE_ENVVARS=$APACHE_CONFDIR/envvars 39 | fi 40 | export APACHE_CONFDIR APACHE_ENVVARS 41 | 42 | ENV="env -i LANG=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 43 | if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then 44 | ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR" 45 | fi 46 | if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then 47 | ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS" 48 | fi 49 | 50 | 51 | #edit /etc/default/apache2 to change this. 52 | HTCACHECLEAN_RUN=auto 53 | HTCACHECLEAN_MODE=daemon 54 | HTCACHECLEAN_SIZE=300M 55 | HTCACHECLEAN_DAEMON_INTERVAL=120 56 | HTCACHECLEAN_PATH=/var/cache/apache2$DIR_SUFFIX/mod_cache_disk 57 | HTCACHECLEAN_OPTIONS="" 58 | 59 | # Read configuration variable file if it is present 60 | if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then 61 | . /etc/default/apache2$DIR_SUFFIX 62 | elif [ -f /etc/default/apache2 ] ; then 63 | . /etc/default/apache2 64 | fi 65 | 66 | PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 67 | 68 | VERBOSE=no 69 | if [ -f /etc/default/rcS ]; then 70 | . /etc/default/rcS 71 | fi 72 | . /lib/lsb/init-functions 73 | 74 | 75 | # Now, set defaults: 76 | APACHE2CTL="$ENV apache2ctl" 77 | HTCACHECLEAN="$ENV htcacheclean" 78 | PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE) 79 | APACHE2_INIT_MESSAGE="" 80 | 81 | CONFTEST_OUTFILE= 82 | cleanup() { 83 | if [ -n "$CONFTEST_OUTFILE" ] ; then 84 | rm -f "$CONFTEST_OUTFILE" 85 | fi 86 | } 87 | trap cleanup 0 # "0" means "EXIT", but "EXIT" is not portable 88 | 89 | 90 | apache_conftest() { 91 | [ -z "$CONFTEST_OUTFILE" ] || rm -f "$CONFTEST_OUTFILE" 92 | CONFTEST_OUTFILE=$(mktemp) 93 | if ! $APACHE2CTL configtest > "$CONFTEST_OUTFILE" 2>&1 ; then 94 | return 1 95 | else 96 | rm -f "$CONFTEST_OUTFILE" 97 | CONFTEST_OUTFILE= 98 | return 0 99 | fi 100 | } 101 | 102 | clear_error_msg() { 103 | [ -z "$CONFTEST_OUTFILE" ] || rm -f "$CONFTEST_OUTFILE" 104 | CONFTEST_OUTFILE= 105 | APACHE2_INIT_MESSAGE= 106 | } 107 | 108 | print_error_msg() { 109 | [ -z "$APACHE2_INIT_MESSAGE" ] || log_warning_msg "$APACHE2_INIT_MESSAGE" 110 | if [ -n "$CONFTEST_OUTFILE" ] ; then 111 | echo "Output of config test was:" >&2 112 | cat "$CONFTEST_OUTFILE" >&2 113 | rm -f "$CONFTEST_OUTFILE" 114 | CONFTEST_OUTFILE= 115 | fi 116 | } 117 | 118 | apache_wait_start() { 119 | local STATUS=$1 120 | local i=0 121 | while : ; do 122 | PIDTMP=$(pidofproc -p $PIDFILE $DAEMON) 123 | if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then 124 | return $STATUS 125 | fi 126 | 127 | if [ $i = "20" ] ; then 128 | APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX instance did not start within 20 seconds. Please read the log files to discover problems" 129 | return 2 130 | fi 131 | 132 | [ "$VERBOSE" != no ] && log_progress_msg "." 133 | sleep 1 134 | i=$(($i+1)) 135 | done 136 | } 137 | 138 | apache_wait_stop() { 139 | local STATUS=$1 140 | 141 | PIDTMP=$(pidofproc -p $PIDFILE $DAEMON) 142 | if [ -n "${PIDTMP:-}" ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then 143 | local i=0 144 | while kill -0 "${PIDTMP:-}" 2> /dev/null; do 145 | if [ $i = '60' ]; then 146 | break 147 | STATUS=2 148 | fi 149 | [ "$VERBOSE" != no ] && log_progress_msg "." 150 | sleep 1 151 | i=$(($i+1)) 152 | done 153 | return $STATUS 154 | else 155 | return $STATUS 156 | fi 157 | } 158 | 159 | 160 | # 161 | # Function that starts the daemon/service 162 | # 163 | do_start() 164 | { 165 | # Return 166 | # 0 if daemon has been started 167 | # 1 if daemon was already running 168 | # 2 if daemon could not be started 169 | 170 | if pidofproc -p $PIDFILE "$DAEMON" > /dev/null 2>&1 ; then 171 | return 1 172 | fi 173 | 174 | if apache_conftest ; then 175 | $APACHE2CTL start 176 | apache_wait_start $? 177 | return $? 178 | else 179 | APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed." 180 | return 2 181 | fi 182 | } 183 | 184 | # 185 | # Function that stops the daemon/service 186 | # 187 | do_stop() 188 | { 189 | # Return 190 | # 0 if daemon has been stopped 191 | # 1 if daemon was already stopped 192 | # 2 if daemon could not be stopped 193 | # other if a failure occurred 194 | 195 | # either "stop" or "graceful-stop" 196 | local STOP=$1 197 | # can't use pidofproc from LSB here 198 | local AP_RET=0 199 | 200 | if pidof $DAEMON > /dev/null 2>&1 ; then 201 | if [ -e $PIDFILE ] && pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE) > /dev/null 2>&1 ; then 202 | AP_RET=2 203 | else 204 | AP_RET=1 205 | fi 206 | else 207 | AP_RET=0 208 | fi 209 | 210 | # AP_RET is: 211 | # 0 if Apache (whichever) is not running 212 | # 1 if Apache (whichever) is running 213 | # 2 if Apache from the PIDFILE is running 214 | 215 | if [ $AP_RET = 0 ] ; then 216 | return 1 217 | fi 218 | 219 | if [ $AP_RET = 2 ] && apache_conftest ; then 220 | $APACHE2CTL $STOP > /dev/null 2>&1 221 | apache_wait_stop $? 222 | return $? 223 | else 224 | if [ $AP_RET = 2 ]; then 225 | clear_error_msg 226 | APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!" 227 | killproc -p $PIDFILE $DAEMON 228 | apache_wait_stop $? 229 | return $? 230 | elif [ $AP_RET = 1 ] ; then 231 | APACHE2_INIT_MESSAGE="There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand". 232 | return 2 233 | fi 234 | fi 235 | 236 | } 237 | 238 | 239 | # 240 | # Function that sends a SIGHUP to the daemon/service 241 | # 242 | do_reload() { 243 | if apache_conftest; then 244 | if ! pidofproc -p $PIDFILE "$DAEMON" > /dev/null 2>&1 ; then 245 | APACHE2_INIT_MESSAGE="Apache2 is not running" 246 | return 2 247 | fi 248 | $APACHE2CTL graceful > /dev/null 2>&1 249 | return $? 250 | else 251 | APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed. Not doing anything." 252 | return 2 253 | fi 254 | } 255 | 256 | 257 | check_htcacheclean() { 258 | [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1 259 | [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0 260 | 261 | MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED) 262 | [ "$HTCACHECLEAN_RUN" = "auto" \ 263 | -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/cache_disk.load ] && \ 264 | return 0 265 | return 1 266 | } 267 | 268 | start_htcacheclean() { 269 | $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \ 270 | -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE 271 | } 272 | 273 | stop_htcacheclean() { 274 | pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || return 1 275 | } 276 | 277 | 278 | # Sanity checks. They need to occur after function declarations 279 | [ -x $DAEMON ] || exit 0 280 | 281 | if [ ! -x $DAEMON ] ; then 282 | echo "No apache-bin package installed" 283 | exit 0 284 | fi 285 | 286 | if [ -z "$PIDFILE" ] ; then 287 | echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2 288 | exit 2 289 | fi 290 | 291 | if check_htcacheclean ; then 292 | if [ ! -d "$HTCACHECLEAN_PATH" ] ; then 293 | echo "htcacheclean is configured, but directory $HTCACHECLEAN_PATH does not exist!" >&2 294 | exit 2 295 | fi 296 | fi 297 | 298 | 299 | 300 | case "$1" in 301 | start) 302 | log_daemon_msg "Starting $DESC" "$NAME" 303 | do_start 304 | RET_STATUS=$? 305 | case "$RET_STATUS" in 306 | 0|1) 307 | log_success_msg 308 | [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was already running" 309 | if check_htcacheclean ; then 310 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting HTTP cache cleaning daemon" "htcacheclean" 311 | start_htcacheclean 312 | [ "$VERBOSE" != no ] && log_end_msg $? 313 | fi 314 | ;; 315 | 2) 316 | log_failure_msg 317 | print_error_msg 318 | exit 1 319 | ;; 320 | esac 321 | ;; 322 | stop|graceful-stop) 323 | log_daemon_msg "Stopping $DESC" "$NAME" 324 | do_stop "$1" 325 | RET_STATUS=$? 326 | case "$RET_STATUS" in 327 | 0|1) 328 | log_success_msg 329 | [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was not running" 330 | ;; 331 | 2) 332 | log_failure_msg 333 | print_error_msg 334 | exit 1 335 | ;; 336 | esac 337 | print_error_msg 338 | 339 | if check_htcacheclean ; then 340 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping HTTP cache cleaning daemon" "htcacheclean" 341 | stop_htcacheclean 342 | [ "$VERBOSE" != no ] && log_end_msg $? 343 | fi 344 | 345 | ;; 346 | status) 347 | status_of_proc -p $PIDFILE "apache2" "$NAME" 348 | exit $? 349 | ;; 350 | reload|force-reload|graceful) 351 | log_daemon_msg "Reloading $DESC" "$NAME" 352 | do_reload 353 | RET_STATUS=$? 354 | case "$RET_STATUS" in 355 | 0|1) 356 | log_success_msg 357 | [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was already running" 358 | ;; 359 | 2) 360 | log_failure_msg 361 | print_error_msg 362 | exit 1 363 | ;; 364 | esac 365 | print_error_msg 366 | ;; 367 | restart) 368 | log_daemon_msg "Restarting $DESC" "$NAME" 369 | do_stop stop 370 | case "$?" in 371 | 0|1) 372 | do_start 373 | case "$?" in 374 | 0) 375 | log_end_msg 0 376 | ;; 377 | 1|*) 378 | log_end_msg 1 # Old process is still or failed to running 379 | print_error_msg 380 | exit 1 381 | ;; 382 | esac 383 | ;; 384 | *) 385 | # Failed to stop 386 | log_end_msg 1 387 | print_error_msg 388 | exit 1 389 | ;; 390 | esac 391 | ;; 392 | start-htcacheclean) 393 | log_daemon_msg "Starting htcacheclean" 394 | start_htcacheclean 395 | log_end_msg $? 396 | exit $? 397 | ;; 398 | stop-htcacheclean) 399 | log_daemon_msg "Stopping htcacheclean" 400 | stop_htcacheclean 401 | log_end_msg $? 402 | exit $? 403 | ;; 404 | *) 405 | echo "Usage: $SCRIPTNAME {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean}" >&2 406 | exit 3 407 | ;; 408 | esac 409 | 410 | exit 0 411 | 412 | # vim: syntax=sh ts=4 sw=4 sts=4 sr noet 413 | -------------------------------------------------------------------------------- /templates/default/envvars.erb: -------------------------------------------------------------------------------- 1 | unset HOME 2 | if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then 3 | SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}" 4 | else 5 | SUFFIX= 6 | fi 7 | export APACHE_RUN_USER=<%= @run_user %> 8 | export APACHE_RUN_GROUP=<%= @run_group %> 9 | export APACHE_PID_FILE=<%= @pid_file %> 10 | export APACHE_RUN_DIR=<%= @run_dir %> 11 | export APACHE_LOCK_DIR=<%= @lock_dir %> 12 | export APACHE_LOG_DIR=<%= @log_dir %> 13 | export LANG=C 14 | export LANG 15 | -------------------------------------------------------------------------------- /templates/default/httpd.conf.erb: -------------------------------------------------------------------------------- 1 | <% if @servername %> 2 | ServerName <%= @servername %> 3 | <% end %> 4 | <% if @server_root %> 5 | ServerRoot <%= @server_root %> 6 | <% end %> 7 | <% if @pid_file %> 8 | PidFile <%= @pid_file %> 9 | <% end %> 10 | <% if @run_user %> 11 | User <%= @run_user %> 12 | <% end %> 13 | <% if @run_group %> 14 | Group <%= @run_group %> 15 | <% end %> 16 | <% if @lock_file %> 17 | LockFile <%= @lock_file %> 18 | <% end %> 19 | <% if @mutex %> 20 | Mutex <%= @mutex %> 21 | <% end %> 22 | <% if @config.timeout %> 23 | Timeout <%= @config.timeout %> 24 | <% end %> 25 | <% if @error_log %> 26 | ErrorLog <%= @error_log %> 27 | <% end %> 28 | <% if @config.log_level %> 29 | LogLevel <%= @config.log_level %> 30 | <% end %> 31 | <% if @config.keepalive %> 32 | KeepAlive On 33 | <% else %> 34 | KeepAlive Off 35 | <% end %> 36 | <% if @config.maxkeepaliverequests %> 37 | MaxKeepAliveRequests <%= @config.maxkeepaliverequests %> 38 | <% end %> 39 | <% if @config.keepalivetimeout %> 40 | KeepAliveTimeout <%= @config.keepalivetimeout %> 41 | <% end %> 42 | DefaultType None 43 | <% if @config.hostname_lookups %> 44 | HostnameLookups <%= @config.hostname_lookups %> 45 | <% end %> 46 | 47 | <% if @config.listen_addresses.nil? %> 48 | <% @config.listen_ports.each do |port| %> 49 | Listen <%= port %> 50 | <% end %> 51 | <% else %> 52 | <% Array(@config.listen_addresses).each do |address| %> 53 | <% @config.listen_ports.each do |port| %> 54 | Listen <%= address %>:<%= port %> 55 | <% end %> 56 | <% end %> 57 | <% end %> 58 | 59 | <% if @includes %> 60 | <% @includes.each do |i| %> 61 | Include <%= i %> 62 | <% end %> 63 | <% end %> 64 | <% if @include_optionals %> 65 | <% @include_optionals.each do |i| %> 66 | IncludeOptional <%= i %> 67 | <% end %> 68 | <% end %> 69 | -------------------------------------------------------------------------------- /templates/default/module_load.erb: -------------------------------------------------------------------------------- 1 | LoadModule <%= @module_name %> <%= @module_path %> 2 | -------------------------------------------------------------------------------- /templates/default/mpm.conf.erb: -------------------------------------------------------------------------------- 1 | _module> 2 | <% if @startservers %> 3 | StartServers <%= @startservers %> 4 | <% end %> 5 | <% if @minspareservers %> 6 | MinSpareServers <%= @minspareservers %> 7 | <% end %> 8 | <% if @maxspareservers %> 9 | MaxSpareServers <%= @maxspareservers %> 10 | <% end %> 11 | <% if @maxclients %> 12 | MaxClients <%= @maxclients %> 13 | <% end %> 14 | <% if @maxrequestsperchild %> 15 | MaxRequestsPerChild <%= @maxrequestsperchild %> 16 | <% end %> 17 | <% if @minsparethreads %> 18 | MinSpareThreads <%= @minsparethreads %> 19 | <% end %> 20 | <% if @maxsparethreads %> 21 | MaxSpareThreads <%= @maxsparethreads %> 22 | <% end %> 23 | <% if @threadlimit %> 24 | ThreadLimit <%= @threadlimit %> 25 | <% end %> 26 | <% if @threadsperchild %> 27 | ThreadsPerChild <%= @threadsperchild %> 28 | <% end %> 29 | <% if @maxrequestworkers %> 30 | MaxRequestWorkers <%= @maxrequestworkers %> 31 | <% end %> 32 | <% if @maxconnectionsperchild %> 33 | MaxConnectionsPerChild <%= @maxconnectionsperchild %> 34 | <% end %> 35 | 36 | -------------------------------------------------------------------------------- /templates/default/rhel/sysconfig/httpd-2.2.erb: -------------------------------------------------------------------------------- 1 | <% if @mpm == 'prefork' %> 2 | HTTPD=/usr/sbin/<%= @apache_name %> 3 | <% else %> 4 | HTTPD=/usr/sbin/<%= @apache_name %>.<%= @mpm %> 5 | <% end %> 6 | OPTIONS="-f /etc/<%= @apache_name %>/conf/httpd.conf" 7 | LOCKFILE=/var/lock/subsys/<%= @apache_name %> 8 | PIDFILE=<%= @pid_file %> 9 | -------------------------------------------------------------------------------- /templates/default/rhel/sysconfig/httpd-2.4.erb: -------------------------------------------------------------------------------- 1 | HTTPD=/usr/sbin/<%= @apache_name %> 2 | OPTIONS="-f /etc/<%= @apache_name %>/conf/httpd.conf" 3 | LOCKFILE=/var/lock/subsys/<%= @apache_name %> 4 | PIDFILE=<%= @pid_file %> 5 | -------------------------------------------------------------------------------- /templates/default/systemd/httpd.conf.erb: -------------------------------------------------------------------------------- 1 | d /run/<%= @apache_name %> 710 root <%= @run_user %> 2 | d /run/<%= @apache_name %>/htcacheclean 700 <%= @run_user %> <%= @run_group %> 3 | -------------------------------------------------------------------------------- /templates/default/systemd/httpd.service.erb: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=The Apache HTTP Server 3 | After=network.target remote-fs.target nss-lookup.target 4 | 5 | [Service] 6 | <% if node['platform_family'] == 'debian' %> 7 | Type=simple 8 | <% else %> 9 | Type=notify 10 | <% end %> 11 | Environment=LANG=C 12 | 13 | ExecStart=/usr/sbin/<%= @binary_name %> -f /etc/<%= @apache_name %>/<%= @config_relative_path %> -DFOREGROUND 14 | ExecReload=/usr/sbin/<%= @binary_name %> -f /etc/<%= @apache_name %>/<%= @config_relative_path %> -k graceful 15 | ExecStop=/bin/kill -WINCH ${MAINPID} 16 | 17 | KillSignal=SIGCONT 18 | PrivateTmp=true 19 | 20 | [Install] 21 | WantedBy=multi-user.target 22 | -------------------------------------------------------------------------------- /test/cookbooks/hello_world_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'hello_world_test' 2 | version '0.0.1' 3 | 4 | depends 'httpd' 5 | -------------------------------------------------------------------------------- /test/cookbooks/hello_world_test/recipes/default-docker.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | httpd_service 'default' do 4 | action :create 5 | end 6 | 7 | httpd_config 'hello' do 8 | source 'hello.erb' 9 | notifies :restart, 'httpd_service[default]' 10 | end 11 | 12 | file '/var/www/index.html' do 13 | content 'hello there\n' 14 | action :create 15 | end 16 | -------------------------------------------------------------------------------- /test/cookbooks/hello_world_test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | httpd_service 'default' do 4 | action [:create, :start] 5 | end 6 | 7 | httpd_config 'hello' do 8 | source 'hello.erb' 9 | notifies :restart, 'httpd_service[default]' 10 | end 11 | 12 | file '/var/www/index.html' do 13 | content 'hello there\n' 14 | action :create 15 | end 16 | -------------------------------------------------------------------------------- /test/cookbooks/hello_world_test/templates/default/hello.erb: -------------------------------------------------------------------------------- 1 | 2 | ServerAdmin webmaster@localhost 3 | 4 | DocumentRoot /var/www 5 | 6 | 7 | Options FollowSymLinks 8 | AllowOverride None 9 | 10 | 11 | 12 | Options Indexes FollowSymLinks MultiViews 13 | AllowOverride None 14 | Order allow,deny 15 | allow from all 16 | 17 | 18 | ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 19 | 20 | AllowOverride None 21 | Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 22 | Order allow,deny 23 | Allow from all 24 | 25 | 26 | LogLevel warn 27 | 28 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_config_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'httpd_config_test' 2 | version '0.0.1' 3 | 4 | depends 'httpd' 5 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_config_test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | httpd_config 'hello' do 4 | instance 'default' 5 | source 'hello.conf.erb' 6 | action :create 7 | end 8 | 9 | httpd_config 'hello_again' do 10 | instance 'foo' 11 | source 'hello.conf.erb' 12 | action :create 13 | end 14 | 15 | httpd_config 'sensitive' do 16 | instance 'sensitive' 17 | source 'sensitive.conf.erb' 18 | sensitive true 19 | variables( 20 | password: 'should_be_hidden') 21 | action :create 22 | end 23 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_config_test/templates/default/hello.conf.erb: -------------------------------------------------------------------------------- 1 | # hello there 2 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_config_test/templates/default/sensitive.conf.erb: -------------------------------------------------------------------------------- 1 | # hidden test 2 | <% if @password %> 3 | password <%= @password %> 4 | <% end %> -------------------------------------------------------------------------------- /test/cookbooks/httpd_module_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'httpd_module_test' 2 | version '0.0.1' 3 | 4 | depends 'httpd' 5 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_module_test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | httpd_module 'auth_basic' do 4 | httpd_version node['httpd']['version'] 5 | action :create 6 | end 7 | 8 | httpd_module 'proxy' do 9 | httpd_version node['httpd']['version'] 10 | action :create 11 | end 12 | 13 | httpd_module 'expires' do 14 | httpd_version node['httpd']['version'] 15 | action :create 16 | end 17 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['httpd']['service_name'] = 'default' 2 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'httpd_service_test' 2 | version '0.0.1' 3 | 4 | depends 'httpd' 5 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/recipes/actions.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | # This recipe creates a separate httpd_service listening on its own port(s) to 4 | # test each httpd_service action. Integration tests determine whether each 5 | # action was successful by checking for on-disk configuration, listening ports, 6 | # and contents of PID files. 7 | 8 | # Delete any services left over from previous converges. 9 | %w(create delete start stop restart reload).each do |act| 10 | httpd_service "cleanup #{act}_test" do 11 | instance "#{act}_test" 12 | action :delete 13 | end 14 | end 15 | 16 | ######################################## 17 | # action :create 18 | # setup: create an httpd_service 19 | # test: confirm that httpd configuration files exist. 20 | 21 | httpd_service 'create create_test' do 22 | instance 'create_test' 23 | listen_ports [8101] 24 | startservers '1' 25 | minspareservers '1' 26 | maxspareservers '1' 27 | action :create 28 | end 29 | 30 | ######################################## 31 | # action :delete 32 | # setup: create an httpd_service, then delete it. 33 | # test: confirm that httpd configuration files do not exist. 34 | 35 | httpd_service 'create & start delete_test' do 36 | instance 'delete_test' 37 | listen_ports [8102] 38 | startservers '1' 39 | minspareservers '1' 40 | maxspareservers '1' 41 | action [:create, :start] 42 | end 43 | 44 | httpd_service 'delete delete_test' do 45 | instance 'delete_test' 46 | action :delete 47 | end 48 | 49 | ######################################## 50 | # action :start 51 | # setup: create an httpd_service, then start it. 52 | # test: confirm that httpd service is listening on its assigned port. 53 | 54 | httpd_service 'create start_test' do 55 | instance 'start_test' 56 | listen_ports [8103] 57 | startservers '1' 58 | minspareservers '1' 59 | maxspareservers '1' 60 | action :create 61 | end 62 | 63 | httpd_service 'start start_test' do 64 | instance 'start_test' 65 | action :start 66 | end 67 | 68 | ######################################## 69 | # action :stop 70 | # setup: create and start an httpd_service, then stop it. 71 | # test: confirm that httpd service is not listening on its assigned port. 72 | 73 | httpd_service 'create & start stop_test' do 74 | instance 'stop_test' 75 | listen_ports [8104] 76 | startservers '1' 77 | minspareservers '1' 78 | maxspareservers '1' 79 | action [:create, :start] 80 | end 81 | 82 | httpd_service 'stop stop_test' do 83 | instance 'stop_test' 84 | action :stop 85 | end 86 | 87 | ######################################## 88 | # action :restart 89 | # setup: 1. create and start an httpd_service 90 | # 2. make a copy of its PID file, 91 | # 3. add another listen directive to the service's config 92 | # 4. restart the httpd_service 93 | # 5. make another copy of its PID file. 94 | # test: confirm that the two PID files contain valid PIDs, that the two PIDs 95 | # differ, and that the service is listening on both ports. 96 | 97 | restart_res = httpd_service 'create & start restart_test' do 98 | instance 'restart_test' 99 | listen_ports [8105] 100 | startservers '1' 101 | minspareservers '1' 102 | maxspareservers '1' 103 | action [:create, :start] 104 | end 105 | 106 | ruby_block 'wait for restart pid' do 107 | block do 108 | (1..15).each do |_v| 109 | sleep(1) unless ::File.exist?(restart_res.pid_file) 110 | end 111 | end 112 | end 113 | 114 | remote_file '/restart-pre-action-pids' do 115 | source "file://#{restart_res.pid_file}" 116 | end 117 | 118 | httpd_config 'new-listener' do 119 | instance 'restart_test' 120 | source 'new-listener.erb' 121 | variables(port: 8106) 122 | end 123 | 124 | httpd_service 'restart restart_test' do 125 | instance 'restart_test' 126 | action :restart 127 | notifies :run, 'ruby_block[wait for restart pid]', :immediately 128 | end 129 | 130 | remote_file '/restart-post-action-pids' do 131 | source "file://#{restart_res.pid_file}" 132 | end 133 | 134 | ######################################## 135 | # action :reload 136 | # setup: 1. create and start an httpd_service 137 | # 2. make a copy of its PID file, 138 | # 3. add another listen directive to the service's config 139 | # 4. reload the httpd_service 140 | # 5. make another copy of its PID file. 141 | # test: confirm that the two PID files contain valid PIDs, that the two PIDs 142 | # are the same, and that the service is listening on both ports. 143 | 144 | reload_res = httpd_service 'create & start reload_test' do 145 | instance 'reload_test' 146 | listen_ports [8107] 147 | startservers '1' 148 | minspareservers '1' 149 | maxspareservers '1' 150 | action [:create, :start] 151 | end 152 | 153 | ruby_block 'wait for reload pid' do 154 | block do 155 | (1..15).each do |_v| 156 | sleep(1) unless ::File.exist?(reload_res.pid_file) 157 | end 158 | end 159 | end 160 | 161 | remote_file '/reload-pre-action-pids' do 162 | source "file://#{reload_res.pid_file}" 163 | end 164 | 165 | httpd_config 'new-listener' do 166 | instance 'reload_test' 167 | source 'new-listener.erb' 168 | variables(port: 8108) 169 | end 170 | 171 | httpd_service 'reload reload_test' do 172 | instance 'reload_test' 173 | action :reload 174 | notifies :run, 'ruby_block[wait for reload pid]', :immediately 175 | end 176 | 177 | remote_file '/reload-post-action-pids' do 178 | source "file://#{reload_res.pid_file}" 179 | end 180 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/recipes/multi.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | group 'alice' do 4 | action :create 5 | end 6 | 7 | user 'alice' do 8 | gid 'alice' 9 | action :create 10 | end 11 | 12 | group 'bob' do 13 | action :create 14 | end 15 | 16 | user 'bob' do 17 | gid 'bob' 18 | action :create 19 | end 20 | 21 | httpd_service 'default' do 22 | action :delete 23 | end 24 | 25 | # hard code values where we can 26 | httpd_service 'instance-1' do 27 | contact 'hal@computers.biz' 28 | keepalive false 29 | maxkeepaliverequests '2001' 30 | keepalivetimeout '0' 31 | listen_ports %w(8080 4343) 32 | log_level 'warn' 33 | version node['httpd']['version'] 34 | run_user 'alice' 35 | run_group 'alice' 36 | timeout '4321' 37 | mpm 'prefork' 38 | startservers '10' 39 | minspareservers '10' 40 | maxspareservers '20' 41 | action [:create, :start] 42 | end 43 | 44 | # pass everything from node attributes 45 | httpd_service 'instance-2' do 46 | contact node['httpd']['contact'] 47 | keepalive node['httpd']['keepalive'] 48 | maxkeepaliverequests node['httpd']['maxkeepaliverequests'] 49 | keepalivetimeout node['httpd']['keepalivetimeout'] 50 | listen_ports node['httpd']['listen_ports'] 51 | log_level node['httpd']['log_level'] 52 | version node['httpd']['version'] 53 | run_user node['httpd']['run_user'] 54 | run_group node['httpd']['run_group'] 55 | timeout node['httpd']['timeout'] 56 | mpm node['httpd']['mpm'] 57 | startservers node['httpd']['startservers'] 58 | minspareservers node['httpd']['minspareservers'] 59 | maxspareservers node['httpd']['maxspareservers'] 60 | action [:create, :start] 61 | end 62 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/recipes/single.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | httpd_service node['httpd']['service_name'] do 4 | action [:create, :start] 5 | end 6 | -------------------------------------------------------------------------------- /test/cookbooks/httpd_service_test/templates/default/new-listener.erb: -------------------------------------------------------------------------------- 1 | Listen 0.0.0.0:<%= @port %> 2 | -------------------------------------------------------------------------------- /test/integration/config/debian_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'debian' || os[:family] == 'ubuntu' 2 | if os[:release].to_i == 7 3 | describe file('/etc/apache2-default/conf.d') do 4 | it { should be_directory } 5 | its('mode') { should eq 00755 } 6 | it { should be_owned_by 'root' } 7 | it { should be_grouped_into 'root' } 8 | end 9 | 10 | describe file('/etc/apache2-default/conf.d/hello.conf') do 11 | it { should be_file } 12 | it { should be_owned_by 'root' } 13 | it { should be_grouped_into 'root' } 14 | its('mode') { should eq 00644 } 15 | end 16 | 17 | describe file('/etc/apache2-foo/conf.d/hello_again.conf') do 18 | it { should be_file } 19 | it { should be_owned_by 'root' } 20 | it { should be_grouped_into 'root' } 21 | its('mode') { should eq 00644 } 22 | end 23 | else 24 | describe file('/etc/apache2-default/conf-available') do 25 | it { should be_directory } 26 | it { should be_owned_by 'root' } 27 | it { should be_grouped_into 'root' } 28 | its('mode') { should eq 00755 } 29 | end 30 | 31 | describe file('/etc/apache2-default/conf-enabled') do 32 | it { should be_directory } 33 | it { should be_owned_by 'root' } 34 | it { should be_grouped_into 'root' } 35 | its('mode') { should eq 00755 } 36 | end 37 | 38 | describe file('/etc/apache2-default/conf-available/hello.conf') do 39 | it { should be_file } 40 | its('mode') { should eq 00644 } 41 | it { should be_owned_by 'root' } 42 | it { should be_grouped_into 'root' } 43 | end 44 | 45 | describe file('/etc/apache2-default/conf-enabled/hello.conf') do 46 | it { should be_file } 47 | it { should be_owned_by 'root' } 48 | it { should be_grouped_into 'root' } 49 | it { should be_linked_to '/etc/apache2-default/conf-available/hello.conf' } 50 | end 51 | 52 | describe file('/etc/apache2-foo/conf-available') do 53 | it { should be_directory } 54 | it { should be_owned_by 'root' } 55 | it { should be_grouped_into 'root' } 56 | its('mode') { should eq 00755 } 57 | end 58 | 59 | describe file('/etc/apache2-foo/conf-enabled') do 60 | it { should be_directory } 61 | it { should be_owned_by 'root' } 62 | it { should be_grouped_into 'root' } 63 | its('mode') { should eq 00755 } 64 | end 65 | 66 | describe file('/etc/apache2-foo/conf-available/hello_again.conf') do 67 | it { should be_file } 68 | it { should be_owned_by 'root' } 69 | it { should be_grouped_into 'root' } 70 | its('mode') { should eq 00644 } 71 | end 72 | 73 | describe file('/etc/apache2-foo/conf-enabled/hello_again.conf') do 74 | it { should be_file } 75 | it { should be_owned_by 'root' } 76 | it { should be_grouped_into 'root' } 77 | it { should be_linked_to '/etc/apache2-foo/conf-available/hello_again.conf' } 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /test/integration/config/rhel_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'centos' || os[:family] == 'fedora' || os[:family] == 'opensuse' 2 | describe file('/etc/httpd-default/conf.d') do 3 | it { should be_directory } 4 | it { should be_owned_by 'root' } 5 | it { should be_grouped_into 'root' } 6 | its('mode') { should eq 00755 } 7 | end 8 | 9 | describe file('/etc/httpd-default/conf.d/hello.conf') do 10 | it { should be_file } 11 | it { should be_owned_by 'root' } 12 | it { should be_grouped_into 'root' } 13 | its('content') { should eq "# hello there\n" } 14 | its('mode') { should eq 00644 } 15 | end 16 | 17 | describe file('/etc/httpd-foo/conf.d') do 18 | it { should be_directory } 19 | it { should be_owned_by 'root' } 20 | it { should be_grouped_into 'root' } 21 | its('mode') { should eq 00755 } 22 | end 23 | 24 | describe file('/etc/httpd-foo/conf.d/hello_again.conf') do 25 | it { should be_file } 26 | it { should be_owned_by 'root' } 27 | it { should be_grouped_into 'root' } 28 | its('content') { should eq "# hello there\n" } 29 | its('mode') { should eq 00644 } 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/integration/hello_world_test/hello_spec.rb: -------------------------------------------------------------------------------- 1 | describe command("curl -L localhost | grep 'hello there'") do 2 | its(:exit_status) { should eq 0 } 3 | end 4 | -------------------------------------------------------------------------------- /test/integration/module22/debian_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'debian' || os[:family] == 'ubuntu' 2 | # auth_basic 3 | describe file('/usr/lib/apache2/modules/mod_auth_basic.so') do 4 | it { should be_file } 5 | its('mode') { should eq 00644 } 6 | it { should be_owned_by 'root' } 7 | it { should be_grouped_into 'root' } 8 | end 9 | 10 | describe file('/etc/apache2-default/mods-available') do 11 | it { should be_directory } 12 | its('mode') { should eq 00755 } 13 | it { should be_owned_by 'root' } 14 | it { should be_grouped_into 'root' } 15 | end 16 | 17 | describe file('/etc/apache2-default/mods-enabled') do 18 | it { should be_directory } 19 | its('mode') { should eq 00755 } 20 | it { should be_owned_by 'root' } 21 | it { should be_grouped_into 'root' } 22 | end 23 | 24 | describe file('/etc/apache2-default/mods-available/auth_basic.load') do 25 | it { should be_file } 26 | its('mode') { should eq 00644 } 27 | it { should be_owned_by 'root' } 28 | it { should be_grouped_into 'root' } 29 | end 30 | 31 | describe file('/etc/apache2-default/mods-enabled/auth_basic.load') do 32 | it { should be_file } 33 | it { should be_owned_by 'root' } 34 | it { should be_grouped_into 'root' } 35 | it { should be_linked_to '/etc/apache2-default/mods-available/auth_basic.load' } 36 | end 37 | 38 | # auth_kerb 39 | describe file('/usr/lib/apache2/modules/mod_expires.so') do 40 | it { should be_file } 41 | its('mode') { should eq 00644 } 42 | it { should be_owned_by 'root' } 43 | it { should be_grouped_into 'root' } 44 | end 45 | 46 | describe file('/etc/apache2-default/mods-available') do 47 | it { should be_directory } 48 | its('mode') { should eq 00755 } 49 | it { should be_owned_by 'root' } 50 | it { should be_grouped_into 'root' } 51 | end 52 | 53 | describe file('/etc/apache2-default/mods-enabled') do 54 | it { should be_directory } 55 | its('mode') { should eq 00755 } 56 | it { should be_owned_by 'root' } 57 | it { should be_grouped_into 'root' } 58 | end 59 | 60 | describe file('/etc/apache2-default/mods-available/expires.load') do 61 | it { should be_file } 62 | its('mode') { should eq 00644 } 63 | it { should be_owned_by 'root' } 64 | it { should be_grouped_into 'root' } 65 | end 66 | 67 | describe file('/etc/apache2-default/mods-enabled/expires.load') do 68 | it { should be_file } 69 | it { should be_owned_by 'root' } 70 | it { should be_grouped_into 'root' } 71 | it { should be_linked_to '/etc/apache2-default/mods-available/expires.load' } 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /test/integration/module22/rhel_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'centos' || os[:family] == 'fedora' 2 | # auth_basic 3 | describe file('/usr/lib64/httpd/modules/mod_auth_basic.so') do 4 | it { should be_file } 5 | its('mode') { should eq 00755 } 6 | it { should be_owned_by 'root' } 7 | it { should be_grouped_into 'root' } 8 | end 9 | 10 | describe file('/etc/httpd-default/conf.d') do 11 | it { should be_directory } 12 | its('mode') { should eq 00755 } 13 | it { should be_owned_by 'root' } 14 | it { should be_grouped_into 'root' } 15 | end 16 | 17 | describe file('/etc/httpd-default/conf.d/auth_basic.load') do 18 | it { should be_file } 19 | its('mode') { should eq 00644 } 20 | it { should be_owned_by 'root' } 21 | it { should be_grouped_into 'root' } 22 | end 23 | 24 | # auth_kerb 25 | describe file('/usr/lib64/httpd/modules/mod_expires.so') do 26 | it { should be_file } 27 | its('mode') { should eq 00755 } 28 | it { should be_owned_by 'root' } 29 | it { should be_grouped_into 'root' } 30 | end 31 | 32 | describe file('/etc/httpd-default/conf.d') do 33 | it { should be_directory } 34 | its('mode') { should eq 00755 } 35 | it { should be_owned_by 'root' } 36 | it { should be_grouped_into 'root' } 37 | end 38 | 39 | describe file('/etc/httpd-default/conf.d/expires.load') do 40 | it { should be_file } 41 | its('mode') { should eq 00644 } 42 | it { should be_owned_by 'root' } 43 | it { should be_grouped_into 'root' } 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /test/integration/module24/debian_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'debian' || os[:family] == 'ubuntu' 2 | # auth_basic 3 | describe file('/usr/lib/apache2/modules/mod_auth_basic.so') do 4 | it { should be_file } 5 | it { should be_owned_by 'root' } 6 | it { should be_grouped_into 'root' } 7 | its('mode') { should eq 00644 } 8 | end 9 | 10 | describe file('/etc/apache2-default/mods-available') do 11 | it { should be_directory } 12 | it { should be_owned_by 'root' } 13 | it { should be_grouped_into 'root' } 14 | its('mode') { should eq 00755 } 15 | end 16 | 17 | describe file('/etc/apache2-default/mods-enabled') do 18 | it { should be_directory } 19 | it { should be_owned_by 'root' } 20 | it { should be_grouped_into 'root' } 21 | its('mode') { should eq 00755 } 22 | end 23 | 24 | describe file('/etc/apache2-default/mods-available/auth_basic.load') do 25 | it { should be_file } 26 | it { should be_owned_by 'root' } 27 | it { should be_grouped_into 'root' } 28 | its('mode') { should eq 00644 } 29 | end 30 | 31 | describe file('/etc/apache2-default/mods-enabled/auth_basic.load') do 32 | it { should be_linked_to '/etc/apache2-default/mods-available/auth_basic.load' } 33 | it { should be_owned_by 'root' } 34 | it { should be_grouped_into 'root' } 35 | end 36 | 37 | describe file('/etc/apache2-default/mods-available/expires.load') do 38 | it { should be_file } 39 | it { should be_owned_by 'root' } 40 | it { should be_grouped_into 'root' } 41 | its('mode') { should eq 00644 } 42 | end 43 | 44 | describe file('/etc/apache2-default/mods-enabled/expires.load') do 45 | it { should be_linked_to '/etc/apache2-default/mods-available/expires.load' } 46 | it { should be_owned_by 'root' } 47 | it { should be_grouped_into 'root' } 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/integration/module24/rhel_spec.rb: -------------------------------------------------------------------------------- 1 | if os[:family] == 'centos' || os[:family] == 'fedora' || os[:family] == 'opensuse' 2 | 3 | describe file('/etc/httpd-default/conf.modules.d') do 4 | it { should be_directory } 5 | its('mode') { should eq 00755 } 6 | it { should be_owned_by 'root' } 7 | it { should be_grouped_into 'root' } 8 | end 9 | 10 | describe file('/etc/httpd-default/conf.modules.d/auth_basic.load') do 11 | it { should be_file } 12 | its('mode') { should eq 00644 } 13 | it { should be_owned_by 'root' } 14 | it { should be_grouped_into 'root' } 15 | end 16 | 17 | describe file('/etc/httpd-default/conf.modules.d') do 18 | it { should be_directory } 19 | its('mode') { should eq 00755 } 20 | it { should be_owned_by 'root' } 21 | it { should be_grouped_into 'root' } 22 | end 23 | 24 | describe file('/etc/httpd-default/conf.modules.d/expires.load') do 25 | it { should be_file } 26 | its('mode') { should eq 00644 } 27 | it { should be_owned_by 'root' } 28 | it { should be_grouped_into 'root' } 29 | end 30 | end 31 | 32 | if os[:family] == 'centos' || os[:family] == 'fedora' 33 | # auth_basic 34 | describe file('/usr/lib64/httpd/modules/mod_auth_basic.so') do 35 | it { should be_file } 36 | its('mode') { should eq 00755 } 37 | it { should be_owned_by 'root' } 38 | it { should be_grouped_into 'root' } 39 | end 40 | 41 | # auth_kerb 42 | describe file('/usr/lib64/httpd/modules/mod_expires.so') do 43 | it { should be_file } 44 | its('mode') { should eq 00755 } 45 | it { should be_owned_by 'root' } 46 | it { should be_grouped_into 'root' } 47 | end 48 | elsif os[:family] == 'opensuse' 49 | # auth_basic 50 | describe file('/usr/lib64/apache2/mod_auth_basic.so') do 51 | it { should be_file } 52 | its('mode') { should eq 00755 } 53 | it { should be_owned_by 'root' } 54 | it { should be_grouped_into 'root' } 55 | end 56 | 57 | # auth_kerb 58 | describe file('/usr/lib64/apache2/mod_expires.so') do 59 | it { should be_file } 60 | its('mode') { should eq 00755 } 61 | it { should be_owned_by 'root' } 62 | it { should be_grouped_into 'root' } 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /test/integration/service22-actions/actions_spec.rb: -------------------------------------------------------------------------------- 1 | case os[:family] 2 | when 'redhat' 3 | service_prefix = 'httpd' 4 | apache_conf = 'conf/httpd.conf' 5 | when 'debian' 6 | service_prefix = 'apache2' 7 | apache_conf = 'apache2.conf' 8 | end 9 | 10 | service_create = "#{service_prefix}-create_test" 11 | service_delete = "#{service_prefix}-delete_test" 12 | service_start = "#{service_prefix}-start_test" 13 | service_stop = "#{service_prefix}-stop_test" 14 | service_restart = "#{service_prefix}-restart_test" 15 | service_reload = "#{service_prefix}-reload_test" 16 | 17 | describe file("/etc/#{service_create}/#{apache_conf}") do 18 | it { is_expected.to exist } 19 | end 20 | 21 | describe service(service_create) do 22 | it { is_expected.to be_installed } 23 | it { is_expected.to_not be_running } 24 | end 25 | 26 | describe port(8101) do 27 | it { is_expected.to_not be_listening } 28 | end 29 | 30 | describe directory("/etc/#{service_delete}/") do 31 | it { is_expected.to_not exist } 32 | end 33 | 34 | describe service(service_delete) do 35 | it { is_expected.to_not be_installed } 36 | it { is_expected.to_not be_running } 37 | end 38 | 39 | describe port(8102) do 40 | it { is_expected.to_not be_listening } 41 | end 42 | 43 | describe file("/etc/#{service_start}/#{apache_conf}") do 44 | it { is_expected.to exist } 45 | end 46 | 47 | describe service(service_start) do 48 | it { is_expected.to be_installed } 49 | it { is_expected.to be_running } 50 | end 51 | 52 | describe port(8103) do 53 | it { is_expected.to be_listening } 54 | end 55 | 56 | describe file("/etc/#{service_stop}/#{apache_conf}") do 57 | it { is_expected.to exist } 58 | end 59 | 60 | describe service(service_stop) do 61 | it { is_expected.to be_installed } 62 | it { is_expected.to_not be_running } 63 | end 64 | 65 | describe port(8104) do 66 | it { is_expected.to_not be_listening } 67 | end 68 | 69 | describe file("/etc/#{service_restart}/#{apache_conf}") do 70 | it { is_expected.to exist } 71 | end 72 | 73 | describe service(service_restart) do 74 | it { is_expected.to be_installed } 75 | it { is_expected.to be_running } 76 | end 77 | 78 | describe port(8105) do 79 | it { is_expected.to be_listening } 80 | end 81 | 82 | describe port(8106) do 83 | it { is_expected.to be_listening } 84 | end 85 | 86 | describe file('/restart-pre-action-pids') do 87 | it { is_expected.to exist } 88 | example { expect(subject.content.to_i).to be > 0 } 89 | end 90 | 91 | describe file('/restart-post-action-pids') do 92 | it { is_expected.to exist } 93 | example { expect(subject.content.to_i).to be > 0 } 94 | example do 95 | expect(subject.content.strip) 96 | .to_not eq(file('/restart-pre-action-pids').content.strip) 97 | end 98 | end 99 | 100 | describe file("/etc/#{service_reload}/#{apache_conf}") do 101 | it { is_expected.to exist } 102 | end 103 | 104 | describe service(service_reload) do 105 | it { is_expected.to be_installed } 106 | it { is_expected.to be_running } 107 | end 108 | 109 | describe port(8107) do 110 | it { is_expected.to be_listening } 111 | end 112 | 113 | describe port(8108) do 114 | it { is_expected.to be_listening } 115 | end 116 | 117 | describe file('/reload-pre-action-pids') do 118 | it { is_expected.to exist } 119 | example { expect(subject.content.to_i).to be > 0 } 120 | end 121 | 122 | describe file('/reload-post-action-pids') do 123 | it { is_expected.to exist } 124 | example { expect(subject.content.to_i).to be > 0 } 125 | example do 126 | expect(subject.content.strip) 127 | .to eq(file('/reload-pre-action-pids').content.strip) 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /test/integration/service22-multi/assert_functioning_spec.rb: -------------------------------------------------------------------------------- 1 | describe port(80) do 2 | it { should_not be_listening } 3 | end 4 | 5 | describe port(443) do 6 | it { should_not be_listening } 7 | end 8 | 9 | describe port(81) do 10 | it { should be_listening } 11 | its('protocols') { should include 'tcp' } 12 | end 13 | 14 | describe port(8080) do 15 | it { should be_listening } 16 | its('protocols') { should include 'tcp' } 17 | end 18 | 19 | describe port(444) do 20 | it { should be_listening } 21 | its('protocols') { should include 'tcp' } 22 | end 23 | 24 | describe port(4343) do 25 | it { should be_listening } 26 | its('protocols') { should include 'tcp' } 27 | end 28 | -------------------------------------------------------------------------------- /test/integration/service22-single/assert_functioning_spec.rb: -------------------------------------------------------------------------------- 1 | describe port(80) do 2 | it { should be_listening } 3 | its('protocols') { should include 'tcp' } 4 | end 5 | -------------------------------------------------------------------------------- /test/integration/service24-actions/actions_spec.rb: -------------------------------------------------------------------------------- 1 | case os[:family] 2 | when 'redhat', 'fedora', 'suse' 3 | service_prefix = 'httpd' 4 | apache_conf = 'conf/httpd.conf' 5 | when 'debian' 6 | service_prefix = 'apache2' 7 | apache_conf = 'apache2.conf' 8 | end 9 | 10 | service_create = "#{service_prefix}-create_test" 11 | service_delete = "#{service_prefix}-delete_test" 12 | service_start = "#{service_prefix}-start_test" 13 | service_stop = "#{service_prefix}-stop_test" 14 | service_restart = "#{service_prefix}-restart_test" 15 | service_reload = "#{service_prefix}-reload_test" 16 | 17 | describe file("/etc/#{service_create}/#{apache_conf}") do 18 | it { is_expected.to exist } 19 | end 20 | 21 | describe service(service_create) do 22 | it { is_expected.to be_installed } 23 | it { is_expected.to_not be_running } 24 | end 25 | 26 | describe port(8101) do 27 | it { is_expected.to_not be_listening } 28 | end 29 | 30 | describe directory("/etc/#{service_delete}/") do 31 | it { is_expected.to_not exist } 32 | end 33 | 34 | describe service(service_delete) do 35 | it { is_expected.to_not be_installed } 36 | it { is_expected.to_not be_running } 37 | end 38 | 39 | describe port(8102) do 40 | it { is_expected.to_not be_listening } 41 | end 42 | 43 | describe file("/etc/#{service_start}/#{apache_conf}") do 44 | it { is_expected.to exist } 45 | end 46 | 47 | describe service(service_start) do 48 | it { is_expected.to be_installed } 49 | it { is_expected.to be_running } 50 | end 51 | 52 | describe port(8103) do 53 | it { is_expected.to be_listening } 54 | end 55 | 56 | describe file("/etc/#{service_stop}/#{apache_conf}") do 57 | it { is_expected.to exist } 58 | end 59 | 60 | describe service(service_stop) do 61 | it { is_expected.to be_installed } 62 | it { is_expected.to_not be_running } 63 | end 64 | 65 | describe port(8104) do 66 | it { is_expected.to_not be_listening } 67 | end 68 | 69 | describe file("/etc/#{service_restart}/#{apache_conf}") do 70 | it { is_expected.to exist } 71 | end 72 | 73 | describe service(service_restart) do 74 | it { is_expected.to be_installed } 75 | it { is_expected.to be_running } 76 | end 77 | 78 | describe port(8105) do 79 | it { is_expected.to be_listening } 80 | end 81 | 82 | describe port(8106) do 83 | it { is_expected.to be_listening } 84 | end 85 | 86 | describe file('/restart-pre-action-pids') do 87 | it { is_expected.to exist } 88 | example { expect(subject.content.to_i).to be > 0 } 89 | end 90 | 91 | describe file('/restart-post-action-pids') do 92 | it { is_expected.to exist } 93 | example { expect(subject.content.to_i).to be > 0 } 94 | example do 95 | expect(subject.content.strip) 96 | .to_not eq(file('/restart-pre-action-pids').content.strip) 97 | end 98 | end 99 | 100 | describe file("/etc/#{service_reload}/#{apache_conf}") do 101 | it { is_expected.to exist } 102 | end 103 | 104 | describe service(service_reload) do 105 | it { is_expected.to be_installed } 106 | it { is_expected.to be_running } 107 | end 108 | 109 | describe port(8107) do 110 | it { is_expected.to be_listening } 111 | end 112 | 113 | describe port(8108) do 114 | it { is_expected.to be_listening } 115 | end 116 | 117 | describe file('/reload-pre-action-pids') do 118 | it { is_expected.to exist } 119 | example { expect(subject.content.to_i).to be > 0 } 120 | end 121 | 122 | describe file('/reload-post-action-pids') do 123 | it { is_expected.to exist } 124 | example { expect(subject.content.to_i).to be > 0 } 125 | example do 126 | expect(subject.content.strip) 127 | .to eq(file('/reload-pre-action-pids').content.strip) 128 | end 129 | end 130 | -------------------------------------------------------------------------------- /test/integration/service24-multi/assert_functioning_spec.rb: -------------------------------------------------------------------------------- 1 | describe port(80) do 2 | it { should_not be_listening } 3 | end 4 | 5 | describe port(443) do 6 | it { should_not be_listening } 7 | end 8 | 9 | describe port(81) do 10 | it { should be_listening } 11 | its('protocols') { should include 'tcp' } 12 | end 13 | 14 | describe port(8080) do 15 | it { should be_listening } 16 | its('protocols') { should include 'tcp' } 17 | end 18 | 19 | describe port(444) do 20 | it { should be_listening } 21 | its('protocols') { should include 'tcp' } 22 | end 23 | 24 | describe port(4343) do 25 | it { should be_listening } 26 | its('protocols') { should include 'tcp' } 27 | end 28 | -------------------------------------------------------------------------------- /test/integration/service24-single/assert_functioning_spec.rb: -------------------------------------------------------------------------------- 1 | describe port(80) do 2 | it { should be_listening } 3 | its('protocols') { should include 'tcp' } 4 | end 5 | --------------------------------------------------------------------------------