#!/bin/bash
# -*- Mode: shell-script -*-
# Copyright (C) 2003 by MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)
# suspend: 15
# resume: 25

. /etc/sysconfig/suspend

STATE=/var/run/pm/startedservices
ARG=$1

if [[ -z $RESTART_SERVICES ]];then
    exit;
fi

function suspend {
    rm -f $STATE
    for service in $RESTART_SERVICES;do
	if [[ -x /etc/init.d/$service ]];then
            if service $service status 2>/dev/null >/dev/null; then
                echo $service >> $STATE
            fi
	    # Stop it even if the "status" command is broken
	    service $service stop 2>/dev/null >/dev/null
	fi
    done
}

function resume {
    for service in $RESTART_SERVICES;do
        if [[ -f $STATE ]]; then
            if grep -q $service $STATE 2>/dev/null >/dev/null; then
	        service $service start 2>/dev/null >/dev/null
            fi
	fi
    done
}

case $ARG in
    suspend)
	suspend
	;;
    resume)
	resume
	;;
esac
