#! @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 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 } start_softdeps() { for i in $softdeps $i start RETVAL=$? if test $RETVAL != 0; then continue } start() { # are we already running? # if so, exit with code 0 if test -a $STATDIR/$prog = 1; then exit 0 # if not, continue # launch all hard dependencies start_deps # launch all preferred dependencies start_softdeps # launch our own program } stop() { # are we running? If so, then stop, otherwise, do nothing... if test -a $STATDIR/$prog = 0; then exit 0 # stop our own program } register() { touch $STATEDIR/$prog } unregister() { rm $STATEDIR/$prog }