diff --git a/hive/bin/ethminer b/hive/bin/ethminer index d4a51a328..a28c7e3fe 100755 --- a/hive/bin/ethminer +++ b/hive/bin/ethminer @@ -65,10 +65,11 @@ function config_gen() { fi - - [[ ! -z $ETHMINER_USER_CONFIG ]] && echo "$ETHMINER_USER_CONFIG" >> $MINER_CONFIG + #remove deprecated option + sed -i '/--stratum-protocol/d' $MINER_CONFIG + #replace tpl values in whole file [[ -z $EWAL && -z $ZWAL && -z $DWAL ]] && echo -e "${RED}No WAL address is set${NOCOLOR}" [[ ! -z $EWAL ]] && sed -i "s/%EWAL%/$EWAL/g" $MINER_CONFIG #|| echo -e "${RED}EWAL not set${NOCOLOR}" diff --git a/hive/bin/telec b/hive/bin/telec new file mode 100755 index 000000000..8527fbe78 --- /dev/null +++ b/hive/bin/telec @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +# Teleconsole control script + + +MAX_TELEC_IDLE=3600 + +. colors + + + + +if [[ ! -e /usr/local/bin/teleconsole ]]; then + echo "${CYAN}> Installing Teleconsole${NOCOLOR}" + curl https://www.teleconsole.com/get.sh | sh +fi + + +#man logfile for teleconsole screen output +logfile=/run/hive/teleconsole.1 + +start () { + screen -ls teleconsole | grep -q teleconsole && running=1 || running=0 + + [[ $running -eq 1 ]] && + echo -e "${YELLOW}Teleconsole session already running${NOCOLOR}" && + exit 1 + + + #[[ -e $logfile ]] && rm $logfile + [[ `ls -l /run/hive/teleconsole.* | wc -l` -ne 0 ]] && rm /run/hive/teleconsole.* + + screen -dm -c /hive/etc/screenrc.teleconsole + sleep 0.2 + + for i in {1..30}; do # wait console init + #^MYour Teleconsole ID: ^[[1meu97a28a596ce613ee679c714437899da9ae326e21^[[0m^M + buf=`cat $logfile | grep -m1 "Your Teleconsole ID: "` + if [[ ! -z $buf ]]; then + buf=$(sed "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g" <<< "$buf") #sed removes colors + sessid=$(awk '{print $NF}' <<< "$buf") + [[ -z $sessid ]] && continue #just in case + echo -e "${CYAN}TELECONSOLE${NOCOLOR} ${GREEN}$sessid${NOCOLOR}" + echo "" + #now what?)))) we've just checked that there is a session id in log file + + #cat $logfile | sed -e 's/\[1m/\[32m/' #replace id to green + cat $logfile + + exit 0 + fi + + sleep 0.5 + done + + cat $logfile + echo -e "${YELLOW}Unable to start Teleconsole session${NOCOLOR}" +} + +stop () { + screen -S teleconsole -X quit + [[ $? -eq 0 ]] && + echo -e "${YELLOW}Teleconsole session closed${NOCOLOR}" +} + +open () { + screen -r -S teleconsole +} + + +#The idea is to watch for file mtime or size and kill idle session +killidle () { + echo "Watching for teleconsole idle" + sleep 5 + + while true; do + sleep 60 + + mtime=`stat -c %Y $logfile` + + now=`date +%s` + elapsed=$(($now - $mtime)) + echo "idle for $elapsed seconds" + + if [[ $elapsed -ge $MAX_TELEC_IDLE ]]; then + echo -e "${YELLOW}Stopping teleconsole, idle more than $MAX_TELEC_IDLE seconds" + stop + exit 0 + fi + done +} + + + +case $1 in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + open) + open + ;; + killidle) + killidle + ;; + log) #miner log 2 //can be 2 for other miner, log from miner.1 or miner.2!!! + cat $logfile + ;; + *) + screen -ls teleconsole | grep -q teleconsole && running=1 || running=0 + + [[ $running -eq 1 ]] && + echo -e "${GREEN}Teleconsole session running${NOCOLOR}" || + echo -e "${YELLOW}Teleconsole session is not running${NOCOLOR}" + + echo -e "Usage: ${CYAN}telec start|stop|log|open${NOCOLOR}" + ;; +esac \ No newline at end of file diff --git a/hive/etc/apt/postinst b/hive/etc/apt/postinst new file mode 100755 index 000000000..2d434b224 --- /dev/null +++ b/hive/etc/apt/postinst @@ -0,0 +1,148 @@ +#!/usr/bin/env bash + +# Post installation script for deb package + +mkdir -p /run/hive + +chown -R user:user /hive +chown -R root:root /hive/etc/logrotate.d/* #or the rules will not work + +#just to ensure log is preserved between boots +mkdir -p /var/log/journal + + +miner logdirscreate + +#can be fat partition, no more messages +#chown -R user:user /hive-config > /dev/null + + +#Environment + +[[ ! -L /etc/environment && -e /hive/etc/environment ]] && #it's not a symlink + echo "Linking /etc/environment" && + mv -f /etc/environment /etc/environment~ && + ln -sf /hive/etc/environment /etc/environment + + + +#Services + +[[ ! -f /lib/systemd/system/hive.service ]] && + echo "Linking and enabling hive service" && + ln -s /hive/etc/hive.service /lib/systemd/system/hive.service && + systemctl enable hive + +[[ ! -f /lib/systemd/system/hivex.service ]] && + echo "Linking hivex service" && + ln -s /hive/etc/hivex.service /lib/systemd/system/hivex.service + +[[ ! -f /lib/systemd/system/hive-console.service ]] && + echo "Linking hive-console service" && + ln -s /hive/etc/hive-console.service /lib/systemd/system/hive-console.service + +[[ ! -f /lib/systemd/system/hive-watchdog.service ]] && + echo "Linking hive-watchdog service" && + ln -s /hive/etc/hive-watchdog.service /lib/systemd/system/hive-watchdog.service + +if [[ ! -L /lib/systemd/system/systemd-networkd-wait-online.service ]]; then #check for symlink + echo "Linking systemd-networkd-wait-online.service" + rm /lib/systemd/system/systemd-networkd-wait-online.service > /dev/null 2>&1 + ln -sf /hive/etc/systemd-networkd-wait-online.service /lib/systemd/system/systemd-networkd-wait-online.service +fi + +if [[ ! -L /lib/systemd/system/wpa_supplicant@wlan0.service ]]; then #check for symlink + echo "Linking wpa_supplicant@wlan0.service" + rm /lib/systemd/system/wpa_supplicant@wlan0.service > /dev/null 2>&1 + ln -sf /hive/etc/wpa_supplicant@wlan0.service /lib/systemd/system/wpa_supplicant@wlan0.service +fi + +if [[ ! -L /lib/systemd/system/wpa_supplicant@ra0.service ]]; then #check for symlink + echo "Linking wpa_supplicant@ra0.service" + rm /lib/systemd/system/wpa_supplicant@ra0.service > /dev/null 2>&1 + ln -sf /hive/etc/wpa_supplicant@wlan0.service /lib/systemd/system/wpa_supplicant@ra0.service +fi + + + +#Cron + +#remove system, use our own cron +[[ -f /etc/cron.hourly/logrotate ]] && + echo "Removing /etc/cron.hourly/logrotate" && + rm /etc/cron.hourly/logrotate + +[[ -f /etc/cron.daily/logrotate ]] && + echo "Removing /etc/cron.daily/logrotate" && + rm /etc/cron.daily/logrotate + +[[ ! -f /etc/logrotate.d/hive ]] && + echo "Linking hive logrotate" && + ln -sf /hive/etc/logrotate.d/hive /etc/logrotate.d/hive + +[[ ! -L /etc/logrotate.d/rsyslog ]] && #check for symlink + echo "Linking rsyslog config" && + rm /etc/logrotate.d/rsyslog && + ln -sf /hive/etc/logrotate.d/rsyslog /etc/logrotate.d/rsyslog + +crontab /hive/etc/crontab.root + +systemctl restart cron.service + +#if [[ ! -f /etc/cron.hourly/logrotate ]]; then +# if [[ -f /etc/cron.daily/logrotate ]]; then +# echo "Moving /etc/cron.daily/logrotate to /etc/cron.hourly/logrotate" +# mv /etc/cron.daily/logrotate /etc/cron.hourly/logrotate +# #service cron restart +# systemctl restart cron.service +# /etc/cron.hourly/logrotate +# else +# echo "WARNING: /etc/cron.daily/logrotate does not exist" +# fi +#fi + + +#MEMORY ALLOC FAILED: mlock failed for xmr-stak-cpu miner +cat /etc/sysctl.conf | grep -q "vm.nr_hugepages"; [[ $? -eq 1 ]] && (echo "vm.nr_hugepages = 128" >> /etc/sysctl.conf && sysctl -w vm.nr_hugepages=128) +#cat /etc/security/limits.conf | grep -q "* soft memlock 262144"; [[ $? -eq 1 ]] && echo "* soft memlock 262144" >> /etc/security/limits.conf +#cat /etc/security/limits.conf | grep -q "* hard memlock 262144"; [[ $? -eq 1 ]] && echo "* hard memlock 262144" >> /etc/security/limits.conf + + +# USB drive optimizations +cat /etc/fstab | grep "^UUID=2158442c-b245-4f6d-941b-ced5f3d3a427" | grep -q "noatime,commit=120" +[[ $? -eq 1 ]] && #not found + echo "Setting \"noatime,commit=120\" as root FS mount options" && + sed -i 's/^UUID=2158442c-b245-4f6d-941b-ced5f3d3a427.*/UUID=2158442c-b245-4f6d-941b-ced5f3d3a427 \/ ext4 errors=remount-ro,noatime,commit=120 0 1/g' /etc/fstab + +#Config directory setup ----------------------------------------------------- + +[[ ! -d /hive-config ]] && mkdir -p -m 777 /hive-config + +cp -r --no-clobber /hive/etc/hive-config.stub/* /hive-config/ + + + + +#Teleconsole env check ----------------------------------------------------- +cat /root/.bashrc | grep -qE '^# Teleconsole required start' || +(echo "Adding environment to /root/.bashrc for Teleconsole"; +echo -e "\n\n# Teleconsole required start +source /etc/environment +export PATH +export CUDA_DEVICE_ORDER +# Teleconsole required end" >> /root/.bashrc) + + + + + +#will be created from stub +#[[ ! -e /hive-config/vnc-password.txt ]] && +# cp hive/etc/hive-config.stub/vnc-password.txt /hive-config/vnc-password.txt + + +#Moved to selfupgrade +#hello +#miner restart + +exit 0 \ No newline at end of file diff --git a/hive/etc/screenrc.teleconsole b/hive/etc/screenrc.teleconsole new file mode 100644 index 000000000..e92bb0faa --- /dev/null +++ b/hive/etc/screenrc.teleconsole @@ -0,0 +1,15 @@ +sessionname teleconsole + +hardstatus alwayslastline +#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]' +hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}[ %{W}%t%?(%u)%?%{r} ]%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]' + +deflog on +logfile /run/hive/teleconsole.%n +logfile flush 1 +logtstamp off +#logtstamp after 122 + + +screen -t killidle telec killidle +screen -t teleconsole bash -i -c 'teleconsole; telec stop'