Skip to content

Commit

Permalink
Add new option to send an rpc cmd to all wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
joeuhren committed Mar 3, 2021
1 parent 9d14da5 commit db134d5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ To update all installed wallets with a single command, use the following:
```
Usage Example: `sudo sh exor-mn-installer.sh -u`
- -R or --rpcall
Send an RPC command to all wallets controlled by this script and display the results
Usage Example: `sudo sh exor-mn-installer.sh -R getblockcount`
- -S or --stopall
Shutdown all wallets controlled by this script and wait for all to finish shutting down before continuing
Expand Down Expand Up @@ -301,10 +306,38 @@ cexor5 getmasternodestatus
#### Shut down all running wallets:
**NOTE:** The following command will shut down masternode wallets one at a time and wait for each to completely close before proceeding to the next:
```
sudo sh exor-mn-installer.sh -S
```
#### Send an rpc command to all wallets simultaneously:
View the current block for all wallets:
```
sudo sh exor-mn-installer.sh -R getblockcount
```
Check masternode status for all wallets:
```
sudo sh exor-mn-installer.sh -R getmasternodestatus
```
Stop all wallets:
```
sudo sh exor-mn-installer.sh -R stop
```
Commands with spaces can also be used by surrounding the full command in double-quotes:
```
sudo sh exor-mn-installer.sh -R "masternode status"
```
#### Sample cron job to shut down all running wallets and reboot once a month:
1st allow reboot cmd to be run without root permissions:
Expand Down
50 changes: 49 additions & 1 deletion exor-mn-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ help_menu() {
echo " apt-get update"
echo " apt-get upgrade"
echo " apt-get dist-upgrade"
echo " -R, --rpcall"
echo " send an RPC command to all wallets controlled by this script and"
echo " display the results"
echo " -S, --stopall"
echo " shutdown all wallets controlled by this script and wait for all to"
echo " finish shutting down before continuing"
Expand Down Expand Up @@ -505,6 +508,44 @@ removeWalletLinks() {
rm -f "${HOME_DIR}/${WALLET_PREFIX}-cli${INSTALL_SUFFIX}"
}

rpc_command() {
WALLET_CLOSED=0
# Check for installed wallets
i=1; while [ $i -le 99 ]; do
case $i in
1) WALLET_DIR_TEST="${DEFAULT_WALLET_DIR}"
DATA_DIR_TEST="${DEFAULT_DATA_DIR}" ;;
*) WALLET_DIR_TEST="${DEFAULT_WALLET_DIR}${i}"
DATA_DIR_TEST="${DEFAULT_DATA_DIR}${i}" ;;
esac

if [ -d "${HOME_DIR}/${WALLET_DIR_TEST}" ]; then
# Found an installed wallet
# Check if the wallet is currently running
if [ -f "${HOME_DIR}/${WALLET_DIR_TEST}/${WALLET_PREFIX}d" ] && [ -n "$(lsof "${HOME_DIR}/${WALLET_DIR_TEST}/${WALLET_PREFIX}d" 2> /dev/null)" ]; then
# Wallet is running
# Add space if a wallet was already closed
if [ $WALLET_CLOSED -eq 0 ]; then
echo
fi
# Display info msg
echo "${CYAN}#####${NONE} Wallet #${i} Response: ${CYAN}#####${NONE}" && echo
# Issue rpc command
${HOME_DIR}/${WALLET_DIR_TEST}/${WALLET_PREFIX}-cli -datadir=${USER_HOME_DIR}/${DATA_DIR_TEST} ${1}
# Keep track of wallet being closed
echo && WALLET_CLOSED=1
fi
fi

i=$(( i + 1 ))
done

# Check if any wallets were closed
if [ $WALLET_CLOSED -eq 0 ]; then
echo && echo "${GREEN}#####${NONE} No wallets are currently running ${GREEN}#####${NONE}" && echo
fi
}

stop_all() {
WALLET_CLOSED=0
# Check for installed wallets
Expand Down Expand Up @@ -583,7 +624,7 @@ if [ -z "${CURRENT_USER}" ]; then
fi

# Read command line arguments
if ! ARGS=$(getopt -o "ht:w:g:N:i:p:n:a:sfbcuSU" -l "help,type:,wallet:,genkey:,net:,ip:,port:,number:,adapter:,noswap,nofirewall,nobruteprotect,nochainsync,noosupgrade,stopall,updateall" -n "${0##*/}" -- "$@"); then
if ! ARGS=$(getopt -o "ht:w:g:N:i:p:n:a:R:sfbcuSU" -l "help,type:,wallet:,genkey:,net:,ip:,port:,number:,adapter:,rpcall:,noswap,nofirewall,nobruteprotect,nochainsync,noosupgrade,stopall,updateall" -n "${0##*/}" -- "$@"); then
# invalid command line arguments so show help menu
help_menu
exit;
Expand Down Expand Up @@ -674,6 +715,13 @@ while true; do
shift;
OSUPGRADE="0";
;;
-R|--rpcall)
shift;
if [ -n "$1" ]; then
rpc_command "$1"
exit
fi
;;
-S|--stopall)
shift;
stop_all;
Expand Down

0 comments on commit db134d5

Please sign in to comment.