Skip to content

Commit 832263c

Browse files
authored
healthcheck for rpc task (#15)
1 parent 3d76e47 commit 832263c

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

rpc/healthcheck.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
BLOCKCHAIN_TIME=$(curl --silent --max-time 3 "http://localhost/status" |jq -r .result.sync_info.latest_block_time)
4+
5+
if [[ ${BLOCKCHAIN_TIME} == "null" ]]; then
6+
echo Status: 502
7+
echo Content-type:text/plain
8+
echo
9+
echo The node is currently not responding.
10+
exit 0
11+
fi
12+
13+
if [[ ! -z "$BLOCKCHAIN_TIME" ]]; then
14+
BLOCKCHAIN_SECS=`date -d $BLOCKCHAIN_TIME +%s`
15+
CURRENT_SECS=`date +%s`
16+
17+
# if within 60 seconds of current time, call it synced and report healthy
18+
BLOCK_AGE=$((${CURRENT_SECS} - ${BLOCKCHAIN_SECS}))
19+
20+
if [[ ${BLOCK_AGE} -le 60 ]]; then
21+
echo Status: 200
22+
echo Content-type:text/plain
23+
echo
24+
echo latest_block_time is less than 60 seconds, this node is considered healthy.
25+
else
26+
echo Status: 503
27+
echo Content-type:text/plain
28+
echo
29+
echo latest_block_time is higher than 60 seconds, this node is responding but not synced
30+
fi
31+
else
32+
echo Status: 502
33+
echo Content-type:text/plain
34+
echo
35+
echo The node is currently not responding.
36+
fi

rpc/nginx.conf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
#user http;
3+
worker_processes 1;
4+
5+
#error_log logs/error.log;
6+
#error_log logs/error.log notice;
7+
#error_log logs/error.log info;
8+
9+
#pid logs/nginx.pid;
10+
11+
12+
events {
13+
worker_connections 1024;
14+
}
15+
16+
17+
http {
18+
include mime.types;
19+
default_type application/octet-stream;
20+
21+
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
22+
# '$status $body_bytes_sent "$http_referer" '
23+
# '"$http_user_agent" "$http_x_forwarded_for"';
24+
25+
#access_log logs/access.log main;
26+
27+
sendfile on;
28+
#tcp_nopush on;
29+
30+
#keepalive_timeout 0;
31+
keepalive_timeout 65;
32+
33+
#gzip on;
34+
35+
resolver 127.0.0.11 valid=30s; # Docker's DNS server
36+
37+
server {
38+
listen 80;
39+
server_name localhost;
40+
#charset koi8-r;
41+
42+
#access_log logs/host.access.log main;
43+
44+
location / {
45+
proxy_http_version 1.1;
46+
proxy_set_header Upgrade $http_upgrade;
47+
proxy_set_header Connection "upgrade";
48+
proxy_set_header X-Real-IP $remote_addr;
49+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
50+
proxy_set_header Host $http_host;
51+
proxy_set_header X-NginX-Proxy true;
52+
53+
proxy_pass http://localhost:26657/;
54+
}
55+
56+
location /healthcheck {
57+
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/healthcheck.sh;
58+
fastcgi_pass unix:/var/run/fcgiwrap.socket;
59+
}
60+
61+
#error_page 404 /404.html;
62+
63+
# redirect server error pages to the static page /50x.html
64+
#
65+
error_page 500 502 503 504 /50x.html;
66+
location = /50x.html {
67+
root /usr/share/nginx/html;
68+
}
69+
}
70+
}

rpc/quicksync.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ then
5252
exit
5353
fi
5454

55-
pacman -Syu --noconfirm go git base-devel wget jq $pacman_pkgs
55+
pacman -Syu --noconfirm go git base-devel wget jq nginx spawn-fcgi fcgiwrap $pacman_pkgs
5656

5757
echo "#################################################################################################################"
5858
echo "build from source:"
@@ -242,5 +242,14 @@ fi
242242
echo "download addrbook..."
243243
curl -Ls $proxy_cache_url$addrbook_url > $node_home/config/addrbook.json
244244

245-
# start chain
245+
echo "#################################################################################################################"
246+
echo "start nginx..."
247+
curl -Ls "https://raw.githubusercontent.com/baabeetaa/cosmosia/main/rpc/nginx.conf" > /etc/nginx/nginx.conf
248+
curl -Ls "https://raw.githubusercontent.com/baabeetaa/cosmosia/main/rpc/healthcheck.sh" > /usr/share/nginx/html/healthcheck.sh
249+
chmod +x /usr/share/nginx/html/healthcheck.sh
250+
spawn-fcgi -s /var/run/fcgiwrap.socket -M 766 /usr/sbin/fcgiwrap
251+
/usr/sbin/nginx
252+
253+
echo "#################################################################################################################"
254+
echo "start chain..."
246255
$HOME/go/bin/$daemon_name start $start_flags

0 commit comments

Comments
 (0)