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() {
|
|
|
|
for i in $deps
|
|
|
|
$i start
|
|
|
|
RETVAL=$?
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
exit $RETVAL
|
|
|
|
}
|
|
|
|
|
2006-03-09 14:20:40 +01:00
|
|
|
start_softdeps() {
|
|
|
|
for i in $softdeps
|
|
|
|
$i start
|
|
|
|
RETVAL=$?
|
|
|
|
if test $RETVAL != 0; then
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if test -a $STATDIR/$prog = 1; then
|
|
|
|
exit 0
|
|
|
|
# if not, continue
|
2006-02-17 17:29:04 +01:00
|
|
|
# launch all hard dependencies
|
|
|
|
start_deps
|
|
|
|
# launch all preferred dependencies
|
2006-03-09 14:20:40 +01:00
|
|
|
start_softdeps
|
|
|
|
# launch our own program
|
2006-02-17 17:29:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
# are we running? If so, then stop, otherwise, do nothing...
|
2006-03-09 14:20:40 +01:00
|
|
|
if test -a $STATDIR/$prog = 0; then
|
|
|
|
exit 0
|
|
|
|
# stop our own program
|
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
|
|
|
|
}
|