Last active
December 8, 2019 17:15
-
-
Save pfrenssen/5d722ee6b112a18bc4441def143250d4 to your computer and use it in GitHub Desktop.
Launches ethminer when the display goes to sleep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/systemd/user/launch-ethminer.service | |
[Unit] | |
Description=Launches ethminer when the display goes to sleep. | |
[Service] | |
ExecStart=bash /home/pieter/v/launchminer.sh | |
KillMode=process | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/systemd/user/launch-ethminer.timer | |
# Enable the timer using the following command: | |
# $ systemctl --user enable launch-ethminer.timer | |
[Unit] | |
Description=Check every few seconds if the monitor went to sleep, so we can launch ethminer. | |
[Timer] | |
OnCalendar=*:*:0/2 | |
Persistent=true | |
AccuracySec=1sec | |
[Install] | |
WantedBy=timers.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get information about the X session. | |
XINFO=$(xset -q 2>/dev/null) | |
DATE=$(date) | |
if [ $? -eq 0 ]; then | |
echo $XINFO | grep "Monitor is On" > /dev/null | |
MONITOR_IS_ON=$((1 - $?)) | |
else | |
# X is not running. | |
echo "$DATE X is not running" >> /home/pieter/v/launchminer.log | |
MONITOR_IS_ON=0 | |
fi | |
# If the monitor is switched on, retrieve all running miners and kill them. | |
if [ $MONITOR_IS_ON -eq 1 ]; then | |
for PID in $(pidof ethminer); do | |
echo "$DATE Kill miner $PID" >> /home/pieter/v/launchminer.log | |
kill $PID | |
done | |
# If the monitor is off, check if a miner is running. If not start one. | |
elif [[ ! $(pidof ethminer) ]]; then | |
echo "$DATE Start mining" >> /home/pieter/v/launchminer.log | |
ethminer -U -P stratum1+tcp://9d874d6a172efddcb302d1581213acae8a49c0d8.archsofia@eu1.ethermine.org:4444 & | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment