| 1 |
|
| 2 |
pp_kit_service_group_script () {
|
| 3 |
typeset grp svcs scriptpath out
|
| 4 |
grp="$1"
|
| 5 |
svcs="$2"
|
| 6 |
scriptpath="/sbin/init.d/$grp"
|
| 7 |
out="$pp_destdir$scriptpath"
|
| 8 |
|
| 9 |
pp_add_file_if_missing $scriptpath run 755 || return 0
|
| 10 |
|
| 11 |
cat <<-. > $out
|
| 12 |
#!/sbin/sh
|
| 13 |
# generated by pp $pp_version
|
| 14 |
svcs="$svcs"
|
| 15 |
.
|
| 16 |
|
| 17 |
cat <<-'.' >> $out
|
| 18 |
#-- starts services in order.. stops them all if any break
|
| 19 |
pp_start () {
|
| 20 |
undo=
|
| 21 |
for svc in $svcs; do
|
| 22 |
/sbin/init.d/$svc start
|
| 23 |
case $? in
|
| 24 |
0|4)
|
| 25 |
undo="$svc $undo"
|
| 26 |
;;
|
| 27 |
*)
|
| 28 |
if test -n "$undo"; then
|
| 29 |
for svc in $undo; do
|
| 30 |
/sbin/init.d/$svc stop
|
| 31 |
done
|
| 32 |
return 1
|
| 33 |
fi
|
| 34 |
;;
|
| 35 |
esac
|
| 36 |
done
|
| 37 |
return 0
|
| 38 |
}
|
| 39 |
|
| 40 |
#-- stops services in reverse
|
| 41 |
pp_stop () {
|
| 42 |
reverse=
|
| 43 |
for svc in $svcs; do
|
| 44 |
reverse="$svc $reverse"
|
| 45 |
done
|
| 46 |
rc=0
|
| 47 |
for svc in $reverse; do
|
| 48 |
/sbin/init.d/$svc stop || rc=$?
|
| 49 |
done
|
| 50 |
return $rc
|
| 51 |
}
|
| 52 |
|
| 53 |
case $1 in
|
| 54 |
start_msg) echo "Starting $svcs";;
|
| 55 |
stop_msg) echo "Stopping $svcs";;
|
| 56 |
start) pp_start;;
|
| 57 |
stop) pp_stop;;
|
| 58 |
*) echo "usage: $0 {start|stop|start_msg|stop_msg}"
|
| 59 |
exit 1;;
|
| 60 |
esac
|
| 61 |
.
|
| 62 |
}
|
| 63 |
|
| 64 |
pp_kit_service_script () {
|
| 65 |
typeset svc scriptpath out
|
| 66 |
|
| 67 |
svc="$1"
|
| 68 |
scriptpath="/sbin/init.d/$svc"
|
| 69 |
|
| 70 |
pp_load_service_vars "$svc"
|
| 71 |
|
| 72 |
test -n "$user" -a x"$user" != x"root" &&
|
| 73 |
cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\""
|
| 74 |
if test -z "$pidfile"; then
|
| 75 |
pidfile="/var/run/$svc.pid"
|
| 76 |
cmd="$cmd & echo \$! > \$pidfile"
|
| 77 |
fi
|
| 78 |
|
| 79 |
pp_add_file_if_missing $scriptpath run 755
|
| 80 |
|
| 81 |
cat <<-. > $pp_destdir$scriptpath
|
| 82 |
svc="$svc"
|
| 83 |
pidfile="$pidfile"
|
| 84 |
|
| 85 |
pp_start () {
|
| 86 |
$cmd
|
| 87 |
}
|
| 88 |
.
|
| 89 |
cat <<-'.' >>$pp_destdir$scriptpath
|
| 90 |
pp_stop () {
|
| 91 |
if test ! -s "$pidfile"; then
|
| 92 |
echo "Unable to stop $svc (no pid file)"
|
| 93 |
return 1
|
| 94 |
else
|
| 95 |
read pid < "$pidfile"
|
| 96 |
if kill -0 "$pid" 2>/dev/null; then
|
| 97 |
if kill -${stop_signal:-TERM} "$pid"; then
|
| 98 |
rm -f "$pidfile"
|
| 99 |
return 0
|
| 100 |
else
|
| 101 |
echo "Unable to stop $svc"
|
| 102 |
return 1
|
| 103 |
fi
|
| 104 |
else
|
| 105 |
rm -f "$pidfile"
|
| 106 |
return 0
|
| 107 |
fi
|
| 108 |
fi
|
| 109 |
}
|
| 110 |
|
| 111 |
pp_running () {
|
| 112 |
if test ! -s "$pidfile"; then
|
| 113 |
return 1
|
| 114 |
else
|
| 115 |
read pid < "$pidfile"
|
| 116 |
kill -0 "$pid" 2>/dev/null
|
| 117 |
fi
|
| 118 |
}
|
| 119 |
case $1 in
|
| 120 |
start_msg) echo "Starting the $svc service";;
|
| 121 |
stop_msg) echo "Stopping the $svc service";;
|
| 122 |
start)
|
| 123 |
if pp_running; then
|
| 124 |
echo "$svc already running";
|
| 125 |
exit 0
|
| 126 |
elif pp_start; then
|
| 127 |
echo "$svc started";
|
| 128 |
# rc(1M) says we should exit 4, but nobody expects it!
|
| 129 |
exit 0
|
| 130 |
else
|
| 131 |
exit 1
|
| 132 |
fi
|
| 133 |
;;
|
| 134 |
stop)
|
| 135 |
if pp_stop; then
|
| 136 |
echo "$svc stopped";
|
| 137 |
exit 0
|
| 138 |
else
|
| 139 |
exit 1
|
| 140 |
fi
|
| 141 |
;;
|
| 142 |
*) echo "usage: $0 {start|stop|start_msg|stop_msg}"
|
| 143 |
exit 1
|
| 144 |
;;
|
| 145 |
esac
|
| 146 |
.
|
| 147 |
}
|
| 148 |
|
| 149 |
pp_kit_make_service () {
|
| 150 |
typeset level priority startlevels stoplevels
|
| 151 |
typeset svc svcvar
|
| 152 |
|
| 153 |
svc="$1"
|
| 154 |
svcvar=`pp_makevar $svc`
|
| 155 |
|
| 156 |
#-- don't do anything if the script exists
|
| 157 |
if test -s "$pp_destdir/sbin/init.d/$svc"; then
|
| 158 |
pp_error "$pp_destdir/sbin/init.d/$svc exists"
|
| 159 |
return
|
| 160 |
fi
|
| 161 |
|
| 162 |
# symlink the script, depending on the priorities chosen
|
| 163 |
eval priority='${pp_kit_priority_'$svcvar'}'
|
| 164 |
test -z "$priority" && priority="${pp_kit_priority:-50}"
|
| 165 |
|
| 166 |
eval startlevels='${pp_kit_startlevels_'$svcvar'}'
|
| 167 |
test -z "$startlevels" && startlevels="$pp_kit_startlevels"
|
| 168 |
|
| 169 |
eval stoplevels='${pp_kit_stoplevels_'$svcvar'}'
|
| 170 |
test -z "$stoplevels" && stoplevels="$pp_kit_stoplevels"
|
| 171 |
|
| 172 |
# create the script and config file
|
| 173 |
pp_kit_service_script $svc
|
| 174 |
|
| 175 |
# fix the priority up
|
| 176 |
case "$priority" in
|
| 177 |
???) :;;
|
| 178 |
??) priority=0$priority;;
|
| 179 |
?) priority=00$priority;;
|
| 180 |
esac
|
| 181 |
|
| 182 |
if test x"$stoplevels" = x"auto"; then
|
| 183 |
stoplevels=
|
| 184 |
test -z "$startlevels" || for level in $startlevels; do
|
| 185 |
stoplevels="$stoplevels `expr $level - 1`"
|
| 186 |
done
|
| 187 |
fi
|
| 188 |
|
| 189 |
# create the symlinks
|
| 190 |
test -z "$startlevels" || for level in $startlevels; do
|
| 191 |
echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%post.run
|
| 192 |
echo " rm /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%preun.run
|
| 193 |
done
|
| 194 |
test -z "$stoplevels" || for level in $stoplevels; do
|
| 195 |
echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%post.run
|
| 196 |
echo " rm -f /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%preun.run
|
| 197 |
done
|
| 198 |
}
|