Skip to content

Commit

Permalink
Merge pull request #75 from dnsimple/create_pid_dir_on_init
Browse files Browse the repository at this point in the history
Create PID directory on init start commands
  • Loading branch information
therobot committed Jun 23, 2017
2 parents b3a387a + 79f3792 commit b62e019
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 3 additions & 4 deletions resources/pdns_recursor_service_sysvinit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@


action :enable do
# To make sure the default package doesn't start any "pdns_recursor" daemon
# because the default service could stop all other instances
# Some sysvint systems start the default pdns-recursor after installations
# We make sure to disable it which also stops the service in some platforms
service 'pdns-recursor' do
supports restart: true, status: true
action [:disable, :stop]
only_if { ::File.exist?('/var/run/pdns_recursor.pid') }
action :disable
end

service_name = sysvinit_name(new_resource.instance_name)
Expand Down
8 changes: 8 additions & 0 deletions templates/default/recursor.init.debian.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ if [ -r /etc/default/pdns-recursor ]; then
. /etc/default/pdns-recursor
fi

create_socket_dir() {
if [ ! -d $PIDDIR ]; then
mkdir -p $PIDDIR
chmod 0755 $PIDDIR
fi
}

start() {
# Return
# 0 if daemon has been started / was already running
# >0 if daemon could not be started
create_socket_dir
start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 0
start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON -- --daemon=yes --config-name=${INSTANCE_NAME} --config-dir=${CONFIG_DIR} || return 2
}
Expand Down
25 changes: 21 additions & 4 deletions templates/default/recursor.init.rhel.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,42 @@
#
# description: PowerDNS Recursor is a non authoritative/recursing DNS server
# processname: <%= @service_name %>
# config: <%= ::File.join(@config_dir, "#{@service_name}.conf") %>
# pidfile: <%= ::File.join('/', 'var', 'run', @pdns_virtual_instance, "#{@service_name}.pid") %>
# config: <%= ::File.join(@config_dir, "recursor-#{@pdns_virtual_instance}.conf") %>
# pidfile: <%= ::File.join(@socket_dir, "pdns_recursor-#{@pdns_virtual_instance}.pid") %>
#

# source function library
. /etc/rc.d/init.d/functions


RETVAL=0
PROGNAME=<%= @service_name %>
PIDFILE=<%= ::File.join('/', 'var', 'run', @pdns_virtual_instance, "#{@service_name}.pid") %>
CONFIG_FILE=<%= ::File.join(@config_dir, "recursor-#{@pdns_virtual_instance}.conf") %>
INSTANCE_NAME=<%= @pdns_virtual_instance %>

# Derive the socket-dir setting from $CONFIG_FILE
# or fall back to the default /var/run if not specified there.
PIDDIR=$(awk -F= '/^socket-dir=/ {print $2}' $CONFIG_FILE)
if [ -z "$PIDDIR" ]; then PIDDIR=/var/run; fi
# The binary "pdns_recursor" handles its own pidfile according the following
# schema: pdns_recursor-<VIRTUAL_INSTANCE_NAME>
PIDFILE="${PIDDIR}/pdns_recursor-${INSTANCE_NAME}.pid"

# When using "--config-name" for pdns, pdns_recursor already prefix every
# resource by 'pdns_recursor-'.
EXTRAOPTS="--config-name=<%= @pdns_virtual_instance %> --config-dir=<%= @config_dir %>"

pdns_recursor="/usr/sbin/pdns_recursor ${EXTRAOPTS}"

create_socket_dir() {
if [ ! -d $PIDDIR ]; then
mkdir -p $PIDDIR
chmod 0755 $PIDDIR
fi
}

start() {
echo -n $"Starting pdns-recursor virtual instance '<%= @pdns_virtual_instance %>': "
create_socket_dir
daemon ${pdns_recursor} --daemon 2>/dev/null
RETVAL=$?
echo
Expand Down

0 comments on commit b62e019

Please sign in to comment.