Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatibility fix for CentOS 7.x platform and nmap-ncat issues. #37

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 23 additions & 21 deletions lib/dashman_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ _check_dependencies() {

# make sure we have the right netcat version (-4,-6 flags)
if [ ! -z "$(which nc)" ]; then
(nc -z -4 8.8.8.8 53 2>&1) >/dev/null
(nc -4 8.8.8.8 53 2>&1) </dev/null >/dev/null
if [ $? -gt 0 ]; then
MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES}netcat6 "
fi
Expand Down Expand Up @@ -358,7 +358,7 @@ restart_dashd(){

if [ $DASHD_RUNNING == 1 ]; then
pending " --> ${messages["stopping"]} dashd. ${messages["please_wait"]}"
$DASH_CLI stop 2>&1 >/dev/null
$DASH_CLI stop 2>/dev/null >/dev/null
sleep 10
killall -9 dashd dash-shutoff 2>/dev/null
ok "${messages["done"]}"
Expand All @@ -373,7 +373,7 @@ restart_dashd(){
ok "${messages["done"]}"

pending " --> ${messages["starting_dashd"]}"
$INSTALL_DIR/dashd 2>&1 >/dev/null
$INSTALL_DIR/dashd 2>/dev/null >/dev/null
DASHD_RUNNING=1
ok "${messages["done"]}"

Expand All @@ -399,7 +399,6 @@ restart_dashd(){
update_dashd(){

if [ $LATEST_VERSION != $CURRENT_VERSION ] || [ ! -z "$REINSTALL" ] ; then


if [ ! -z "$REINSTALL" ];then
echo -e ""
Expand Down Expand Up @@ -470,7 +469,7 @@ update_dashd(){

if [ $DASHD_RUNNING == 1 ]; then
pending " --> ${messages["stopping"]} dashd. ${messages["please_wait"]}"
$DASH_CLI stop >/dev/null 2>&1
$DASH_CLI stop 2>/dev/null >/dev/null
sleep 15
killall -9 dashd dash-shutoff >/dev/null 2>&1
ok "${messages["done"]}"
Expand Down Expand Up @@ -554,15 +553,15 @@ update_dashd(){

pending " --> updating sentinel... "
cd sentinel
git remote update >/dev/null 2>&1
git remote update >/dev/null 2>&1
git reset -q --hard origin/master
cd ..
ok "${messages["done"]}"

# patch it -----------------------------------------------------------

pending " --> updating crontab... "
(crontab -l 2>/dev/null | grep -v sentinel.py ; echo "* * * * * cd $INSTALL_DIR/sentinel && venv/bin/python bin/sentinel.py 2>&1 >> sentinel-cron.log") | crontab -
(crontab -l 2>/dev/null | grep -v sentinel.py ; echo "* * * * * cd $INSTALL_DIR/sentinel && venv/bin/python bin/sentinel.py >> sentinel-cron.log 2>&1") | crontab -
ok "${messages["done"]}"

fi
Expand Down Expand Up @@ -765,11 +764,11 @@ install_dashd(){
pending " $MAINNET_BOOTSTRAP_FILE_1_SIZE... "
tput sc
echo -e "$C_CYAN"
$wget_cmd -O - $MAINNET_BOOTSTRAP_FILE_1 | pv -trepa -s${MAINNET_BOOTSTRAP_FILE_1_SIZE_M}m -w80 -N bootstrap > ${MAINNET_BOOTSTRAP_FILE_1##*/}
$wget_cmd -O - $MAINNET_BOOTSTRAP_FILE_1 | pv -trep -s${MAINNET_BOOTSTRAP_FILE_1_SIZE_M}m -w80 -N bootstrap > ${MAINNET_BOOTSTRAP_FILE_1##*/}
MAINNET_BOOTSTRAP_FILE=${MAINNET_BOOTSTRAP_FILE_1##*/}
if [ ! -s $MAINNET_BOOTSTRAP_FILE ]; then
rm $MAINNET_BOOTSTRAP_FILE
$wget_cmd -O - $MAINNET_BOOTSTRAP_FILE_2 | pv -trepa -s${MAINNET_BOOTSTRAP_FILE_1_SIZE_M}m -w80 -N bootstrap > ${MAINNET_BOOTSTRAP_FILE_2##*/}
$wget_cmd -O - $MAINNET_BOOTSTRAP_FILE_2 | pv -trep -s${MAINNET_BOOTSTRAP_FILE_1_SIZE_M}m -w80 -N bootstrap > ${MAINNET_BOOTSTRAP_FILE_2##*/}
MAINNET_BOOTSTRAP_FILE=${MAINNET_BOOTSTRAP_FILE_2##*/}
fi
echo -ne "$C_NORM"
Expand Down Expand Up @@ -935,7 +934,7 @@ get_dashd_status(){
get_public_ips

MASTERNODE_BIND_IP=$PUBLIC_IPV4
PUBLIC_PORT_CLOSED=$( timeout 2 nc -4 -z $PUBLIC_IPV4 9999 2>&1 >/dev/null; echo $? )
PUBLIC_PORT_CLOSED=$( timeout 2 nc -4 $PUBLIC_IPV4 9999 2>&1 </dev/null >/dev/null; echo $? )
# if [ $PUBLIC_PORT_CLOSED -ne 0 ] && [ ! -z "$PUBLIC_IPV6" ]; then
# PUBLIC_PORT_CLOSED=$( timeout 2 nc -6 -z $PUBLIC_IPV6 9999 2>&1 >/dev/null; echo $? )
# if [ $PUBLIC_PORT_CLOSED -eq 0 ]; then
Expand Down Expand Up @@ -1009,7 +1008,7 @@ awk ' \

cd $INSTALL_DIR/sentinel
SENTINEL_INSTALLED=$( ls -l bin/sentinel.py | wc -l )
SENTINEL_PYTEST=$( venv/bin/py.test test 2>&1 > /dev/null ; echo $? )
SENTINEL_PYTEST=$( venv/bin/py.test test 2>/dev/null > /dev/null ; echo $? )
SENTINEL_CRONTAB=$( crontab -l | grep sentinel | grep -v '^#' | wc -l )
SENTINEL_LAUNCH_OUTPUT=$( venv/bin/python bin/sentinel.py 2>&1 )
if [ -z "$SENTINEL_LAUNCH_OUTPUT" ] ; then
Expand All @@ -1028,16 +1027,17 @@ awk ' \

WEB_NINJA_JSON_TEXT=$(echo $WEB_NINJA_API | python -m json.tool)
WEB_NINJA_SEES_OPEN=$(echo "$WEB_NINJA_JSON_TEXT" | grep '"Result"' | grep open | wc -l)
WEB_NINJA_MN_ADDY=$(echo "$WEB_NINJA_JSON_TEXT" | grep MasternodePubkey | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_VIN=$(echo "$WEB_NINJA_JSON_TEXT" | grep MasternodeOutputHash | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_VIDX=$(echo "$WEB_NINJA_JSON_TEXT" | grep MasternodeOutputIndex | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_BALANCE=$(echo "$WEB_NINJA_JSON_TEXT" | grep Value | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_LAST_PAID_TIME_EPOCH=$(echo "$WEB_NINJA_JSON_TEXT" | grep MNLastPaidTime | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_LAST_PAID_AMOUNT=$(echo "$WEB_NINJA_JSON_TEXT" | grep MNLastPaidAmount | awk '{print $2}' | sed -e 's/[",]//g')
WEB_NINJA_MN_LAST_PAID_BLOCK=$(echo "$WEB_NINJA_JSON_TEXT" | grep MNLastPaidBlock | awk '{print $2}' | sed -e 's/[",]//g')

WEB_NINJA_LAST_PAYMENT_TIME=$(date -d @${WEB_NINJA_MN_LAST_PAID_TIME_EPOCH} '+%m/%d/%Y %H:%M:%S' 2>/dev/null)

LOCAL_MN_STATUS=$( $DASH_CLI masternode status | python -mjson.tool )
MN_PAYEE=$(echo "$LOCAL_MN_STATUS" | grep '"payee"' | awk '{print $2}' | sed -e 's/[",]//g')
MN_FUNDING=$([ ! -z "$MN_PAYEE" ] && echo "$LOCAL_MN_STATUS" | grep '"outpoint"' | awk '{print $2}' | sed -e 's/[",]//g')

if [ ! -z "$WEB_NINJA_LAST_PAYMENT_TIME" ]; then
local daysago=$(dateDiff -d now "$WEB_NINJA_LAST_PAYMENT_TIME")
local hoursago=$(dateDiff -h now "$WEB_NINJA_LAST_PAYMENT_TIME")
Expand Down Expand Up @@ -1115,10 +1115,10 @@ print_status() {
pending "${messages["status_mnvislo"]}" ; [ $MN_VISIBLE -gt 0 ] && ok "${messages["YES"]}" || err "${messages["NO"]}"
if [ $WEB_NINJA_API_OFFLINE -eq 0 ]; then
pending "${messages["status_mnvisni"]}" ; [ $WEB_NINJA_SEES_OPEN -gt 0 ] && ok "${messages["YES"]}" || err "${messages["NO"]}"
pending "${messages["status_mnaddre"]}" ; ok "$WEB_NINJA_MN_ADDY"
pending "${messages["status_mnfundt"]}" ; ok "$WEB_NINJA_MN_VIN-$WEB_NINJA_MN_VIDX"
pending "${messages["status_mnaddre"]}" ; ok "$MN_PAYEE"
pending "${messages["status_mnfundt"]}" ; ok "$MN_FUNDING"
pending "${messages["status_mnqueue"]}" ; [ $MN_QUEUE_IN_SELECTION -gt 0 ] && highlight "$MN_QUEUE_POSITION/$MN_QUEUE_LENGTH (selection pending)" || ok "$MN_QUEUE_POSITION/$MN_QUEUE_LENGTH"
pending " masternode mnsync state : " ; [ ! -z "$MN_SYNC_ASSET" ] && ok "$MN_SYNC_ASSET" || ""
pending " masternode mnsync state : " ; [ ! -z "$MN_SYNC_ASSET" ] && ok "$MN_SYNC_ASSET"
pending " masternode network state : " ; [ "$MN_STATUS" == "ENABLED" ] && ok "$MN_STATUS" || highlight "$MN_STATUS"

pending "${messages["status_mnlastp"]}" ; [ ! -z "$WEB_NINJA_MN_LAST_PAID_AMOUNT" ] && \
Expand Down Expand Up @@ -1216,7 +1216,7 @@ install_sentinel() {
cd sentinel

pending " --> virtualenv init... "
virtualenv venv 2>&1 > /dev/null;
virtualenv venv 2>/dev/null >/dev/null;
if [[ $? -gt 0 ]];then
err " --> virtualenv initialization failed"
pending " when running: " ; echo
Expand All @@ -1226,7 +1226,7 @@ install_sentinel() {
ok "${messages["done"]}"

pending " --> pip modules... "
venv/bin/pip install -r requirements.txt 2>&1 > /dev/null;
venv/bin/pip install -r requirements.txt 2>/dev/null > /dev/null;
if [[ $? -gt 0 ]];then
err " --> pip install failed"
pending " when running: " ; echo
Expand All @@ -1236,7 +1236,7 @@ install_sentinel() {
ok "${messages["done"]}"

pending " --> testing installation... "
venv/bin/py.test ./test/ 2>&1>/dev/null;
venv/bin/py.test ./test/ 2>/dev/null >/dev/null;
if [[ $? -gt 0 ]];then
err " --> sentinel tests failed"
pending " when running: " ; echo
Expand All @@ -1246,9 +1246,11 @@ install_sentinel() {
ok "${messages["done"]}"

pending " --> installing crontab... "
(crontab -l 2>/dev/null | grep -v sentinel.py ; echo "* * * * * cd $INSTALL_DIR/sentinel && venv/bin/python bin/sentinel.py 2>&1 >> sentinel-cron.log") | crontab -
(crontab -l 2>/dev/null | grep -v sentinel.py ; echo "* * * * * cd $INSTALL_DIR/sentinel && venv/bin/python bin/sentinel.py >> sentinel-cron.log 2>&1") | crontab -
ok "${messages["done"]}"

[ -e venv/bin/python2 ] && [ ! -L venv/bin/python2 ] && [ ! -z "$LD_LIBRARY_PATH" ] && cp -a venv/bin/python2 venv/bin/python2.bin && echo -e "#!/bin/sh\nLD_LIBRARY_PATH=$LD_LIBRARY_PATH exec \`dirname \$0\`/python2.bin \$*" > venv/bin/python2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the wrapper is because the cron run doesn't have LD_LIBRARY_PATH set?
Instead, is there a way to set it in the initial virtualenv install at line 1219 virtualenv venv 2>/dev/null >/dev/null;?

Copy link
Author

@hookbot hookbot Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it MIGHT be possible to move that line up closer to line 1252 way up closer to line 1219, but I was scared of possible infinite grinding the "pip install" and "py.test" stuff when they attempt to run the "bin/python2" which never requires any LD_LIBRARY_PATH dancing around.

This wrapper is ONLY for CentOS 6.x where that new-fangled Python 2.7 requirement is nearly impossible to find. The only way I was able to get sentinel to work on CentOS 6.x was using the "scl" wrapper:

$ time scl enable python27 "~/dashman/dashman install sentinel"

And yes, no matter how hard I tried to fix the crontab entry to run the correct "scl" wrapper properly on CentOS 6.x platform, every time I accidentally update dashman, she keeps bricking over my goodness with that nasty stock "sentinel" crontab entry, then my node would fall into WATCHDOG_EXPIRED and I'd lose all my beans. I couldn't stand it anymore, so I added that patch to buttwag around all the frustrations. Now everything works great again on CentOS 6.x.

Basically, this just ensures that if there is any "$LD_LIBRARY_PATH" existing during the commandline installation, that same environment will exist when the cron runs too.

Fortunately, in the other 99% of the cases, this "$LD_LIBRARY_PATH" is already naked, so this line just doesn't do anything at all.

OH! What would be REALLY cool would be if dashman could automagically detect the version of python running and do all the "scl" wrapper stuff if that's the only way to reach python2.7 on the current system.

Yes, I realize this is ugly, but I'm open to any suggestions.

Copy link
Author

@hookbot hookbot Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: I've also found that CentOS 6.x runs more efficiently than CentOS 7.x (and other Platforms) on VMs with less memory resources, which is what really makes this patch so much more valuable to people who care about how much money it costs each month to keep a masternode up and running.


cd ..

}