Source

iredapd / rc_scripts / iredapd.freebsd

Full commit
Zhang Huangbin cc68391 

Zhang Huangbin b8edcd0 
Zhang Huangbin cc68391 








Zhang Huangbin e85694f 
Zhang Huangbin cc68391 























Zhang Huangbin ec166c5 


Zhang Huangbin cc68391 





























































#!/usr/local/bin/bash

# Author: Zhang Huangbin (zhb@iredmail.org)

# PROVIDE: iredapd
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr
name='iredapd'
rcvar=`set_rcvar`

BINPATH='/opt/iredapd/iredapd.py'
pidfile='/var/run/iredapd.pid'

check_status() {
    # Usage: check_status pid_number
    PID="${1}"
    l=$(ps -p ${PID} | wc -l | awk '{print $1}')
    if [ X"$l" == X"2" ]; then
        echo "running"
    else
        echo "stopped"
    fi
}

start() {
    if [ -f ${pidfile} ]; then
        PID="$(cat ${pidfile})"
        s="$(check_status ${PID})"

        if [ X"$s" == X"running" ]; then
            echo "${name} is already running."
        else
            rm -f ${pidfile} >/dev/null 2>&1
        fi
    fi

    echo "Starting ${name} ..."
    /usr/local/bin/python ${BINPATH}
    unset s
}

stop() {
    if [ -f ${pidfile} ]; then
        PID="$(cat ${pidfile})"
        s="$(check_status ${PID})"

        if [ X"$s" == X"running" ]; then
            echo "Stopping ${name} ..."
            kill -9 ${PID}
            if [ X"$?" == X"0" ]; then
                rm -f ${pidfile} >/dev/null 2>&1
            else
                echo -e "\t\t[ FAILED ]"
            fi
        else
            echo "${name} is already stopped."
            rm -f ${pidfile} >/dev/null 2>&1
        fi
    else
        echo "${name} is already stopped."
    fi
    unset s
}

status() {
    if [ -f ${pidfile} ]; then
        PID="$(cat ${pidfile})"
        s="$(check_status ${PID})"

        if [ X"$s" == X"running" ]; then
            echo "${name} is running."
        else
            echo "${name} is stopped."
        fi
    else
        echo "${name} is stopped."
    fi
    unset s
}

empty(){
case "$1" in
    start) start ;;
    stop) stop ;;
    status) status ;;
    restart) stop && start ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        RETVAL=1
        ;;
esac
}

start_cmd="start"
stop_cmd="stop"
status_cmd="status"
restart_cmd="stop && start"

command="start"
load_rc_config ${name}
run_rc_command "$1"