#!/bin/sh
###############################################################################
# $Id: edac.init.in 76 2008-02-08 22:57:23Z grondo $
###############################################################################
# Copyright (C) 2006-2007 The Regents of the University of California.
# Produced at Lawrence Livermore National Laboratory.
# Written by Mark Grondona <mgrondona@llnl.gov>
# UCRL-CODE-230739.
# Modified by Yaroslav Halchenko <debian@onerussian.com> 2007 for Debian OS
###############################################################################
# chkconfig:      345 40 60
###############################################################################
### BEGIN INIT INFO
# Provides:       edac
# Required-Start: $local_fs $named $time
# Required-Stop: $local_fs $named $time
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: Initialize EDAC
# Description:    Initialize EDAC: load DIMM labels into EDAC
### END INIT INFO
###############################################################################

unset SERVICE

SERVICE="edac"
DESC="Memory Error Detection and Correction"
prefix="/usr"
exec_prefix="${prefix}"
sbindir="${exec_prefix}/sbin"
sysconfdir="/etc"

PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
STATUS=0

###############################################################################

# Read configuration to see if we need to load 
#  EDAC_DRIVER 
# 
for dir in "$sysconfdir/default" "$sysconfdir/sysconfig"; do
  [ -f "$dir/$SERVICE" ] && . "$dir/$SERVICE"
done


###############################################################################

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
. /lib/lsb/init-functions

###############################################################################

service_start ()
{
# Start the service.  Required by LSB.
#
  [ -n "$EDAC_DRIVER" ] || return 0
  modprobe $EDAC_DRIVER
  rc=$?
  case $rc in
    0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    5) log_failure_msg ": No EDAC support for this hardware"; log_end_msg 1 ;;
    *) log_failure_msg ": Unknown return code $rc. Please file a bug report"; log_end_msg 1;;
  esac
}

service_stop ()
{
  # Stop the service -- unload the module
  [ -n "$EDAC_DRIVER" ] || return 0
  modprobe -r $EDAC_DRIVER
  return $?
}

###############################################################################

service_status ()
{
# Print the current status of the service.  Required by LSB.
#
  log_daemon_msg "Status of $DESC"
  $EDAC --status
  rc=0
}

###############################################################################

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Loading drivers for $DESC" "${SERVICE} "
    service_start
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Unloading drivers for $DESC" "${SERVICE} "
    service_stop
    ;;
  status)
    service_status
    ;;
  restart|force-reload)
    log_daemon_msg "Forcing reload of drivers for $DESC" "${SERVICE}"
    service_stop  || log_end_msg 1
    service_start && log_end_msg 0 || log_end_msg 1

    ;;
  *)
    COMMANDS="{start|stop|status|restart|force-reload}"
    echo "Usage: $0 ${COMMANDS}" >&2
    exit 3
    ;;
esac

:
