#!/bin/bash

function stop_pandoranext() {
    # Find the PID of PandoraNext
    pid=$(pgrep -f PandoraNext)

    # Check if the PID was found
    if [ -n "$pid" ]; then
        echo "Stopping PandoraNext running with PID $pid..."
        kill $pid

        # Wait a bit to ensure the process has been terminated
        sleep 2

        # Check if PandoraNext was successfully terminated
        if kill -0 $pid 2>/dev/null; then
            echo "Failed to stop PandoraNext. Trying with force..."
            kill -9 $pid
            sleep 2
        else
            echo "PandoraNext stopped successfully."
        fi
    else
        echo "PandoraNext is not running."
    fi
}

function start_pandoranext() {
    echo "Starting PandoraNext..."
    nohup /home/pandora/PandoraNext > /home/pandora/output.log 2>&1 &

    # Wait a moment to ensure the process has started
    sleep 2

    # Check if PandoraNext started successfully
    new_pid=$(pgrep -f PandoraNext)
    if [ -n "$new_pid" ]; then
        echo "PandoraNext started successfully with PID $new_pid."
        echo "Tailing the last 10 lines of output.log:"
        tail -n 10 /home/pandora/output.log
    else
        echo "Failed to start PandoraNext."
    fi
}

case "$1" in
    stop)
        stop_pandoranext
        ;;
    *)
        stop_pandoranext
        start_pandoranext
        ;;
esac
最后修改:2024 年 05 月 11 日
如果觉得我的文章对你有用,请随意赞赏