Switch back to the upstream nginx cookbook

chef_nginx is deprecated
This commit is contained in:
Greg Karékinian
2019-03-14 10:35:11 +01:00
parent e20ad9e6f9
commit fc265014de
122 changed files with 565 additions and 617 deletions

View File

@@ -0,0 +1,97 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=<%= node['nginx']['binary'] %>
NAME=nginx
DESC=nginx
PID=<%= @pid_file %>
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
. /etc/default/nginx
fi
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
return 0
else
$DAEMON -t $DAEMON_OPTS
return $?
fi
}
case "$1" in
start)
echo -n "Starting $DESC: "
test_nginx_config
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
start-stop-daemon --start --quiet --pidfile $PID \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile $PID \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
$PID --exec $DAEMON || true
sleep 1
test_nginx_config
start-stop-daemon --start --quiet --pidfile \
$PID --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID \
--exec $DAEMON || true
echo "$NAME."
;;
configtest|testconfig)
echo -n "Testing $DESC configuration: "
if test_nginx_config; then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p $PID "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0

View File

@@ -0,0 +1,11 @@
server {
listen <%= node['nginx']['port'] -%>;
server_name <%= node['hostname'] %>;
access_log <%= node['nginx']['log_dir'] %>/localhost.access.log;
location / {
root <%= node['nginx']['default_root'] %>;
index index.html index.htm;
}
}

View File

@@ -0,0 +1,6 @@
geo $<%= node['nginx']['remote_ip_var'] %> $authorized_ip {
default no;
<% node['nginx']['authorized_ips'].each do |ip| %>
<%= "#{ip} yes;" %>
<% end %>
}

View File

@@ -0,0 +1,4 @@
geoip_country <%= @country_dat %>;
<% if @city_dat -%>
geoip_city <%= @city_dat %>;
<% end -%>

View File

@@ -0,0 +1 @@
gzip_static <%= node['nginx']['gzip_static'] %>;

View File

@@ -0,0 +1,5 @@
<% node['nginx']['realip']['addresses'].each do |address| -%>
set_real_ip_from <%= address %>;
<% end -%>
real_ip_header <%= node['nginx']['realip']['header'] %>;
real_ip_recursive <%= node['nginx']['realip']['real_ip_recursive'] %>;

View File

@@ -0,0 +1,18 @@
include authorized_ip;
server {
listen <%= node['nginx']['status']['port'] %>;
server_name _;
location /nginx_status {
if ($authorized_ip = no) {
return 404;
}
stub_status on;
access_log off;
}
location / {
return 404;
}
}

View File

@@ -0,0 +1,17 @@
passenger_root <%= node['nginx']['passenger']['root'] %>;
passenger_ruby <%= node['nginx']['passenger']['ruby'] %>;
passenger_max_pool_size <%= node['nginx']['passenger']['max_pool_size'] %>;
passenger_spawn_method <%= node['nginx']['passenger']['spawn_method'] %>;
passenger_buffer_response <%= node['nginx']['passenger']['buffer_response'] %>;
passenger_min_instances <%= node['nginx']['passenger']['min_instances'] %>;
passenger_max_instances_per_app <%= node['nginx']['passenger']['max_instances_per_app'] %>;
passenger_pool_idle_time <%= node['nginx']['passenger']['pool_idle_time'] %>;
passenger_max_requests <%= node['nginx']['passenger']['max_requests'] %>;
passenger_show_version_in_header <%= node['nginx']['passenger']['show_version_in_header'] %>;
<%- if node['nginx']['passenger']['passenger_log_file'] %>
passenger_log_file <%= node['nginx']['passenger']['passenger_log_file'] %>;
<% end %>
<%- if node['nginx']['passenger']['nodejs'] %>
passenger_nodejs <%= node['nginx']['passenger']['nodejs'] %>;
<% end %>

View File

@@ -0,0 +1,89 @@
server {
set $app_home <%= node['nginx']['socketproxy']['root'] %>;
<% if node['nginx']['sts_max_age'] -%>
add_header Strict-Transport-Security "max-age=<%= node['nginx']['sts_max_age'] %>";
<% end -%>
listen <%= node['nginx']['port'] %> default;
access_log <%= node['nginx']['log_dir'] %>/<%= node['nginx']['socketproxy']['logname'] %>.access.log<% if node['nginx']['access_log_options'] %> <%= node['nginx']['access_log_options'] %><% end %>;
error_log <%= node['nginx']['log_dir'] %>/<%= node['nginx']['socketproxy']['logname'] %>.error.log <%= node['nginx']['socketproxy']['log_level'] %>;
<% if node['nginx']['server_name'] -%>
server_name ~^<%= node['nginx']['server_name'] %>\..*$;
<% end -%>
client_max_body_size 4G;
keepalive_timeout 5;
root $app_home/<%= node['nginx']['socketproxy']['default_app'] %>/<%= node['nginx']['socketproxy']['apps'][node['nginx']['socketproxy']['default_app']]['subdir'] %>/public;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS|PATCH)$ ) {
return 405;
}
<% node['nginx']['socketproxy']['apps'].each do |app, app_conf|
if app_conf['context_name']
base_loc = "/#{app_conf['context_name'].gsub(/^\/+/,'').gsub(/\/+$/,'')}"
else
base_loc = ""
end
-%>
location ~ "^<%= base_loc %>/assets/(.*/)*.*-[0-9a-f]{32}.*" {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location ^~ /<%= app_conf['context_name'] %> {
alias $app_home/<%= app %>/<%= app_conf['subdir'] %>/public/;
try_files $uri/index.html $uri.html $uri @app_<%= app %>;
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
error_page 403 /403.html;
}
location @app_<%= app %> {
proxy_read_timeout 600;
<%
if app_conf['socket']['type']
case app_conf['socket']['type']
when 'unix'
-%>
proxy_pass http://unix:$app_home/<%= app %>/<%= app_conf['socket']['path'] %><% if app_conf['prepend_slash'] %>:/<% end %>;
<%
when 'tcp'
-%>
proxy_pass http://localhost:<%= app_conf['socket']['port'] -%>;
<%
end
else
-%>
proxy_pass http://unix:$app_home/<%= app %>/<%= app_conf['socket_path'] %><% if app_conf['prepend_slash'] %>:/<% end %>;
<%
end
-%>
}
<% end # node['nginx']['socketproxy']['apps'].each -%>
error_page 500 502 504 /50x.html;
location = /50x.html {
root html;
}
}

View File

@@ -0,0 +1,4 @@
upload_progress <%= node['nginx']['upload_progress']['zone_name'] -%> <%= node['nginx']['upload_progress']['zone_size'] -%>;
<% if node['nginx']['upload_progress']['javascript_output'] -%>
upload_progress_java_output;
<% end -%>

View File

@@ -0,0 +1,39 @@
# nginx
description "nginx http daemon"
start on (local-filesystems and net-device-up IFACE=lo and runlevel [<%= node['nginx']['upstart']['runlevels'] %>])
stop on runlevel [!<%= node['nginx']['upstart']['runlevels'] %>]
env DAEMON=<%= node['nginx']['binary'] %>
env PID=<%= @pid_file %>
env CONFIG=<%= node['nginx']['source']['conf_path'] %>
respawn
<% if node['nginx']['upstart']['respawn_limit'] -%>
respawn limit <%= node['nginx']['upstart']['respawn_limit'] %>
<% end -%>
pre-start script
${DAEMON} -t
if [ $? -ne 0 ]; then
exit $?
fi
end script
<% unless node['nginx']['upstart']['foreground'] -%>
expect fork
<% else -%>
console output
<% end -%>
exec ${DAEMON} -c "${CONFIG}"
<% if node.recipe?('nginx::passenger') && !node['nginx']['upstart']['foreground'] -%>
# classic example of why pidfiles should have gone away
# with the advent of fork(). we missed that bus a long
# time ago so hack around it.
post-stop script
start-stop-daemon --stop --pidfile ${PID} --name nginx --exec ${DAEMON} --signal QUIT
end script
<% end -%>

View File

@@ -0,0 +1,129 @@
user <%= node['nginx']['user'] %><% if node['nginx']['user'] != node['nginx']['group'] %> <%= node['nginx']['group'] %><% end %>;
worker_processes <%= node['nginx']['worker_processes'] %>;
<% if node['nginx']['daemon_disable'] -%>
daemon off;
<% end -%>
<% if node['nginx']['worker_rlimit_nofile'] -%>
worker_rlimit_nofile <%= node['nginx']['worker_rlimit_nofile'] %>;
<% end -%>
<% if node['nginx']['worker_shutdown_timeout'] -%>
worker_shutdown_timeout <%= node['nginx']['worker_shutdown_timeout'] %>;
<% end -%>
<% node['nginx']['load_modules'].each do |module_to_load| %>
load_module <%= module_to_load %>;
<% end -%>
<% if node['platform'] == 'ubuntu' && node['platform_version'].to_i >= 18 %>
include /etc/nginx/modules-enabled/*.conf;
<% end -%>
error_log <%= node['nginx']['log_dir'] %>/error.log<% if node['nginx']['error_log_options'] %> <%= node['nginx']['error_log_options'] %><% end %>;
pid <%= @pid_file %>;
events {
worker_connections <%= node['nginx']['worker_connections'] %>;
<% if node['nginx']['multi_accept'] -%>
multi_accept on;
<% end -%>
<% if node['nginx']['event'] -%>
use <%= node['nginx']['event'] %>;
<% end -%>
<% if node['nginx']['accept_mutex_delay'] -%>
accept_mutex_delay <%= node['nginx']['accept_mutex_delay'] %>ms;
<% end -%>
}
http {
<% if node.recipe?('nginx::naxsi_module') %>
include <%= node['nginx']['dir'] %>/naxsi_core.rules;
<% end %>
include <%= node['nginx']['dir'] %>/mime.types;
default_type application/octet-stream;
charset_types text/css text/plain text/vnd.wap.wml application/javascript application/json application/rss+xml application/xml;
<% node['nginx']['log_formats'].each do |name, format| %>
log_format <%= name %> <%= format %>;
<% end -%>
<% if node['nginx']['disable_access_log'] -%>
access_log off;
<% else -%>
access_log <%= node['nginx']['log_dir'] %>/access.log<% if node['nginx']['access_log_options'] %> <%= node['nginx']['access_log_options'] %><% end %>;
<% end %>
<% if node['nginx']['server_tokens'] -%>
server_tokens <%= node['nginx']['server_tokens'] %>;
<% end -%>
sendfile <%= node['nginx']['sendfile'] %>;
tcp_nopush <%= node['nginx']['tcp_nopush'] %>;
tcp_nodelay <%= node['nginx']['tcp_nodelay'] %>;
<% if node['nginx']['keepalive'] == 'on' %>
keepalive_requests <%= node['nginx']['keepalive_requests'] %>;
keepalive_timeout <%= node['nginx']['keepalive_timeout'] %>;
<% end %>
<% unless node['nginx']['underscores_in_headers'].nil? %>
underscores_in_headers <%= node['nginx']['underscores_in_headers'] %>;
<% end %>
gzip <%= node['nginx']['gzip'] %>;
<% if node['nginx']['gzip'] == 'on' %>
gzip_http_version <%= node['nginx']['gzip_http_version'] %>;
gzip_comp_level <%= node['nginx']['gzip_comp_level'] %>;
gzip_proxied <%= node['nginx']['gzip_proxied'] %>;
gzip_vary <%= node['nginx']['gzip_vary'] %>;
<% if node['nginx']['gzip_buffers'] -%>
gzip_buffers <%= node['nginx']['gzip_buffers'] %>;
<% end -%>
gzip_types <%= node['nginx']['gzip_types'].join(' ') %>;
gzip_min_length <%= node['nginx']['gzip_min_length'] %>;
gzip_disable "<%= node['nginx']['gzip_disable'] %>";
<% end %>
variables_hash_max_size <%= node['nginx']['variables_hash_max_size'] %>;
variables_hash_bucket_size <%= node['nginx']['variables_hash_bucket_size'] %>;
server_names_hash_bucket_size <%= node['nginx']['server_names_hash_bucket_size'] %>;
types_hash_max_size <%= node['nginx']['types_hash_max_size'] %>;
types_hash_bucket_size <%= node['nginx']['types_hash_bucket_size'] %>;
<% if node['nginx']['proxy_read_timeout'] -%>
proxy_read_timeout <%= node['nginx']['proxy_read_timeout'] %>;
<% end -%>
<% if node['nginx']['client_body_buffer_size'] -%>
client_body_buffer_size <%= node['nginx']['client_body_buffer_size'] %>;
<% end -%>
<% if node['nginx']['client_max_body_size'] -%>
client_max_body_size <%= node['nginx']['client_max_body_size'] %>;
<% end -%>
<% if node['nginx']['large_client_header_buffers'] -%>
large_client_header_buffers <%= node['nginx']['large_client_header_buffers'] %>;
<% end -%>
<% if node['nginx']['map_hash_max_size'] -%>
map_hash_max_size <%= node['nginx']['map_hash_max_size'] %>;
<% end -%>
<% if node['nginx']['proxy_buffer_size'] -%>
proxy_buffer_size <%= node['nginx']['proxy_buffer_size'] %>;
<% end -%>
<% if node['nginx']['proxy_buffers'] -%>
proxy_buffers <%= node['nginx']['proxy_buffers'] %>;
<% end -%>
<% if node['nginx']['proxy_busy_buffers_size'] -%>
proxy_busy_buffers_size <%= node['nginx']['proxy_busy_buffers_size'] %>;
<% end -%>
<% if node['nginx']['enable_rate_limiting'] -%>
limit_req_zone $binary_remote_addr zone=<%= node['nginx']['rate_limiting_zone_name'] %>:<%= node['nginx']['rate_limiting_backoff'] %> rate=<%= node['nginx']['rate_limit'] %>;
<% end -%>
<% node['nginx']['extra_configs'].each do |key, value| -%>
<%= key %> <%= value %>;
<% end -%>
include <%= node['nginx']['dir'] %>/conf.d/*.conf;
include <%= node['nginx']['dir'] %>/sites-enabled/*;
}
<% if node['nginx']['install_method'] == 'source' and node['nginx']['configure_flags'].include? '--with-stream' %>
stream{
include <%= node['nginx']['dir'] %>/streams-enabled/*;
}
<% end %>

View File

@@ -0,0 +1,111 @@
#!/bin/sh
#
# nginx
#
# chkconfig: - 57 47
# description: nginx
# processname: nginx
# config: /etc/sysconfig/nginx
#
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit
exec=<%= node['nginx']['binary'] %>
prog=$(basename $exec)
# default options, overruled by items in sysconfig
NGINX_GLOBAL=""
[ -e /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
options=""
if [ "${NGINX_GLOBAL}" != "" ]; then
options="-g ${NGINX_GLOBAL}"
fi
$exec $options
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
$exec -s stop
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
$exec -s reload
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
configtest() {
if [ "$#" -ne 0 ] ; then
case "$1" in
-q)
FLAG=$1
;;
*)
;;
esac
shift
fi
${exec} -t $FLAG
RETVAL=$?
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status nginx
;;
restart)
restart
;;
reload|force-reload)
reload
;;
condrestart)
[ -f $lockfile ] && restart || :
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|configtest}"
exit 1
esac
exit $?

View File

@@ -0,0 +1,13 @@
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
ExecStartPre=<%= node['nginx']['binary'] %> -t
ExecStart=<%= node['nginx']['binary'] %>
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,2 @@
NGINX_GLOBAL=<%= node['nginx']['global'] %>
ULIMIT="-n <%= node['nginx']['ulimit'] %>"

View File

@@ -0,0 +1,29 @@
#!/bin/sh -e
SYSCONFDIR='<%= node['nginx']['dir'] %>'
if [ -z $1 ]; then
echo "Which site would you like to disable?"
echo -n "Your choices are: "
ls $SYSCONFDIR/sites-enabled/* | \
sed -e "s,$SYSCONFDIR/sites-enabled/,,g" | xargs echo
echo -n "Site name? "
read SITENAME
else
SITENAME=$1
fi
if [ $SITENAME = "default" ]; then
PRIORITY="000"
fi
if ! [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
-e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
echo "This site is already disabled, or does not exist!"
exit 1
fi
if ! rm $SYSCONFDIR/sites-enabled/$SITENAME 2>/dev/null; then
rm -f $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
fi
echo "Site $SITENAME disabled; reload nginx to disable."

View File

@@ -0,0 +1,29 @@
#!/bin/sh -e
SYSCONFDIR='<%= node['nginx']['dir'] %>'
if [ -z $1 ]; then
echo "Which stream would you like to disable?"
echo -n "Your choices are: "
ls $SYSCONFDIR/streams-enabled/* | \
sed -e "s,$SYSCONFDIR/streams-enabled/,,g" | xargs echo
echo -n "Stream name? "
read STREAMNAME
else
STREAMNAME=$1
fi
if [ $STREAMNAME = "default" ]; then
PRIORITY="000"
fi
if ! [ -e $SYSCONFDIR/streams-enabled/$STREAMNAME -o \
-e $SYSCONFDIR/streams-enabled/"$PRIORITY"-"$STREAMNAME" ]; then
echo "This Stream is already disabled, or does not exist!"
exit 1
fi
if ! rm $SYSCONFDIR/streams-enabled/$STREAMNAME 2>/dev/null; then
rm -f $SYSCONFDIR/streams-enabled/"$PRIORITY"-"$STREAMNAME"
fi
echo "Stream $STREAMNAME disabled; reload nginx to disable."

View File

@@ -0,0 +1,38 @@
#!/bin/sh -e
SYSCONFDIR='<%= node['nginx']['dir'] %>'
if [ -z $1 ]; then
echo "Which site would you like to enable?"
echo -n "Your choices are: "
ls $SYSCONFDIR/sites-available/* | \
sed -e "s,$SYSCONFDIR/sites-available/,,g" | xargs echo
echo -n "Site name? "
read SITENAME
else
SITENAME=$1
fi
if [ $SITENAME = "default" ]; then
PRIORITY="000"
fi
if [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
-e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
echo "This site is already enabled!"
exit 0
fi
if ! [ -e $SYSCONFDIR/sites-available/$SITENAME ]; then
echo "This site does not exist!"
exit 1
fi
if [ $SITENAME = "default" ]; then
ln -sf $SYSCONFDIR/sites-available/$SITENAME \
$SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
else
ln -sf $SYSCONFDIR/sites-available/$SITENAME $SYSCONFDIR/sites-enabled/$SITENAME
fi
echo "Site $SITENAME installed; reload nginx to enable."

View File

@@ -0,0 +1,38 @@
#!/bin/sh -e
SYSCONFDIR='<%= node['nginx']['dir'] %>'
if [ -z $1 ]; then
echo "Which stream would you like to enable?"
echo -n "Your choices are: "
ls $SYSCONFDIR/streams-available/* | \
sed -e "s,$SYSCONFDIR/streams-available/,,g" | xargs echo
echo -n "Stream name? "
read STREAMNAME
else
STREAMNAME=$1
fi
if [ $STREAMNAME = "default" ]; then
PRIORITY="000"
fi
if [ -e $SYSCONFDIR/streams-enabled/$STREAMNAME -o \
-e $SYSCONFDIR/streams-enabled/"$PRIORITY"-"$STREAMNAME" ]; then
echo "This stream is already enabled!"
exit 0
fi
if ! [ -e $SYSCONFDIR/streams-available/$STREAMNAME ]; then
echo "This stream does not exist!"
exit 1
fi
if [ $STREAMNAME = "default" ]; then
ln -sf $SYSCONFDIR/streams-available/$STREAMNAME \
$SYSCONFDIR/streams-enabled/"$PRIORITY"-"$STREAMNAME"
else
ln -sf $SYSCONFDIR/streams-available/$STREAMNAME $SYSCONFDIR/streams-enabled/$STREAMNAME
fi
echo "Stream $STREAMNAME installed; reload nginx to enable."

View File

@@ -0,0 +1,82 @@
#
# Author:: Jamie Winsor (<jamie@vialstudios.com>)
#
# Copyright 2012, Riot Games
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Ohai.plugin(:Nginx) do
provides "nginx"
provides "nginx/version"
provides "nginx/configure_arguments"
provides "nginx/prefix"
provides "nginx/conf_path"
def parse_flags(flags)
prefix = nil
conf_path = nil
flags.each do |flag|
case flag
when /^--prefix=(.+)$/
prefix = Regexp.last_match(1)
when /^--conf-path=(.+)$/
conf_path = Regexp.last_match(1)
end
end
[prefix, conf_path]
end
collect_data do
nginx Mash.new unless nginx
# if we fail we should still have these values to avoid nil class errors
# if people try to use them
nginx[:version] = nil unless nginx[:version]
nginx[:configure_arguments] = [] unless nginx[:configure_arguments]
nginx[:prefix] = nil unless nginx[:prefix]
nginx[:conf_path] = nil unless nginx[:conf_path]
begin
so = shell_out("<%= @binary %> -V")
# Sample output:
# nginx version: nginx/1.10.1
# built by clang 7.3.0 (clang-703.0.31)
# built with OpenSSL 1.0.2h 3 May 2016
# TLS SNI support enabled
# configure arguments: --prefix=/usr/local/Cellar/nginx/1.10.1 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.10.1/bin/nginx --with-cc-opt='-I/usr/local/Cellar/pcre/8.38/include -I/usr/local/Cellar/openssl/1.0.2h_1/include' --with-ld-opt='-L/usr/local/Cellar/pcre/8.38/lib -L/usr/local/Cellar/openssl/1.0.2h_1/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module
if so.exitstatus == 0
so.stderr.split("\n").each do |line|
case line
when /^configure arguments:(.+)/
# This could be better: I'm splitting on configure arguments which removes them and also
# adds a blank string at index 0 of the array. This is why we drop index 0 and map to
# add the '--' prefix back to the configure argument.
nginx[:configure_arguments] = Regexp.last_match(1).split(/\s--(?!param)/).drop(1).map { |ca| "--#{ca}" }
prefix, conf_path = parse_flags(nginx[:configure_arguments])
nginx[:prefix] = prefix
nginx[:conf_path] = conf_path
when /^nginx version: nginx\/(\d+\.\d+\.\d+)/
nginx[:version] = Regexp.last_match(1)
end
end
end
rescue
Ohai::Log.debug('Nginx plugin: Could not shell_out "<%= @binary %> -V"')
end
end
end

View File

@@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd -tt ./main

View File

@@ -0,0 +1,4 @@
#!/bin/sh
ulimit -n <%= node['nginx']['ulimit'] %>
exec 2>&1
exec <%= node['nginx']['src_binary'] %> -c <%= node['nginx']['dir'] %>/nginx.conf

View File

@@ -0,0 +1,97 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=<%= node['nginx']['binary'] %>
NAME=nginx
DESC=nginx
PID=<%= @pid_file %>
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
. /etc/default/nginx
fi
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
return 0
else
$DAEMON -t $DAEMON_OPTS
return $?
fi
}
case "$1" in
start)
echo -n "Starting $DESC: "
test_nginx_config
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
start-stop-daemon --start --quiet --pidfile $PID \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile $PID \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
$PID --exec $DAEMON || true
sleep 1
test_nginx_config
start-stop-daemon --start --quiet --pidfile \
$PID --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile $PID \
--exec $DAEMON || true
echo "$NAME."
;;
configtest|testconfig)
echo -n "Testing $DESC configuration: "
if test_nginx_config; then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p $PID "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0