Management & Monitoring
This section is designed to gather steps for managing the different services around the xcash-dpops program, getting logs and monitoring the activity.

Managing Installation

You can manage your program installation with the installer script:
1
bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh)"
Copied!
The installation script enables you to install and manage your xcash-dpops program easily.

Restart Program

If you have an issue with your program running, or need to do some changes in the settings and need to restart the different program, it is recommended to restart the service using the installer script.
Run the installer script and choose option 12.
1
bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh)"
Copied!

Update program

When a new update of the program is pushed, you will need to a update your program.
Run the installer script and choose option 2.
1
bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh)"
Copied!

Change delegate mode

To change your settings from a solo to a shared delegate (and vice versa), you can run the installer script and choose option 9, or change the settings (fees and minimum payout) with option 10.
1
bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh)"
Copied!
You will be asked to input a delegate fee and a minimum payout amount to your voters. The script will automatically change the program settings to match your changes.
Don't forget to update your delegate fee by updating the public information as well.

Back up your local database

As a shared delegated, you will have the responsability to distribute the payout to your voters. The voters information and shares are stored locally into your delegate node database. Before attempting to update your node, or do maintenance on your server, it is highly recommended to backup this information.
To backup your shared delegate database, chose option 19:
1
bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh)"
Copied!

Recover mode

To be added.
allows you to change your public_address or VRF key must be using a domain name with delegate add txt record, value @ data is xcash-dpops:MYNEWPUBLICKEY or xcash-dpops:MYNEWVRFKEY you can do 1 or both at the same time does not matter then open ANY wallet (does not need to be the delegate wallet in case you lost it) and type delegate_recover mydomain, and it will do everything for you.

systemd services

systemd is generally used to manage low-level programs in Linux-based systems. It's a reliable way to automatically run programs on startup, and manage and monitor the different services.
In systemd, a unit refers to any resource that the system knows how to operate on and manage. This is the primary object that the systemd tools know how to deal with. These resources are defined using configuration files called unit files. Whether you installed with the autoinstaller script or manually, the programs needed to run the X-Cash consensus are managed in systemd with unit files.
The different services needed for the X-Cash consensus running on the server are listed below:
xcash-dpops.service
xcash-daemon.service
xcash-rpc-wallet.service
mongodb.service
firewall.service
1
[Unit]
2
Description=X-Cash DPOPS Daemon background process
3
​
4
[Service]
5
Type=simple
6
LimitNOFILE=infinity
7
User=root
8
WorkingDirectory=~/xcash-official/xcash-dpops/build
9
ExecStart=~/xcash-official/xcash-dpops/build/xcash-dpops --block-verifiers-secret-key BLOCK_VERIFIER_SECRET_KEY
10
Restart=always
11
​
12
[Install]
13
WantedBy=multi-user.target
Copied!
1
[Unit]
2
Description=X-Cash Daemon background process
3
​
4
[Service]
5
Type=simple
6
User=root
7
ExecStart=~/xcash-official/xcash-core/build/release/bin/xcash-wallet-rpc --wallet-file ~/xcash-official/xcash-wallets/WALLET --password PASSWORD --rpc-bind-port 18285 --confirm-external-bind --daemon-port 18281 --disable-rpc-login --trusted-daemon
8
Restart=always
9
​
10
[Install]
11
WantedBy=multi-user.target
Copied!
1
[Unit]
2
Description=X-Cash RPC Wallet background process
3
​
4
[Service]
5
Type=simple
6
User=root
7
ExecStart=~/xcash-official/xcash-core/build/release/bin/xcash-wallet-rpc --wallet-file ~/xcash-official/xcash-wallets/WALLET --password PASSWORD --rpc-bind-port 18285 --confirm-external-bind --daemon-port 18281 --disable-rpc-login --trusted-daemon
8
Restart=always
9
​
10
[Install]
11
WantedBy=multi-user.target
Copied!
1
[Unit]
2
Description=MongoDB Database Server
3
After=network.target
4
​
5
[Service]
6
Type=forking
7
User=root
8
Type=oneshot
9
RemainAfterExit=yes
10
PIDFile=~/xcash-official/systemdpid/mongod.pid
11
ExecStart=~/xcash-official/mongodb-linux-x86_64-ubuntu1804-4.4.0-rc7-36-gcf4ac31/bin/mongod --fork --syslog --dbpath /data/db
12
​
13
LimitFSIZE=infinity
14
LimitCPU=infinity
15
LimitAS=infinity
16
LimitNOFILE=64000
17
LimitNPROC=64000
18
LimitMEMLOCK=infinity
19
TasksMax=infinity
20
TasksAccounting=false
21
​
22
[Install]
23
WantedBy=multi-user.target
Copied!
1
[Unit]
2
Description=firewall
3
​
4
[Service]
5
Type=oneshot
6
RemainAfterExit=yes
7
User=root
8
ExecStart=~/xcash-official/xcash-dpops/scripts/firewall/firewall_script.sh
9
​
10
[Install]
11
WantedBy=multi-user.target
Copied!
All the unit files are located in /lib/systemd/system/

Services Management

At some point, you might have to need to restart or check the status of the services, either to reflect a change you have made, to update, or to run the program with different parameters.
Start
Restart
Stop
Status
To start a systemd service, run:
1
systemctl start SERVICE
Copied!
Example:
1
systemctl start xcash-dpops
Copied!
To restart a systemd service, run:
1
systemctl restart SERVICE
Copied!
Example:
1
systemctl restart xcash-rpc-wallet
Copied!
To stop a systemd service, run:
1
systemctl stop SERVICE
Copied!
Example:
1
systemctl stop xcash-daemon
Copied!
To check the status of a systemd service, run:
1
systemctl status SERVICE
Copied!
Example:
1
systemctl status mongodb
Copied!
Output:
1
● mongodb.service - MongoDB Database Server
2
Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset: enabled)
3
Active: active (exited) since Mon 2020-06-08 11:50:51 CEST; 38min ago
4
Main PID: 14852 (code=exited, status=0/SUCCESS)
5
CGroup: /system.slice/mongodb.service
6
└─14854 /root/xcash-official/mongodb-linux-x86_64-ubuntu1804-4.2.3/bin/mongod --fork --syslog --dbpath /data/db/
Copied!

Monitoring & Logging

While the services are running in the background, you might want to check the outputs of the different programs.
To monitor the services, we are using journalctl which fetch the journal of the systemd services. Using journalctl without paramaters will show the full contents of the journal, starting with the oldest entry collected.
For a live logging with better readability, we will limit the output by using the following parameters:
1
journalctl --unit=SERVICE --follow -n 100 --output cat
Copied!
To check the xcash-dpops services, you can copy the following commands:
xcash-dpops
xcash-daemon
xcash-rpc-wallet
mongodb
firewall
1
journalctl --unit=xcash-dpops --follow -n 100 --output cat
Copied!
1
journalctl --unit=xcash-daemon --follow -n 100 --output cat
Copied!
1
journalctl --unit=xcash-rpc-wallet --follow -n 100 --output cat
Copied!
1
journalctl --unit=mongodb --follow -n 100 --output cat
Copied!
1
journalctl --unit=firewall --follow -n 100 --output cat
Copied!
The xcash-daemon service export its logs in a different place. To display the latest log, use the following command:
1
tail -n 100 ~/xcash-official/logs/xcash-daemon-log.txt
Copied!

Login service checking

We can change the motd generated when we login to our server to make it show us basic node information like the service status, our balance and blockchain syncronization status
Optionally, we can to disable all the automatic scripts executed when we log in and only enable ours.
1
chmod -x /etc/update-motd.d/*
Copied!
We need to place our script in the update-motd.d directory, we will name it 00-xcash-node-checks and put our script inside
1
#!/bin/bash
2
​
3
# Adjust this variable to the name of your xcash-daemon unit file name
4
XCASH_DAEMON_SRV=xcash-daemon
5
​
6
# Adjust this variable to the name of your xcash-wallets unit file name
7
XCASH_WALLET_SRV=xcash-rpc-wallet
8
​
9
# Adjust this variable to the name of your xcash-dpops unit file name
10
XCASH_DPOPS_SRV=xcash-dpops
11
​
12
# Adjust this variable to the name of your mongodb unit file name
13
MONGODB_SRV=mongodb
14
​
15
DAEMON_URL="http://127.0.0.1:18281/json_rpc"
16
WALLET_URL="http://127.0.0.1:18285/json_rpc"
17
CURL='curl -w "\n" -s -H "Content-Type: application/json" -X'
18
​
19
red="\033[01;31m"
20
green="\033[01;32m"
21
reset="\033[0m"
22
​
23
function check_height(){
24
if lsof -Pi :18281 -sTCP:LISTEN -t >/dev/null ; then
25
DATA=`$CURL GET $DAEMON_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}'`
26
​
27
HEIGHT=$(echo "$DATA" | grep '"count"' | awk {'print $2'} | sed s'|,||g' | tr -d $'\r')
28
STATUS=$(echo "$DATA" | grep '"status"' | awk {'print $2'} | sed s'|"||g' | tr -d $'\r')
29
​
30
if [ $STATUS == "OK" ]; then
31
STATUS=${green}OK${reset}
32
else
33
SATTUS=${red}FAIL${reset}
34
fi
35
​
36
echo
37
echo -e "Blockhain sync status: $STATUS"
38
echo "Blockchain height: $HEIGHT"
39
else
40
echo
41
echo "X-Cash Daemon service is not running...."
42
echo "Check the $XCASH_DAEMON_SRV service status"
43
fi
44
}
45
​
46
function get_node_balance(){
47
if lsof -Pi :18285 -sTCP:LISTEN -t >/dev/null ; then
48
DATA=`$CURL GET $WALLET_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_balance","params":{"account_index":0,"address_indices":[0]}}'`
49
​
50
ADDR=$(echo "$DATA" | grep '"address"' | awk {'print $2'} | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d $'\r')
51
UNSPENT_OUTPUTS=$(echo "$DATA" | grep '"num_unspent_outputs"' | awk {'print $2'} | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d $'\r')
52
​
53
ATOMIC_TOTAL_BALANCE=$(echo "$DATA" | grep '"balance"' | awk {'print $2'} | sed s'|,||g' | head -1 | tr -d $'\r')
54
ATOMIC_UNLOCKED_BALANCE=$(echo "$DATA" | grep '"unlocked_balance"' | awk {'print $2'} | sed s'|,||g' | head -1 | sed s"|^M||g" | tr -d $'\r')
55
TOTAL_BALANCE=$((ATOMIC_TOTAL_BALANCE/1000000))
56
UNLOCKED_BALANCE=$((ATOMIC_UNLOCKED_BALANCE/1000000))
57
​
58
echo
59
echo "Public address: $ADDR"
60
echo "Unspent outputs: $UNSPENT_OUTPUTS"
61
echo "Total balance: $TOTAL_BALANCE XCASH"
62
echo "Unlocked balance: $UNLOCKED_BALANCE XCASH"
63
else
64
echo
65
echo "X-Cash RCP Wallet service is not running...."
66
echo "Check the $XCASH_WALLET_SRV service status"
67
fi
68
}
69
​
70
function check_services_status(){
71
echo
72
MONGODB_UP_SINCE=$(systemctl show $MONGODB_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
73
XCASH_DAEMON_UP_SINCE=$(systemctl show $XCASH_DAEMON_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
74
XCASH_WALLET_UP_SINCE=$(systemctl show $XCASH_WALLET_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
75
XCASH_DPOPS_UP_SINCE=$(systemctl show $XCASH_DPOPS_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
76
​
77
systemctl is-active $MONGODB_SRV --quiet \
78
&& echo -e ${green}MongoDB service is running since...............$MONGODB_UP_SINCE${reset} \
79
|| echo -e ${red}MongoDB service is not running${reset}
80
​
81
systemctl is-active $XCASH_DAEMON_SRV --quiet \
82
&& echo -e ${green}X-Cash Daemon service is running since.........$XCASH_DAEMON_UP_SINCE${reset} \
83
|| echo -e ${red}X-Cash Daemon service is not running${reset}
84
​
85
systemctl is-active $XCASH_WALLET_SRV --quiet \
86
&& echo -e ${green}X-Cash RPC Wallet service is running since.....$XCASH_WALLET_UP_SINCE${reset} \
87
|| echo -e ${red}X-Cash RPC Wallet service is not running${reset}
88
​
89
systemctl is-active $XCASH_DPOPS_SRV --quiet \
90
&& echo -e ${green}X-Cash DPoPS service is running since..........$XCASH_DPOPS_UP_SINCE${reset} \
91
|| echo -e ${red}X-Cash DPoPS service is not running${reset}
92
}
93
​
94
check_height
95
get_node_balance
96
check_services_status
97
echo
Copied!
If you have custom service names you need to adjust the service variable names at the beginning of the script
Then, we need to make it executable
1
chmod +x /etc/update-motd.d/00-xcash-node-checks
Copied!
After that, every time we log in to our server by ssh we will see something like this.
Last modified 8mo ago