From 4bf86dc02faec097545dd3491ee1cb38c5883378 Mon Sep 17 00:00:00 2001 From: fbt Date: Thu, 3 Jul 2014 11:05:52 +0400 Subject: [PATCH] pidfiles are evil --- init.d/cjdroute | 20 +++++++++++++------- init.d/dbus | 9 ++------- init.d/dhcpcd | 5 ++--- init.d/dropbear | 1 + init.d/mpd | 3 ++- init.d/nrpe | 3 ++- init.d/ntpd | 4 ++-- init.d/privoxy | 4 ++-- init.d/sshd | 4 ++-- init.d/sysctl | 6 ++++++ init.d/syslog-ng | 3 ++- init.d/xinetd | 4 ++-- 12 files changed, 38 insertions(+), 28 deletions(-) diff --git a/init.d/cjdroute b/init.d/cjdroute index cac2f2a..ab6ebe6 100755 --- a/init.d/cjdroute +++ b/init.d/cjdroute @@ -2,7 +2,8 @@ unset reload -service_command='/usr/bin/cjdroute' +service_command='/usr/local/sbin/cjdroute-start' +service_respawn=true cjdroute_config='/etc/cjdroute.conf' cjdroute_admin_port='11234' @@ -16,10 +17,6 @@ cjdroute.check_tun_module() { } } -get_pid() { - lsof -i :"$cjdroute_admin_port" | tail -1 | cut -d ' ' -f 2 -} - start() { cjdroute.check_tun_module || { return 1; } @@ -28,7 +25,16 @@ start() { return 1 } - "$service_command" < "${cjdroute_config}" &>"$service_logfile" && { - watchman.msg "${service_name} started" + watchman.start +} + +stop() { + [[ "$service_respawn" == 'true' ]] && { watchman.stop; } # stopping the watchdog + + # Stopping the actual s-o-b daemon that won't die properly. + cjdroute_control_pid=`lsof -i :"$cjdroute_admin_port" | tail -1 | cut -d ' ' -f 2` + watchman.pid_check "$cjdroute_control_pid" && { + kill "$cjdroute_control_pid" + watchman.pid_wait "$cjdroute_control_pid" } } diff --git a/init.d/dbus b/init.d/dbus index 60c5756..474a89a 100755 --- a/init.d/dbus +++ b/init.d/dbus @@ -1,8 +1,8 @@ #!/usr/bin/env watchman +service_respawn=true service_command='/usr/bin/dbus-daemon' -service_args='--system' -service_pidfile='/run/dbus/pid' +service_args='--system --nofork' start_pre() { /usr/bin/dbus-uuidgen --ensure=/etc/machine-id @@ -13,8 +13,3 @@ start() { start_pre watchman.start } - -stop() { - [[ -e "$service_pidfile" ]] && { rm "$service_pidfile"; } - watchman.stop -} diff --git a/init.d/dhcpcd b/init.d/dhcpcd index ba522b6..0be06f1 100755 --- a/init.d/dhcpcd +++ b/init.d/dhcpcd @@ -1,7 +1,6 @@ #!/usr/bin/env watchman # dhcp client daemon initscript +service_respawn=true service_command='/usr/sbin/dhcpcd' -service_pidfile='/var/run/dhcpcd.pid' - -source "${cfg_dir}/conf.d/dhcpcd.sh" +service_args='-B -C resolv.conf' diff --git a/init.d/dropbear b/init.d/dropbear index 022d72a..2434be2 100755 --- a/init.d/dropbear +++ b/init.d/dropbear @@ -1,3 +1,4 @@ #!/usr/bin/env watchman +service_respawn=true service_command='/bin/dropbear' diff --git a/init.d/mpd b/init.d/mpd index 56c8e70..fe61f0e 100755 --- a/init.d/mpd +++ b/init.d/mpd @@ -1,4 +1,5 @@ #!/usr/bin/env watchman +service_respawn=true service_command='/bin/mpd' -service_pidfile='/run/mpd.pid' +service_args='--no-daemon' diff --git a/init.d/nrpe b/init.d/nrpe index 5c84251..c2f5e90 100755 --- a/init.d/nrpe +++ b/init.d/nrpe @@ -2,6 +2,7 @@ cfg_nrpe_config='/etc/nrpe/nrpe.cfg' +service_respawn=true service_command='/usr/bin/nrpe' service_pidfile='/run/nrpe.pid' -service_args=" -c ${cfg_nrpe_config} -d" +service_args="-c ${cfg_nrpe_config} -d" diff --git a/init.d/ntpd b/init.d/ntpd index e3dc959..3f70614 100755 --- a/init.d/ntpd +++ b/init.d/ntpd @@ -2,6 +2,6 @@ cfg_ntpd_config='/etc/ntp.conf' +service_respawn='true' service_command='/bin/ntpd' -service_pidfile='/run/ntpd.pid' -service_args="-c $cfg_ntpd_config -p $service_pidfile" +service_args="-c $cfg_ntpd_config -n" diff --git a/init.d/privoxy b/init.d/privoxy index 2336685..ad30ff1 100755 --- a/init.d/privoxy +++ b/init.d/privoxy @@ -3,9 +3,9 @@ privoxy_username='privoxy' privoxy_configfile='/etc/privoxy/config' +service_respawn='true' service_command='/usr/bin/privoxy' -service_pidfile='/run/privoxy.pid' -service_args="--pidfile ${service_pidfile} --user ${privoxy_username} ${privoxy_configfile}" +service_args="--no-daemon --user ${privoxy_username} ${privoxy_configfile}" privoxy::configtest() { "${service_command}" --config-test ${service_args} diff --git a/init.d/sshd b/init.d/sshd index 8ea5322..0a38cf1 100755 --- a/init.d/sshd +++ b/init.d/sshd @@ -2,9 +2,9 @@ cfg_sshd_cfgdir='/etc/ssh' +service_respawn=true service_command='/bin/sshd' -service_args="-f $cfg_sshd_cfgdir/sshd_config" -service_pidfile='/run/sshd.pid' +service_args="-D -f $cfg_sshd_cfgdir/sshd_config" sshd_genkeys() { [[ -e "/etc/ssh/ssh_host_key" ]] || { ssh-keygen -A; } diff --git a/init.d/sysctl b/init.d/sysctl index 2d39d30..10353d3 100755 --- a/init.d/sysctl +++ b/init.d/sysctl @@ -13,3 +13,9 @@ done service_type='oneshot' service_command='/sbin/sysctl' service_args="-p /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf" + +start() { + watchman.start +} + +unset restart reload diff --git a/init.d/syslog-ng b/init.d/syslog-ng index ad983fb..7a604bd 100755 --- a/init.d/syslog-ng +++ b/init.d/syslog-ng @@ -1,4 +1,5 @@ #!/usr/bin/env watchman +service_respawn=true service_command='/bin/syslog-ng' -service_pidfile='/run/syslog-ng.pid' +service_args='-F' diff --git a/init.d/xinetd b/init.d/xinetd index 2364f02..53ad317 100755 --- a/init.d/xinetd +++ b/init.d/xinetd @@ -1,5 +1,5 @@ #!/usr/bin/env watchman +service_respawn=true service_command='/usr/bin/xinetd' -service_pidfile="/run/xinetd.pid" -service_args="-pidfile $service_pidfile" +service_args='-dontfork'