刘明野

ksa启动脚本备份 init.d

看雪安全接入 Kanxue Security Access

PROG 执行文件名

PROG_PATH 执行文件所在目录

#!/bin/bash
# chkconfig: 2345 56 26
# description: KSA Service

### BEGIN INIT INFO
# Provides: ksa
# Required-Start: $all
# Required-Stop: $all
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop KSA
### END INIT INFO

PROG="ksa_arm64"
PROG_PATH="/usr/local/KSA_linux"
PIDFILE="/var/run/ksa_arm64.pid"

start() {
    if [ -f "$PIDFILE" ]; then
        ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
        if [ $? -ne "0" ]; then
            echo KSA is not running, buy pid file is exits ${PIDFILE}
            exit 1
        else
            echo "KSA is running! ($(cat ${PIDFILE}))"
            exit 0
        fi
    fi
    echo "Starting KSA server..."
    $PROG_PATH/$PROG 2>&1 >/var/log/$PROG &
    sleep 5
    pid=$(ps x | grep $PROG | grep -v grep | awk '{print $1}')
    echo $pid > "$PIDFILE"
    echo "Starting KSA success!"
}
stop() {
    echo "Stopping ..."
    # 方法一
    pid=$(cat $PIDFILE)
    sleep 1
    pkill -9 $pid
    sleep 1
    # 方法二
    pid=$(ps x | grep $PROG | grep -v grep | awk '{print $1}')
    sleep 1
    pkill -9 $pid
    sleep 1
    # 删除临时文件
    rm -f "$PIDFILE"
    rm -f "$PROG_PATH/ksa.log"
    echo "KSA stopped"
}
## Check to see if we are running as root first.
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root" 1>&2
    exit 1
fi
case "$1" in
    start)
        stop
        sleep 3
        start
        exit 0
    ;;
    stop)
        stop
        exit 0
    ;;
    reload|restart|force-reload)
        stop
        sleep 1
        start
        exit 0
    ;;
    **)
        echo "Usage: $0 {start|stop|reload}" 1>&2
        exit 1
    ;;
esac
本文为作者刘明野发布,未经允许禁止转载!
484
0
0
发表留言

友情链接