2006-02-16 19:25:05 +01:00
|
|
|
#! @bash@/bin/sh -e
|
|
|
|
|
|
|
|
## Generic service scripts for NixOS, which provide
|
|
|
|
## * functions to write state to files (/var/run/nix-services)
|
|
|
|
## * functions to read state from file (/var/run/nix-services)
|
|
|
|
## * sanity checking functions
|
|
|
|
|
|
|
|
STATEDIR=/var/run/nix-services
|
2006-02-17 17:29:04 +01:00
|
|
|
RCDIR=/etc/rc.d/
|
|
|
|
|
|
|
|
## resolve $deps to real start/stop scripts first
|
|
|
|
|
|
|
|
start_deps() {
|
2006-03-10 14:32:54 +01:00
|
|
|
for i in $deps; do
|
2006-02-17 17:29:04 +01:00
|
|
|
$i start
|
|
|
|
RETVAL=$?
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
exit $RETVAL
|
2006-03-10 14:32:54 +01:00
|
|
|
fi
|
|
|
|
done
|
2006-02-17 17:29:04 +01:00
|
|
|
}
|
|
|
|
|
2006-03-09 14:20:40 +01:00
|
|
|
start_softdeps() {
|
2006-03-10 14:32:54 +01:00
|
|
|
for i in $softdeps; do
|
2006-03-09 14:20:40 +01:00
|
|
|
$i start
|
|
|
|
RETVAL=$?
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
continue
|
2006-03-10 14:32:54 +01:00
|
|
|
fi
|
|
|
|
done
|
2006-03-09 14:20:40 +01:00
|
|
|
}
|
|
|
|
|
2006-02-17 17:29:04 +01:00
|
|
|
start() {
|
2006-03-09 14:20:40 +01:00
|
|
|
# are we already running?
|
|
|
|
# if so, exit with code 0
|
2006-03-10 14:32:54 +01:00
|
|
|
if test -a $STATDIR/$prog; then
|
2006-03-09 14:20:40 +01:00
|
|
|
exit 0
|
2006-03-10 14:32:54 +01:00
|
|
|
fi
|
2006-03-09 14:20:40 +01:00
|
|
|
# if not, continue
|
2006-02-17 17:29:04 +01:00
|
|
|
# launch all hard dependencies
|
2006-03-10 14:32:54 +01:00
|
|
|
#start_deps
|
2006-02-17 17:29:04 +01:00
|
|
|
# launch all preferred dependencies
|
2006-03-10 14:32:54 +01:00
|
|
|
#start_softdeps
|
2006-03-09 14:20:40 +01:00
|
|
|
# launch our own program
|
2006-03-10 16:05:22 +01:00
|
|
|
startService
|
|
|
|
# if successful, then register
|
|
|
|
register
|
2006-02-17 17:29:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2006-03-10 16:05:22 +01:00
|
|
|
echo "stopping $prog"
|
2006-02-17 17:29:04 +01:00
|
|
|
# are we running? If so, then stop, otherwise, do nothing...
|
2006-03-10 16:05:22 +01:00
|
|
|
if ! test -a $STATEDIR/$prog; then
|
2006-03-09 14:20:40 +01:00
|
|
|
exit 0
|
2006-03-10 14:32:54 +01:00
|
|
|
fi
|
2006-03-09 14:20:40 +01:00
|
|
|
# stop our own program
|
2006-03-10 16:05:22 +01:00
|
|
|
stopService
|
|
|
|
unregister
|
2006-02-17 17:29:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
register() {
|
2006-03-09 14:20:40 +01:00
|
|
|
touch $STATEDIR/$prog
|
2006-02-17 17:29:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unregister() {
|
|
|
|
rm $STATEDIR/$prog
|
|
|
|
}
|
2006-03-10 14:32:54 +01:00
|
|
|
|
|
|
|
status() {
|
|
|
|
# are we running? If so, report
|
2006-03-10 16:05:22 +01:00
|
|
|
if test -a $STATEDIR/$prog; then
|
2006-03-10 14:32:54 +01:00
|
|
|
echo "running"
|
|
|
|
else
|
|
|
|
echo "stopped"
|
|
|
|
fi
|
|
|
|
}
|