procd: convert various packages to procd style init.d scripts

Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 38023
This commit is contained in:
John Crispin 2013-09-17 21:45:30 +00:00
parent 4f62127dea
commit f874094402
9 changed files with 109 additions and 103 deletions

View file

@ -3,17 +3,30 @@
START=20 START=20
STOP=90 STOP=90
SERVICE_DAEMONIZE=1 USE_PROCD=1
SERVICE_WRITE_PID=1
start() { start_service() {
stop
[ -e /proc/sys/kernel/core_pattern ] && { [ -e /proc/sys/kernel/core_pattern ] && {
ulimit -c unlimited ulimit -c unlimited
echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern
} }
service_start /sbin/netifd procd_open_instance
procd_set_param command /sbin/netifd
procd_set_param respawn
procd_close_instance
}
reload_service() {
ubus call network reload
/sbin/wifi down
/sbin/wifi up
}
stop_service() {
/sbin/wifi down
}
service_running() {
setup_switch() { return 0; } setup_switch() { return 0; }
include /lib/network include /lib/network
@ -25,24 +38,20 @@ start() {
/sbin/wifi up /sbin/wifi up
} }
service_triggers()
{
procd_add_reload_trigger "network"
}
restart() { restart() {
ifdown -a ifdown -a
sleep 1 sleep 1
start trap '' TERM
stop "$@"
start "$@"
} }
shutdown() { shutdown() {
ifdown -a ifdown -a
stop stop
} }
stop() {
/sbin/wifi down
service_stop /sbin/netifd
}
reload() {
ubus call network reload
/sbin/wifi down
/sbin/wifi up
}

View file

@ -3,7 +3,8 @@
START=60 START=60
SERVICE_USE_PID=1 USE_PROCD=1
PROG=/usr/sbin/dnsmasq
DNS_SERVERS="" DNS_SERVERS=""
DOMAIN="" DOMAIN=""
@ -479,7 +480,12 @@ dhcp_hostrecord_add() {
xappend "--host-record=$record" xappend "--host-record=$record"
} }
start() { service_triggers()
{
procd_add_reload_trigger "dhcp"
}
start_service() {
include /lib/network include /lib/network
scan_interfaces scan_interfaces
@ -488,6 +494,10 @@ start() {
config_load dhcp config_load dhcp
procd_open_instance
procd_set_param command $PROG -C $CONFIGFILE -k
procd_close_instance
# before we can call xappend # before we can call xappend
mkdir -p $(dirname $CONFIGFILE) mkdir -p $(dirname $CONFIGFILE)
@ -528,23 +538,19 @@ start() {
config_foreach dhcp_cname_add cname config_foreach dhcp_cname_add cname
echo >> $CONFIGFILE echo >> $CONFIGFILE
service_start /usr/sbin/dnsmasq -C $CONFIGFILE && { rm -f /tmp/resolv.conf
rm -f /tmp/resolv.conf [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && {
[ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && { echo "search $DOMAIN" >> /tmp/resolv.conf
echo "search $DOMAIN" >> /tmp/resolv.conf
}
DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
for DNS_SERVER in $DNS_SERVERS ; do
echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
done
} }
DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
for DNS_SERVER in $DNS_SERVERS ; do
echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
done
} }
stop() { stop_service() {
service_stop /usr/sbin/dnsmasq && { [ -f /tmp/resolv.conf ] && {
[ -f /tmp/resolv.conf ] && { rm -f /tmp/resolv.conf
rm -f /tmp/resolv.conf ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
}
} }
} }

View file

@ -123,7 +123,7 @@ start_service()
service_triggers() service_triggers()
{ {
procd_add_config_trigger "dropbear" "/etc/init.d/dropbear" "restart" procd_add_reload_trigger "dropbear"
} }
killclients() killclients()

View file

@ -3,9 +3,7 @@
START=61 START=61
SERVICE_DAEMONIZE=1 USE_PROCD=1
SERVICE_WRITE_PID=1
find_nameserver() { find_nameserver() {
. /lib/functions/network.sh . /lib/functions/network.sh
@ -38,28 +36,22 @@ start_instance() {
config_get port "$cfg" port $((PORT++)) config_get port "$cfg" port $((PORT++))
SERVICE_PID_FILE="/var/run/ipset-dns-$port.pid" \ procd_open_instance
service_start /usr/sbin/ipset-dns "$ipset" "$ipset6" "$port" "$dns" procd_set_param command /usr/sbin/ipset-dns "$ipset" "$ipset6" "$port" "$dns"
procd_set_param env NO_DAEMONIZE=1
procd_set_param respawn
procd_close_instance
} }
start() { service_triggers()
{
procd_add_reload_trigger "ipset-dns"
}
start_service() {
PORT=53001 PORT=53001
DEFNS="$(find_nameserver)" DEFNS="$(find_nameserver)"
# required by ipset-dns to not daemonize itself
export NO_DAEMONIZE=1
config_load ipset-dns config_load ipset-dns
config_foreach start_instance ipset-dns config_foreach start_instance ipset-dns
} }
stop() {
local pid
for pid in /var/run/ipset-dns-*.pid; do
[ -f "$pid" ] || continue
SERVICE_PID_FILE="$pid" \
service_stop /usr/sbin/ipset-dns
rm -f "$pid"
done
}

View file

@ -2,9 +2,12 @@
# Copyright (c) 2011-2012 OpenWrt.org # Copyright (c) 2011-2012 OpenWrt.org
START=80 START=80
USE_PROCD=1
PROG=/usr/sbin/relayd
resolve_ifname() { resolve_ifname() {
grep -qs "^ *$1:" /proc/net/dev && { grep -qs "^ *$1:" /proc/net/dev && {
append args "-I $1" procd_append_param command -I "$1"
append ifaces "$1" append ifaces "$1"
} }
} }
@ -37,6 +40,9 @@ start_relay() {
fi fi
} }
procd_open_instance
procd_set_param command "$PROG"
local net networks local net networks
config_get networks "$cfg" network config_get networks "$cfg" network
for net in $networks; do for net in $networks; do
@ -53,44 +59,41 @@ start_relay() {
local ipaddr local ipaddr
config_get ipaddr "$cfg" ipaddr config_get ipaddr "$cfg" ipaddr
[ -n "$ipaddr" ] && append args "-L $ipaddr" [ -n "$ipaddr" ] && procd_append_param command -L "$ipaddr"
local gateway local gateway
config_get gateway "$cfg" gateway config_get gateway "$cfg" gateway
[ -n "$gateway" ] && append args "-G $gateway" [ -n "$gateway" ] && procd_append_param command -G "$gateway"
local expiry # = 30 local expiry # = 30
config_get expiry "$cfg" expiry config_get expiry "$cfg" expiry
[ -n "$expiry" ] && append args "-t $expiry" [ -n "$expiry" ] && procd_append_param command "$expiry"
local retry # = 5 local retry # = 5
config_get retry "$cfg" retry config_get retry "$cfg" retry
[ -n "$retry" ] && append args "-p $retry" [ -n "$retry" ] && procd_append_param command -p "$retry"
local table # = 16800 local table # = 16800
config_get table "$cfg" table config_get table "$cfg" table
[ -n "$table" ] && append args "-T $table" [ -n "$table" ] && procd_append_param command -T "$table"
local fwd_bcast # = 1 local fwd_bcast # = 1
config_get_bool fwd_bcast "$cfg" forward_bcast 1 config_get_bool fwd_bcast "$cfg" forward_bcast 1
[ $fwd_bcast -eq 1 ] && append args "-B" [ $fwd_bcast -eq 1 ] && procd_append_param command "-B"
local fwd_dhcp # = 1 local fwd_dhcp # = 1
config_get_bool fwd_dhcp "$cfg" forward_dhcp 1 config_get_bool fwd_dhcp "$cfg" forward_dhcp 1
[ $fwd_dhcp -eq 1 ] && append args "-D" [ $fwd_dhcp -eq 1 ] && procd_append_param command"-D"
service_start /usr/sbin/relayd $args procd_close_instance
} }
stop() { service_triggers()
for pid in /var/run/relay-*.pid; do {
SERVICE_PID_FILE="$pid" procd_add_reload_trigger "network"
service_stop /usr/sbin/relayd
rm -f "$SERVICE_PID_FILE"
done
} }
start() { start_service() {
include /lib/network include /lib/network
config_load network config_load network
config_foreach start_relay interface config_foreach start_relay interface

View file

@ -3,8 +3,7 @@
START=50 START=50
SERVICE_DAEMONIZE=1 USE_PROCD=1
SERVICE_WRITE_PID=1
UHTTPD_BIN="/usr/sbin/uhttpd" UHTTPD_BIN="/usr/sbin/uhttpd"
PX5G_BIN="/usr/sbin/px5g" PX5G_BIN="/usr/sbin/px5g"
@ -17,7 +16,7 @@ append_arg() {
local val local val
config_get val "$cfg" "$var" config_get val "$cfg" "$var"
[ -n "$val" -o -n "$def" ] && append UHTTPD_ARGS "$opt ${val:-$def}" [ -n "$val" -o -n "$def" ] && procd_append_param command "$opt" "${val:-$def}"
} }
append_bool() { append_bool() {
@ -28,7 +27,7 @@ append_bool() {
local val local val
config_get_bool val "$cfg" "$var" "$def" config_get_bool val "$cfg" "$var" "$def"
[ "$val" = 1 ] && append UHTTPD_ARGS "$opt" [ "$val" = 1 ] && procd_append_param command "$opt"
} }
generate_keys() { generate_keys() {
@ -53,7 +52,6 @@ generate_keys() {
start_instance() start_instance()
{ {
UHTTPD_ARGS=""
UHTTPD_CERT="" UHTTPD_CERT=""
UHTTPD_KEY="" UHTTPD_KEY=""
@ -61,6 +59,9 @@ start_instance()
local realm="$(uci_get system.@system[0].hostname)" local realm="$(uci_get system.@system[0].hostname)"
local listen http https interpreter indexes path local listen http https interpreter indexes path
procd_open_instance
procd_set_param command "$UHTTPD_BIN" -f
append_arg "$cfg" home "-h" append_arg "$cfg" home "-h"
append_arg "$cfg" realm "-r" "${realm:-OpenWrt}" append_arg "$cfg" realm "-r" "${realm:-OpenWrt}"
append_arg "$cfg" config "-c" append_arg "$cfg" config "-c"
@ -84,17 +85,17 @@ start_instance()
config_get http "$cfg" listen_http config_get http "$cfg" listen_http
for listen in $http; do for listen in $http; do
append UHTTPD_ARGS "-p $listen" procd_append_param command -p "$listen"
done done
config_get interpreter "$cfg" interpreter config_get interpreter "$cfg" interpreter
for path in $interpreter; do for path in $interpreter; do
append UHTTPD_ARGS "-i $path" procd_append_param command -i "$path"
done done
config_get indexes "$cfg" index_page config_get indexes "$cfg" index_page
for path in $indexes; do for path in $indexes; do
append UHTTPD_ARGS "-I $path" procd_append_param command -I "$path"
done done
config_get https "$cfg" listen_https config_get https "$cfg" listen_https
@ -116,29 +117,20 @@ start_instance()
} }
} }
SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid procd_close_instance
service_start $UHTTPD_BIN -f $UHTTPD_ARGS
# Check if daemon is running, if not then # Check if daemon is running, if not then
# re-execute in foreground to display error. # re-execute in foreground to display error.
sleep 1 && service_check $UHTTPD_BIN || \ # sleep 1 && service_check $UHTTPD_BIN || \
$UHTTPD_BIN -f $UHTTPD_ARGS # $UHTTPD_BIN -f $UHTTPD_ARGS
} }
stop_instance() service_triggers()
{ {
local cfg="$1" procd_add_reload_trigger "uhttpd"
SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid
service_stop $UHTTPD_BIN
} }
start() { start_service() {
config_load uhttpd config_load uhttpd
config_foreach start_instance uhttpd config_foreach start_instance uhttpd
} }
stop() {
config_load uhttpd
config_foreach stop_instance uhttpd
}

View file

@ -8,7 +8,6 @@ STOP=89
USE_PROCD=1 USE_PROCD=1
NAME=logread NAME=logread
PROG=/sbin/logread PROG=/sbin/logread
PIDCOUNT=1
start_service_file() start_service_file()
{ {
@ -24,8 +23,6 @@ start_service_file()
procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file" procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file"
[ -n "${log_size}" ] && procd_append_param command -S "$log_size" [ -n "${log_size}" ] && procd_append_param command -S "$log_size"
procd_close_instance procd_close_instance
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
} }
start_service_remote() start_service_remote()
@ -43,8 +40,6 @@ start_service_remote()
procd_set_param command "$PROG" -f -r "$log_ip" "${log_port:-514}" -p "$pid_file" procd_set_param command "$PROG" -f -r "$log_ip" "${log_port:-514}" -p "$pid_file"
[ "${log_proto}" != "udp" ] || procd_append_param command -u [ "${log_proto}" != "udp" ] || procd_append_param command -u
procd_close_instance procd_close_instance
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
} }
service_triggers() service_triggers()

View file

@ -2,11 +2,14 @@
START=12 START=12
SERVICE_DAEMONIZE=1 USE_PROCD=1
SERVICE_WRITE_PID=1 NAME=rpcd
PROG=/sbin/rpcd
start() { start_service() {
service_start /sbin/rpcd procd_open_instance
procd_set_param command "$PROG"
procd_close_instance
} }
stop() { stop() {

View file

@ -27,5 +27,11 @@ start_service() {
procd_append_param command -p $peer procd_append_param command -p $peer
done done
} }
procd_set_param respawn
procd_close_instance procd_close_instance
} }
service_triggers()
{
procd_add_reload_trigger "system"
}