#!/bin/sh
# /etc/init.d/slim: Start, stop and restart Slim daemon on SliTaz, at boot
# time or with the command line.
#
# To start daemon at boot time, just put the right name in the $RUN_DAEMONS
# variable of /etc/rcS.conf and configure options with /etc/slim.conf.
#
. /etc/init.d/rc.functions

NAME=SLiM
DESC="$(_ 'Simple login manager')"
DAEMON=/usr/bin/slim
OPTION="-d"
LOCK_FILE=/var/lock/slim.lock

case "$1" in
  start)
    if active_pidfile $LOCK_FILE slim ; then
      _ '%s is already running.' $NAME
      exit 1
    fi
    action 'Starting %s: %s...' "$DESC" $NAME
    $DAEMON $OPTION
    status
    ;;
  stop)
    if ! active_pidfile $LOCK_FILE slim ; then
      _ '%s is not running.' $NAME
      exit 1
    fi
    action 'Stopping %s: %s...' "$DESC" $NAME
    killall slim
    rm $LOCK_FILE
    status
    ;;
  restart)
    if ! active_pidfile $LOCK_FILE slim ; then
      _ '%s is not running.' $NAME
      exit 1
    fi
    action 'Restarting %s: %s...' "$DESC" $NAME
    killall slim
    rm $LOCK_FILE
    sleep 2
    $DAEMON $OPTION
    status
    ;;
  *)
    emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
    newline
    exit 1
    ;;
esac

exit 0
