From 4f8ecf273c4a239d007125f3b96a55100b661c04 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Oct 2015 14:55:33 +0200 Subject: [PATCH] update network service examples Signed-off-by: Denys Vlasenko --- examples/var_service/dhcp_if/convert2ntpconf | 2 +- examples/var_service/dhcp_if/dhcp_handler | 13 +++++++------ examples/var_service/dhcp_if/finish | 17 +++++++++++++++++ examples/var_service/dhcp_if/log/run | 2 +- examples/var_service/dhcp_if_pinger/run | 4 ++-- examples/var_service/ftpd/log/run | 2 +- examples/var_service/fw/run | 2 +- examples/var_service/httpd/log/run | 2 +- examples/var_service/ifplugd_if/log/run | 2 +- examples/var_service/ifplugd_if/run | 3 +++ examples/var_service/inetd/log/run | 2 +- examples/var_service/ntpd/log/run | 2 +- examples/var_service/ntpd/run | 2 +- examples/var_service/tftpd/log/run | 2 +- examples/var_service/zcip_if/finish | 13 +++++++++++++ examples/var_service/zcip_if/log/run | 2 +- examples/var_service/zcip_if/zcip_handler | 3 ++- 17 files changed, 55 insertions(+), 20 deletions(-) create mode 100755 examples/var_service/dhcp_if/finish create mode 100755 examples/var_service/zcip_if/finish diff --git a/examples/var_service/dhcp_if/convert2ntpconf b/examples/var_service/dhcp_if/convert2ntpconf index debf1ebfe..e9d829308 100755 --- a/examples/var_service/dhcp_if/convert2ntpconf +++ b/examples/var_service/dhcp_if/convert2ntpconf @@ -29,6 +29,6 @@ test "$ip" || exit 1 { for n in $ntpsrv; do echo "let cfg=cfg+1" - echo "ntpip[\$cfg]='$n'"; + echo "ntpip[\$cfg]='$n'" done } >"$1" diff --git a/examples/var_service/dhcp_if/dhcp_handler b/examples/var_service/dhcp_if/dhcp_handler index 927e02a17..3d2a5cb79 100755 --- a/examples/var_service/dhcp_if/dhcp_handler +++ b/examples/var_service/dhcp_if/dhcp_handler @@ -36,7 +36,7 @@ service=${PWD##*/} file_ipconf="$service.ipconf" file_ntpconf="$service.ntpconf" dir_ipconf="/var/run/service/fw" -dir_ntpconf="/var/run/service/ntp" +dir_ntpconf="/var/run/service/ntpd" exec >/dev/null #exec >>"$0.out" #debug @@ -47,7 +47,7 @@ echo "`date`: Params: $*" if test x"$1" != x"bound" && test x"$1" != x"renew" ; then # Reconfigure network with this interface disabled echo "Deconfiguring" - rm "$service.out" + rm "env.out" rm "$file_ipconf" rm "$file_ntpconf" rm "$dir_ipconf/$file_ipconf" @@ -57,7 +57,8 @@ if test x"$1" != x"bound" && test x"$1" != x"renew" ; then fi # Bound: we've got the lease -#env >"$service.out" # debug +# Record information for e.g. dhcp_$IF_pinger service +env >"env.out" ./convert2ipconf "$file_ipconf" # Reconfigure routing and firewall if needed @@ -69,7 +70,7 @@ if test $? != 0; then sv u /var/service/fw fi -if test -d /var/service/ntp; then +if test -d /var/service/ntpd; then ./convert2ntpconf "$file_ntpconf" # Reconfigure ntp server addresses if needed diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1 @@ -77,7 +78,7 @@ if test -d /var/service/ntp; then echo "Reconfiguring ntp" mkdir -p "$dir_ntpconf" 2>/dev/null cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" - sv t /var/service/ntp - sv u /var/service/ntp + sv t /var/service/ntpd + sv u /var/service/ntpd fi fi diff --git a/examples/var_service/dhcp_if/finish b/examples/var_service/dhcp_if/finish new file mode 100755 index 000000000..5e7667a2d --- /dev/null +++ b/examples/var_service/dhcp_if/finish @@ -0,0 +1,17 @@ +#!/bin/sh +# executed when service is taken down ("sv d .") + +service=${PWD##*/} +file_ipconf="$service.ipconf" +file_ntpconf="$service.ntpconf" +dir_ipconf="/var/run/service/fw" +dir_ntpconf="/var/run/service/ntpd" + +# Reconfigure network with this interface disabled +echo "Finish: deconfiguring" +rm "env.out" +rm "$file_ipconf" +rm "$file_ntpconf" +rm "$dir_ipconf/$file_ipconf" +rm "$dir_ntpconf/$file_ntpconf" +sv u /var/service/fw diff --git a/examples/var_service/dhcp_if/log/run b/examples/var_service/dhcp_if/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/dhcp_if/log/run +++ b/examples/var_service/dhcp_if/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/dhcp_if_pinger/run b/examples/var_service/dhcp_if_pinger/run index 1868510d1..e0e87a16a 100755 --- a/examples/var_service/dhcp_if_pinger/run +++ b/examples/var_service/dhcp_if_pinger/run @@ -21,9 +21,9 @@ if test -f "$0.log"; then mv "$0.log.new" "$0.log" fi -test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$ping_time" +test -f "/var/service/dhcp_$if/env.out" || exec env - sleep "$ping_time" -. "/var/service/dhcp_$if/dhcp_$if.out" +. "/var/service/dhcp_$if/env.out" test x"$router" != x"" || exec env - sleep "$ping_time" #msg "Pinging $router" diff --git a/examples/var_service/ftpd/log/run b/examples/var_service/ftpd/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/ftpd/log/run +++ b/examples/var_service/ftpd/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/fw/run b/examples/var_service/fw/run index 396b678ab..81c7f2e7c 100755 --- a/examples/var_service/fw/run +++ b/examples/var_service/fw/run @@ -62,7 +62,7 @@ umask 077 # Make sure rundir/ exists mkdir -p "$rundir" 2>/dev/null -chown -R "$user:" "$rundir" +chown -R "$user": "$rundir" chmod -R a=rX "$rundir" rm -rf rundir 2>/dev/null ln -s "$rundir" rundir diff --git a/examples/var_service/httpd/log/run b/examples/var_service/httpd/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/httpd/log/run +++ b/examples/var_service/httpd/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/ifplugd_if/log/run b/examples/var_service/ifplugd_if/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/ifplugd_if/log/run +++ b/examples/var_service/ifplugd_if/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/ifplugd_if/run b/examples/var_service/ifplugd_if/run index 2781cf9f9..c4f766e88 100755 --- a/examples/var_service/ifplugd_if/run +++ b/examples/var_service/ifplugd_if/run @@ -8,6 +8,9 @@ pwd="$PWD" if="${PWD##*/ifplugd_}" +echo "* Upping iface $if" +ip link set dev "$if" up + echo "* Starting ifplugd on $if [$$]" exec \ env - PATH="$PATH" \ diff --git a/examples/var_service/inetd/log/run b/examples/var_service/inetd/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/inetd/log/run +++ b/examples/var_service/inetd/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/ntpd/log/run b/examples/var_service/ntpd/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/ntpd/log/run +++ b/examples/var_service/ntpd/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/ntpd/run b/examples/var_service/ntpd/run index 581d231a3..6f2a68188 100755 --- a/examples/var_service/ntpd/run +++ b/examples/var_service/ntpd/run @@ -15,7 +15,7 @@ default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool" # Make sure rundir/ exists mkdir -p "$rundir" 2>/dev/null -chown -R "$user:" "$rundir" +chown -R "$user": "$rundir" chmod -R a=rX "$rundir" rm -rf rundir 2>/dev/null ln -s "$rundir" rundir diff --git a/examples/var_service/tftpd/log/run b/examples/var_service/tftpd/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/tftpd/log/run +++ b/examples/var_service/tftpd/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/zcip_if/finish b/examples/var_service/zcip_if/finish new file mode 100755 index 000000000..95995cf5f --- /dev/null +++ b/examples/var_service/zcip_if/finish @@ -0,0 +1,13 @@ +#!/bin/sh +# executed when service is taken down ("sv d .") + +service=${PWD##*/} +file_ipconf="$service.ipconf" +dir_ipconf="/var/run/service/fw" + +# Reconfigure network with this interface disabled +echo "Finish: deconfiguring" +rm "env.out" +rm "$file_ipconf" +rm "$dir_ipconf/$file_ipconf" +sv u /var/service/fw diff --git a/examples/var_service/zcip_if/log/run b/examples/var_service/zcip_if/log/run index 560d1b19f..69d74b73f 100755 --- a/examples/var_service/zcip_if/log/run +++ b/examples/var_service/zcip_if/log/run @@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`" mkdir -p "$logdir" 2>/dev/null chown -R "$user": "$logdir" chmod -R go-rwxst,u+rwX "$logdir" -rm logdir +rm -rf logdir ln -s "$logdir" logdir # make this dir accessible to logger diff --git a/examples/var_service/zcip_if/zcip_handler b/examples/var_service/zcip_if/zcip_handler index 13010db27..3c6ca788b 100755 --- a/examples/var_service/zcip_if/zcip_handler +++ b/examples/var_service/zcip_if/zcip_handler @@ -33,7 +33,8 @@ if test x"$1" != x"config"; then fi # "config": we've got the address -#env # debug +# Record information for e.g. dhcp_$IF_pinger service +env >"env.out" ./convert2ipconf "$file_ipconf" # Reconfigure routing and firewall if needed