HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //proc/thread-self/root/usr/local/lsmcd/bin/lsmcdctrl
#!/bin/sh
#set -x

PROG="$0"
EXECUTABLE=lsmcd
BASE_DIR=`dirname "$PROG"`
if [ $BASE_DIR = '.' ]; then
   BASE_DIR=`pwd`
fi
cd $BASE_DIR
cd ..
BASE_DIR=`pwd`
#BASE_DIR=/usr/local/lsmcd
#BASE_DIR=`pwd`

if [ ! -x "$BASE_DIR"/bin/"$EXECUTABLE" ]; then
    echo "[ERROR] Cannot find $BASE_DIR/$EXECUTABLE"
    exit 1
fi


CONF="$BASE_DIR"/conf/node.conf
DESC="lsmcd"

if [ ! -f $CONF ] ; then
    echo "[ERROR] Cannot find the config $CONF"
    exit 1
fi
LINE=`grep TmpDir $CONF`
if [ "x$LINE" != "x" ]; then
    TMPDIR=`echo  $LINE |cut -d = -f2`    
else
    TMPDIR="/tmp/lsmcd"
fi

PIDFILE=$TMPDIR/lsmcd.pid
if [ ! -d $TMPDIR ]; then
    mkdir $TMPDIR
    if [ $? -ne 0 ]; then
        echo "Temporary directory problem in node.conf"
        exit 1
    fi
fi

RUNNING=0
SYS_NAME=`uname -s`
if [ "x$SYS_NAME" = "xFreeBSD" ] || [ "x$SYS_NAME" = "xDarwin" ] ; then
    PS_CMD="ps -ax"
else
    PS_CMD="ps -ef"
fi

if [ -f $PIDFILE ] ; then
    FPID=`cat $PIDFILE`
    if [ "x$FPID" != "x" ]; then
        PL=`$PS_CMD | grep $EXECUTABLE | grep -v grep | grep -w $FPID`
        if [ "x$PL" != "x" ] ; then
            RUNNING=1
            PID=$FPID
        fi
    fi
fi


ret=0

start()
{
    ret=255
    if [ -f "$PIDFILE" ]; then
        PID=`cat $PIDFILE`
        if [ $? -ne 0 ]; then
            ret=255
            return
        fi
    else
        PID=""
    fi
    if [ ! -f "$CONF" ]; then
        echo "[ERROR] Cannot find the configure file $CONF"
        return 
    fi
    export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
    ASAN_OPTIONS=symbolize=1:debug=true:abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1 "${BASE_DIR}/bin/${EXECUTABLE}" -f $CONF 2>>/tmp/lsmcd.log
    ret=$?

    if [ $ret -eq 0 ]; then
        NEW_PID=`cat $PIDFILE`
        if [ "x$NEW_PID" = "x$PID" ] || [ "x$NEW_PID" = "x" ]; then
            sleep 1
            NEW_PID=`cat $PIDFILE`
        fi
        if [ $? -ne 0 ]; then
            ret=255
            return;
        fi
        sleep 1
        if [ ! -d /proc/$NEW_PID ]; then
            echo "[ERROR] Process terminated after starting"
            ret=255
        else
            echo "[OK] $DESC: pid=$NEW_PID."
        fi

    else
        echo "[ERROR] Failed to start $DESC!"
    fi
}


stop()
{
    kill -TERM $PID
    ret=$?
        if  [ $ret -eq 0 ]; then
        echo "[OK] $DESC: stopped."
    else
        echo "[ERROR] can not kill $DESC"
    fi
}


restart()
{
    if [ $RUNNING -eq 1 ]; then
        kill -USR1 $PID
        ret=$?
        if  [ $ret -ne 0 ]; then
            echo "[ERROR] can not gracefully shutdown $DESC"
        fi
    else
        start
    fi
}

help() {
    echo $"Usage: $PROG {start|stop|restart|status|help}"
    cat <<EOF

start    - start cached daemon 
stop     - stop  cached daemon
restart  - restart (stop then start) cached daemon
status   - show service status
help     - this screen
        
EOF
}

case "$1" in 
    start)
        if [ $RUNNING -eq 1 ]; then
            echo "[ERROR] $DESC is running with pid=$PID."
            ret=1
        else
            start
        fi
        ;;
    stop)
        if [ $RUNNING -eq 1 ]; then
            stop
        else
            echo "[ERROR] $DESC is not running."
            ret=1
        fi
        ;;
    restart)
            restart
        ;;
    status)
        if [ $RUNNING -eq 1 ]; then
            echo "$DESC is running with PID $PID."
        else
            echo "[ERROR] $DESC is not running."
            ret=3
        fi
        ;;
    *)
        help
        ret=3
        ;;
esac
echo "Final rc: " $ret
exit $ret