-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
289 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] ]]; then #check for symlink | ||
echo "Linking [email protected]" | ||
rm /lib/systemd/system/[email protected] > /dev/null 2>&1 | ||
ln -sf /hive/etc/[email protected] /lib/systemd/system/[email protected] | ||
fi | ||
|
||
if [[ ! -L /lib/systemd/system/[email protected] ]]; then #check for symlink | ||
echo "Linking [email protected]" | ||
rm /lib/systemd/system/[email protected] > /dev/null 2>&1 | ||
ln -sf /hive/etc/[email protected] /lib/systemd/system/[email protected] | ||
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |