examples/var_service/: use "svc" for service commands, other tweaks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e5d5f5b9a7
commit
aa75a7da7f
@ -52,7 +52,7 @@ if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
|
|||||||
rm "$file_ntpconf"
|
rm "$file_ntpconf"
|
||||||
rm "$dir_ipconf/$file_ipconf"
|
rm "$dir_ipconf/$file_ipconf"
|
||||||
rm "$dir_ntpconf/$file_ntpconf"
|
rm "$dir_ntpconf/$file_ntpconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ if test $? != 0; then
|
|||||||
echo "Reconfiguring fw"
|
echo "Reconfiguring fw"
|
||||||
mkdir -p "$dir_ipconf" 2>/dev/null
|
mkdir -p "$dir_ipconf" 2>/dev/null
|
||||||
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -d /var/service/ntpd; then
|
if test -d ../ntpd; then
|
||||||
./convert2ntpconf "$file_ntpconf"
|
./convert2ntpconf "$file_ntpconf"
|
||||||
# Reconfigure ntp server addresses if needed
|
# Reconfigure ntp server addresses if needed
|
||||||
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
|
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
|
||||||
@ -78,7 +78,7 @@ if test -d /var/service/ntpd; then
|
|||||||
echo "Reconfiguring ntp"
|
echo "Reconfiguring ntp"
|
||||||
mkdir -p "$dir_ntpconf" 2>/dev/null
|
mkdir -p "$dir_ntpconf" 2>/dev/null
|
||||||
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
|
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
|
||||||
sv t /var/service/ntpd
|
svc -t ntpd
|
||||||
sv u /var/service/ntpd
|
svc -u ntpd
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -14,4 +14,4 @@ rm "$file_ipconf"
|
|||||||
rm "$file_ntpconf"
|
rm "$file_ntpconf"
|
||||||
rm "$dir_ipconf/$file_ipconf"
|
rm "$dir_ipconf/$file_ipconf"
|
||||||
rm "$dir_ntpconf/$file_ntpconf"
|
rm "$dir_ntpconf/$file_ntpconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
|
@ -21,9 +21,9 @@ if test -f "$0.log"; then
|
|||||||
mv "$0.log.new" "$0.log"
|
mv "$0.log.new" "$0.log"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
test -f "/var/service/dhcp_$if/env.out" || exec env - sleep "$ping_time"
|
test -f "../dhcp_$if/env.out" || exec env - sleep "$ping_time"
|
||||||
|
|
||||||
. "/var/service/dhcp_$if/env.out"
|
. "../dhcp_$if/env.out"
|
||||||
test x"$router" != x"" || exec env - sleep "$ping_time"
|
test x"$router" != x"" || exec env - sleep "$ping_time"
|
||||||
|
|
||||||
#msg "Pinging $router"
|
#msg "Pinging $router"
|
||||||
@ -36,12 +36,12 @@ while true; do
|
|||||||
env - sleep "$retry_time"
|
env - sleep "$retry_time"
|
||||||
done
|
done
|
||||||
|
|
||||||
test -d "/var/service/dhcp_$if" && {
|
test -d "../dhcp_$if" && {
|
||||||
msg "Restarting /var/service/dhcp_$if"
|
msg "Restarting dhcp_$if"
|
||||||
sv t "/var/service/dhcp_$if"
|
svc -t "dhcp_$if"
|
||||||
}
|
}
|
||||||
test -d "/var/service/supplicant_$if" && {
|
test -d "../supplicant_$if" && {
|
||||||
msg "Restarting /var/service/supplicant_$if"
|
msg "Restarting supplicant_$if"
|
||||||
sv t "/var/service/supplicant_$if"
|
svc -t "supplicant_$if"
|
||||||
}
|
}
|
||||||
exec env - sleep "$ping_time"
|
exec env - sleep "$ping_time"
|
||||||
|
@ -35,4 +35,4 @@ $empty && echo "server=8.8.8.8"
|
|||||||
$empty && echo "server=8.8.4.4"
|
$empty && echo "server=8.8.4.4"
|
||||||
|
|
||||||
# SIGHUP: make dnsmasq reload config
|
# SIGHUP: make dnsmasq reload config
|
||||||
sv h dnsmasq
|
svc -h dnsmasq
|
||||||
|
@ -8,7 +8,7 @@ extif="if"
|
|||||||
ext_open_tcp="22 80 88" # space-separated
|
ext_open_tcp="22 80 88" # space-separated
|
||||||
|
|
||||||
# Make ourself one-shot
|
# Make ourself one-shot
|
||||||
sv o .
|
svc -o .
|
||||||
# Debug
|
# Debug
|
||||||
#date '+%Y-%m-%d %H:%M:%S' >>"$0.log"
|
#date '+%Y-%m-%d %H:%M:%S' >>"$0.log"
|
||||||
|
|
||||||
|
@ -6,12 +6,22 @@ exec 2>&1
|
|||||||
exec </dev/null
|
exec </dev/null
|
||||||
|
|
||||||
user=root
|
user=root
|
||||||
|
start_delay=15
|
||||||
|
net_down_delay=5
|
||||||
pool="us.pool.ntp.org" # replace "us" with your country code
|
pool="us.pool.ntp.org" # replace "us" with your country code
|
||||||
|
|
||||||
service="${PWD##*/}"
|
service="${PWD##*/}"
|
||||||
rundir="/var/run/service/$service"
|
rundir="/var/run/service/$service"
|
||||||
default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool"
|
default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool"
|
||||||
|
|
||||||
|
echo "* Checking network"
|
||||||
|
test -f /var/run/service/fw/up || exec sleep $net_down_delay
|
||||||
|
|
||||||
|
# With multiple interfaces (e.g. wired+wireless) going up,
|
||||||
|
# networking scripts may restart ntpd service several times
|
||||||
|
# in quick succession. Do not be too eager to start sending
|
||||||
|
# NTP requests:
|
||||||
|
sleep $start_delay
|
||||||
|
|
||||||
# Make sure rundir/ exists
|
# Make sure rundir/ exists
|
||||||
mkdir -p "$rundir" 2>/dev/null
|
mkdir -p "$rundir" 2>/dev/null
|
||||||
@ -20,30 +30,25 @@ chmod -R a=rX "$rundir"
|
|||||||
rm -rf rundir 2>/dev/null
|
rm -rf rundir 2>/dev/null
|
||||||
ln -s "$rundir" rundir
|
ln -s "$rundir" rundir
|
||||||
|
|
||||||
|
|
||||||
echo "* Checking network"
|
|
||||||
test -f /var/run/service/fw/up || exec sleep 7
|
|
||||||
sleep 5 # to let it settle
|
|
||||||
|
|
||||||
# Grab config from dhcp
|
# Grab config from dhcp
|
||||||
cfg=-1
|
cfg=-1
|
||||||
for f in rundir/*.ntpconf; do
|
for f in rundir/*.ntpconf; do
|
||||||
test -f "$f" || continue
|
test -f "$f" || continue
|
||||||
. "$f"
|
. "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Select peers
|
# Select peers
|
||||||
p_opt=""
|
p_opt=""
|
||||||
cfg=0
|
cfg=0
|
||||||
while test x"${ntpip[$cfg]}" != x""; do
|
while test x"${ntpip[$cfg]}" != x""; do
|
||||||
p_opt="$p_opt -p ${ntpip[$cfg]}"
|
p_opt="$p_opt -p ${ntpip[$cfg]}"
|
||||||
let cfg=cfg+1
|
let cfg=cfg+1
|
||||||
done
|
done
|
||||||
test x"$p_opt" == x"" && p_opt="$default_p_opt"
|
test x"$p_opt" == x"" && p_opt="$default_p_opt"
|
||||||
|
|
||||||
if test x"$p_opt" == x""; then
|
if test x"$p_opt" == x""; then
|
||||||
echo "* No NTP peers configured, stopping"
|
echo "* No NTP peers configured, stopping"
|
||||||
sv o .
|
svc -o .
|
||||||
exec sleep 1
|
exec sleep 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# executed when service is taken down ("sv d .")
|
# executed when service is taken down
|
||||||
|
|
||||||
service=${PWD##*/}
|
service=${PWD##*/}
|
||||||
file_ipconf="$service.ipconf"
|
file_ipconf="$service.ipconf"
|
||||||
@ -10,4 +10,4 @@ echo "Finish: deconfiguring"
|
|||||||
rm "env.out"
|
rm "env.out"
|
||||||
rm "$file_ipconf"
|
rm "$file_ipconf"
|
||||||
rm "$dir_ipconf/$file_ipconf"
|
rm "$dir_ipconf/$file_ipconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
|
@ -28,7 +28,7 @@ if test x"$1" != x"config"; then
|
|||||||
echo "Deconfiguring"
|
echo "Deconfiguring"
|
||||||
rm "$file_ipconf"
|
rm "$file_ipconf"
|
||||||
rm "$dir_ipconf/$file_ipconf"
|
rm "$dir_ipconf/$file_ipconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -43,5 +43,5 @@ if test $? != 0; then
|
|||||||
echo "Reconfiguring fw"
|
echo "Reconfiguring fw"
|
||||||
mkdir -p "$dir_ipconf" 2>/dev/null
|
mkdir -p "$dir_ipconf" 2>/dev/null
|
||||||
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
||||||
sv u /var/service/fw
|
svc -u fw
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user