Skip to content

Instantly share code, notes, and snippets.

@allekmott
Last active July 21, 2017 21:02
Show Gist options
  • Save allekmott/3f2eb68f51a5e98ee1e7 to your computer and use it in GitHub Desktop.
Save allekmott/3f2eb68f51a5e98ee1e7 to your computer and use it in GitHub Desktop.
MineHelper

MineHelper

Shell script CudaMiner helper. Hopes to provide simplicity of initializing mining jobs and monitoring them across different machines.

Support

  • Works flawlessly with GTX 660Ti Reference
  • No dual-GPU support yet; if demanded, will supply
  • Please feel free to comment on this script; more will be added above as the community reports results

Setup

Dependencies

  • Some flavor of Linux
  • For this script to have utility, you'll want cbuchner1/CudaMiner and/or pooler/cpuminer built somewhere on your system
  • For GPU fan control, you'll want nvidia-settings installed as well as Option "Coolbits" "5" set in the Device section of your xorg.conf.
    • To configure Option "Coolbits" "5", you'll need to open /etc/X11/xorg.conf in a text editor (done with administrative privileges).
    • In the file, find the line Section "Device"
    • Place Option "Coolbits" "5" on its own line somewhere within that section
    • Save and relog

Configuration

  • The value of GPUMINE_EXE should be set to the name of the program you intend to use to mine using your GPU.
    • For CudaMiner, this would be set to cudaminer.
    • For ccminer, this would be set to ccminer.
  • The value of GPUMINE_DIR should be set to the path of the folder containing your gpu mining program.
    • This path should be absolute if you wish to run the script from any directory
    • GPUMINE_OPTS should then be set to the arguments you wish to provide the mining program
  • The value of CPUMINE_EXE should be set to the name of the program you intend on using to mine using your CPU.
    • For cpuminer, this would be set to minerd
  • The value of CPUMINE_DIR should be set to the path of the folder containing your cpu mining program.
    • This path should be absolute if you wish to run the script from any directory
    • CPUMINE_OPTS should then be set to the arguments you wish to provide the mining program
  • The values of GPU_LOG and CPU_LOG should be set to the corresponding paths of the log files you want the miner execrable to dump their output to
  • If you wish to fix your GPU's fan speed, you may want to set a different default fan speed, as defined by DEFAULT_FAN_SPEED (speeds quantified in % of max speed)
    • It is NOT recommended to set DEFAULT_FAN_SPEED if mining.

Commands

  • ./minehelper.sh start_gpu - Starts up gpu mining program, sends it to the background, and redirects its output to GPU_LOG
  • ./minehelper.sh start_cpu - Starts up cpu mining program, sends it to the background, and redirects its output to CPU_LOG
  • ./minehelper.sh start_both - Starts up both cpu and gpu mining programs, sends them to the background, and redirects their outputs to their corresponding logs (GPU_LOG and CPU_LOG)
  • ./minehelper.sh stop_gpu - Stops gpu mining program
  • ./minehelper.sh stop_cpu - Stops cpu mining program
  • ./minehelper.sh stop_both - Stops both cpu and gpu mining programs
  • ./minehelper.sh set_fan <fan_speed> - Sets GPU fan speed to the provided fan speed, or DEFAULT_FAN_SPEED if no argument is provided
    • Fan speeds are quantified in % of max speed
    • It is NOT recommended to set fan speed below 50 while mining
    • Will ONLY work if run in X11-based GUI (pretty much anything nvidia-settings can run in) and with Option "Coolbits" "5" set (see Dependencies)
  • ./minehelper.sh release_fan - Releases fan control back to the GPU (what it was before set)
    • Will ONLY work if run in X11-based GUI (pretty much anything nvidia-settings can run in) and with Option "Coolbits" "5" set (see Dependencies)
  • ./minehelper.sh help - Displays a simplified version of this subsection

Example Run

  • Start both miners
    • ./minehelper.sh start_both
  • Kick up fan
    • ./minehelper.sh set_fan 70
  • Gotta build software, time to free up CPU
    • ./minehelper.sh stop_cpu
  • Ok, builds finished = time to mine, CPU!
    • ./minehelper.sh start_cpu
  • Got some noise complaints
    • ./minehelper.sh release_fan
  • How many shares so far?
    • GPU?
    • tail gpuminer.log
    • CPU?
    • tail cpuminer.log
  • OK, time to wind down
    • ./minehelper.sh stop_both

Licensing

The MIT License (MIT)

Copyright (c) 2014 Allek Mott

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#!/bin/bash
# minehelper.sh
# Created: 10 May 2014
# Name of gpu mining executable
#
# Example setting:
# GPUMINE_EXE="cudaminer"
GPUMINE_EXE=""
# Directory containing gpu mining executable
#
# Example setting:
# GPUMINE_DIR="/home/user/CudaMiner"
GPUMINE_DIR=""
# Your opts for gpu mining executable
#
# Example setting:
# GPUMINE_OPTS="-o stratum+tcp://examplepool.com:3339 -u worker.machine -p worker-password"
GPUMINE_OPTS=""
# Name of the cpu mining executable
#
# Example setting:
# CPUMINE_EXE="minerd"
CPUMINE_EXE=""
# Directory containing cpu mining executable
#
# Example setting:
# CPUMINE_DIR="/home/user/cpuminer"
CPUMINE_DIR=""
# Your opts for cpu mining executable
#
# Example setting:
# CPUMINE_OPTS="-o stratum+tcp://examplepool.com:3339 -u worker.machine -p worker-password"
CPUMINE_OPTS=""
# Path to gpu mining log
#
# Example setting:
# GPU_LOG="/home/user/cudaminer.log"
GPU_LOG=""
# Path to cpu mining log
#
# Example setting:
# CPU_LOG="/home/user/cpuminer.log"
CPU_LOG=""
# Default fixed GPU fan speed
DEFAULT_FAN_SPEED=60
function usage() {
echo "Usage: $0 [args]"
echo "Run $0 help for more info."
}
function check_fan_success() {
if [ $? -eq 0 ]; then
echo "All good!"
echo
else
echo "Um yeah. That didn't work..."
echo "Fan control functions only work when running a GUI."
echo "See README for more information."
exit
fi
}
function set_fan() {
echo "Setting GPU fan speed..."
FAN_SPEED=$DEFAULT_FAN_SPEED
if [ $# -gt 0 ]; then
FAN_SPEED=$1
fi
nvidia-settings -a "[gpu:0]/GPUFanControlState=1" \
-a "[fan:0]/GPUCurrentFanSpeed=$FAN_SPEED"
check_fan_success
echo "Fan speed set to $FAN_SPEED."
}
function release_fan() {
echo "Releasing GPU fan..."
nvidia-settings -a "[gpu:0]/GPUFanControlState=0"
check_fan_success
echo "Fan released."
}
function start_both() {
echo "Initializing miners..."
start_gpu
start_cpu
}
function start_gpu() {
echo "Killing currently running instances of $GPUMINE_EXE"
stop_gpu
echo Starting GPU miner...
cd $GPUMINE_DIR
echo "
------------------------------------------------------------------------------
New Session $(date)
------------------------------------------------------------------------------" >> $GPU_LOG
./$GPUMINE_EXE $GPUMINE_OPTS >> $GPU_LOG 2>&1 &
check_success
}
function check_success() {
if [ $? -eq 0 ]; then
echo "All good!"
echo ""
else
echo "Uh, yeah. That didn't work..."
exit
fi
}
function start_cpu() {
echo "Killing currently running instances of $CPUMINE_EXE"
stop_cpu
echo "Starting CPU miner..."
# cpuminer
cd $CPUMINE_DIR
echo "
------------------------------------------------------------------------------
New Session $(date)
------------------------------------------------------------------------------" >> $CPU_LOG
./$CPUMINE_EXE $CPUMINE_OPTS >> $CPU_LOG 2>&1 &
check_success
}
function stop_gpu() {
echo "Running 'killall $GPUMINE_EXE'"
killall $GPUMINE_EXE
echo "Stopped" >> $GPU_LOG
}
function stop_cpu() {
echo "Running 'killall $CPUMINE_EXE'"
killall $CPUMINE_EXE
echo "Stopped" >> $CPU_LOG
}
function show_help() {
echo "Miner helper commands:"
echo
echo " start_gpu Start GPU Miner (path provided by GPUMINE_DIR)"
echo " start_cpu Start CPU Miner (path provided by CPUMINE_DIR)"
echo " start_both Start both CPU and GPU miners"
echo " stop_gpu Stop GPU miner"
echo " stop_cpu Stop CPU miner"
echo " stop_both Stop both CPU and GPU miners"
echo " set_fan <speed> Set GPU fan speed to provided % val (See README)"
echo " release_fan Restore default fan curve (no more static speed, see README)."
echo " help What you just used"
}
if [ $# -gt 0 ]; then
if [ "$1" = "start_gpu" ]; then
start_gpu
elif [ "$1" = "start_cpu" ]; then
start_cpu
elif [ "$1" = "stop_gpu" ]; then
stop_gpu
elif [ "$1" = "stop_cpu" ]; then
stop_cpu
elif [ "$1" = "stop_both" ]; then
stop_gpu
stop_cpu
elif [ "$1" = "set_fan" ]; then
if [ $# -gt 1 ]; then
set_fan $2
else
set_fan
fi
elif [ "$1" = "release_fan" ]; then
release_fan
elif [ "$1" = "start_both" ]; then
start_both
elif [ "$1" = "help" ]; then
show_help
else
usage
fi
else
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment