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/
|
2006-03-15 16:51:32 +01:00
|
|
|
NIXPKGS=@nixpkgs@
|
2006-02-17 17:29:04 +01:00
|
|
|
|
|
|
|
## resolve $deps to real start/stop scripts first
|
|
|
|
|
|
|
|
start_deps() {
|
2006-03-10 14:32:54 +01:00
|
|
|
for i in $deps; do
|
2006-03-17 17:33:59 +01:00
|
|
|
echo $i
|
2006-03-15 16:51:32 +01:00
|
|
|
name=`$i/control name`
|
2006-03-17 15:16:11 +01:00
|
|
|
|
|
|
|
if ! test -a "$RCDIR/$name"; then
|
|
|
|
echo $RCDIR/$name $i
|
|
|
|
@nix@/bin/nix-env -p $RCDIR/$name -i $i
|
2006-03-15 16:51:32 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
$i/control start
|
2006-03-17 15:16:11 +01:00
|
|
|
|
2006-02-17 17:29:04 +01:00
|
|
|
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-14 14:44:28 +01:00
|
|
|
echo $i
|
2006-03-15 16:51:32 +01:00
|
|
|
|
|
|
|
name=`$i/control name`
|
|
|
|
if ! test -a "$RCDIR/$name"; then
|
|
|
|
echo $RCDIR/$name $i
|
|
|
|
@nix@/bin/nix-env -p $RCDIR/$name -i $i
|
|
|
|
fi
|
|
|
|
|
|
|
|
$i/control start
|
|
|
|
|
2006-03-09 14:20:40 +01:00
|
|
|
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-15 16:51:32 +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
|
|
|
# if not, continue
|
2006-02-17 17:29:04 +01:00
|
|
|
# launch all hard dependencies
|
2006-03-17 15:16:11 +01:00
|
|
|
start_deps
|
2006-03-17 17:33:59 +01:00
|
|
|
|
|
|
|
RETVAL=$?
|
|
|
|
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
echo $prog failed
|
|
|
|
exit $RETVAL
|
|
|
|
fi
|
|
|
|
|
2006-02-17 17:29:04 +01:00
|
|
|
# launch all preferred dependencies
|
2006-03-14 14:44:28 +01:00
|
|
|
echo "softdeps" $softdeps
|
|
|
|
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
|
2006-03-17 17:33:59 +01:00
|
|
|
|
|
|
|
RETVAL=$?
|
|
|
|
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
echo $prog failed
|
|
|
|
exit $RETVAL
|
|
|
|
fi
|
|
|
|
|
2006-03-10 16:05:22 +01:00
|
|
|
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
|
2006-03-17 17:33:59 +01:00
|
|
|
echo "unregistering"
|
2006-03-10 16:05:22 +01:00
|
|
|
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
|
|
|
|
}
|
2006-03-15 14:47:03 +01:00
|
|
|
|
|
|
|
name() {
|
|
|
|
echo $prog
|
|
|
|
}
|