#!/bin/sh
# Copyright (C) 2004 International Business Machines Corporation and others.
# All Rights Reserved. This program and the accompanying
# materials are made available under the terms of the
# Common Public License v1.0 which accompanies this distribution.
#
# Author: Brian King <brking@us.ibm.com>

service_status(){
	pid=`pidof netatalk` 
	if [ ! -z $pid ]; then
		echo "running"
	else
		echo "stopped"
	fi
}

service_prepare(){
	rm -fr /var/netatalk/
	mkdir -p  /var/netatalk/CNID

	/sbin/svrcfg-all -c afp
}

service_start(){
	service_prepare
	start-stop-daemon --start --make-pidfile -b --pidfile /var/run/netatalk.pid --exec /usr/sbin/netatalk 
}

service_stop(){
	start-stop-daemon --stop --quiet --exec /usr/sbin/netatalk
	rm -rf /var/run/netatalk.pid
}


service_restart(){
	service_stop
	service_start
}

case $1 in
        start)
                service_start
                exit 0 ;;
        stop)
                service_stop
                exit 0 ;;
        restart)
                service_restart
                exit 0 ;;
        status)
                service_status
                exit 0 ;;
        *)
                echo "Usage: `basename $0` {start|stop|restart|status}"
                exit 1 ;;
esac
