#!/bin/sh
#
# N.B. This must use a limited subset of shell commands, since it must
#      work on the compute node's smallish shell, currently busybox "ash".
#
### BEGIN INIT INFO
# Provides:       alps
# Required-Start: $remote_fs $syslog $network $named $netdaemons $hugetlbfs
# Required-Stop:  $remote_fs $syslog $network $named $netdaemons $hugetlbfs
# Default-Start:  3
# Default-Stop:   0 1 2 5 6
# Description:    Create needed ALPS directories; apinit started by RCA
### END INIT INFO

APINIT_PATH=/usr/sbin/apinit
LOGDIR=/var/log/alps
RUNDIR=/var/run/apinit
SPOOLDIR=/var/spool/alps        # This path must agree with ALPS header file

. /etc/rc.status
rc_reset

case "$1" in
  start)
	echo -n "Creating alps directories"
	if [ ! -d $LOGDIR ]; then
		mkdir -p -m 755 $LOGDIR
	fi
	if [ ! -d $RUNDIR ]; then
		mkdir -p -m 755 $RUNDIR
	fi
	if [ ! -d $SPOOLDIR ]; then
		mkdir -p -m 755 $SPOOLDIR
	fi
	if [ ! -d /dev/shm/alps ]; then
		mkdir -p -m 755 /dev/shm/alps
	fi
	mount --bind /dev/shm/alps $SPOOLDIR
	MOUNT_RETURN=$?
	if [ $MOUNT_RETURN -gt 0 ]; then
		echo "$0:  Unable to mount $SPOOLDIR -- error: $MOUNT_RETURN"
		rc_failed
		rc_status -v
		exit 5
	fi
	rc_status -v
	;;

  stop)
	echo -n "Unmounting alps spool directory"
	umount $SPOOLDIR
	rc_status -v
	;;

  status)
	echo -n "Checking for service alps"
	checkproc $APINIT_PATH
	rc_status -v
	;;

  *)
	echo $"Usage: $0 {start|stop|status}"
	exit 1
esac

rc_exit
