#!/bin/sh
#
# fdfs_trackerd - FastDFS tracker
#
# chkconfig: - 85 15
# description: <description, split multiple lines with \
#              a backslash>
# http://fedoraproject.org/wiki/FCNewInit/Initscripts
### BEGIN INIT INFO
# Provides:fdfs_trackerd
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description:
# Description:
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/bin/fdfs_trackerd"
prog=${exec##*/}
conffile=/etc/fdfs/tracker.conf
pidfile=/var/run/$prog.pid
lockfile=/var/lock/subsys/$prog

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

create_pidfile(){
    pid=`pidof $prog`
    echo $pid > $pidfile
}

remove_pidfile(){
    [ -e $pidfile ] && rm -rf $pidfile
}

start() {
    echo -n $"Starting $prog: "
    daemon $exec $conffile
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile &&  create_pidfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile && remove_pidfile
    return $retval
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    status)
        status $prog
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 2
esac
