asterisk_status() {
    local pid
    local rc

    if [ ! -f $ASTRUNDIR/asterisk.pid ]; then
        ocf_log info "Asterisk PBX is not running"
        return $OCF_NOT_RUNNING
    fi

    pid=`cat $ASTRUNDIR/asterisk.pid`
    ocf_run kill -s 0 $pid
    rc=$?

    if [ $rc -eq 0 ]; then
        if ocf_is_true "$OCF_RESKEY_realtime"; then
            astcanary_pid=`pgrep -d " " -f "astcanary $ASTRUNDIR/alt.asterisk.canary.tweet.tweet.tweet"`
            if [ ! "$astcanary_pid" ]; then
                ocf_log err "Asterisk PBX is running but astcanary is not although it should"
                return $OCF_ERR_GENERIC
            fi
        else
            return $OCF_SUCCESS
        fi
    else
        ocf_log info "Asterisk PBX not running: removing old PID file"
        rm -f $ASTRUNDIR/asterisk.pid
        return $OCF_NOT_RUNNING
    fi
}
