Fix permissions for history graph
This commit is contained in:
226
installer
226
installer
@ -186,7 +186,6 @@ fi
|
||||
echo "[***] Building ckpool..."
|
||||
# Obtain the current source code
|
||||
git clone https://bitbucket.org/ckolivas/ckpool.git ckpool
|
||||
chown -R $service_user:$service_user ckpool
|
||||
cd ckpool
|
||||
|
||||
# This simply sets the donation address to allow you to donate to Robbie Ferguson if you win
|
||||
@ -240,7 +239,119 @@ cat > "$APP_ROOT/conf/ckpool.conf" <<EOF
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "[***] Setting up SQLite Databases"
|
||||
|
||||
# Create SQLite DB for hashrate history
|
||||
if [ ! -e "$APP_ROOT/db" ]; then
|
||||
mkdir -p "$APP_ROOT/db"
|
||||
fi
|
||||
HISTDB="$APP_ROOT/db/hashrate_history.sqlite"
|
||||
|
||||
if [ ! -f "$HISTDB" ]; then
|
||||
sqlite3 "$HISTDB" <<'EOSQL'
|
||||
CREATE TABLE IF NOT EXISTS history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ts INTEGER NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
payload TEXT NOT NULL -- base64-encoded JSON from status.php
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_history_addr_ts ON history(address, ts);
|
||||
EOSQL
|
||||
|
||||
fi
|
||||
chown -R "$CKPOOL_USER":"$CKPOOL_USER" "$APP_ROOT"
|
||||
chown www-data:www-data "$HISTDB" || true
|
||||
|
||||
# Save history script
|
||||
cat > /usr/local/sbin/btc-save-history.sh <<'EOF'
|
||||
#!/bin/bash
|
||||
APP_ROOT="/opt/btc-solo"
|
||||
HISTDB="$APP_ROOT/db/hashrate_history.sqlite"
|
||||
USERS_DIR="$APP_ROOT/logs/users"
|
||||
CKPOOL_PHP="/var/www/btc-solo/ckpool_status.php"
|
||||
|
||||
# bail quietly if prerequisites are missing
|
||||
for bin in sqlite3 jq php; do
|
||||
command -v "$bin" >/dev/null 2>&1 || exit 0
|
||||
done
|
||||
|
||||
[ -f "$HISTDB" ] || exit 0
|
||||
[ -d "$USERS_DIR" ] || exit 0
|
||||
[ -f "$CKPOOL_PHP" ] || exit 0
|
||||
|
||||
TS=$(date +%s)
|
||||
|
||||
insert_row() {
|
||||
local ts="$1" addr="$2" json="$3" b64
|
||||
if base64 --help 2>&1 | grep -q '\-w'; then
|
||||
b64=$(printf '%s' "$json" | base64 -w0)
|
||||
else
|
||||
b64=$(printf '%s' "$json" | base64)
|
||||
fi
|
||||
sqlite3 "$HISTDB" \
|
||||
"INSERT INTO history (ts,address,payload) VALUES ($ts,'$addr','$b64');" \
|
||||
2>/dev/null || true
|
||||
}
|
||||
|
||||
# 1) Pool snapshot (no addr = global pool)
|
||||
POOL_JSON=$(php "$CKPOOL_PHP" 2>/dev/null)
|
||||
if [ -n "$POOL_JSON" ]; then
|
||||
ERR=$(printf '%s' "$POOL_JSON" | jq -r '.error // empty' 2>/dev/null)
|
||||
if [ -z "$ERR" ]; then
|
||||
insert_row "$TS" "__POOL__" "$POOL_JSON"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2) Per-address snapshots for worker history
|
||||
for f in "$USERS_DIR"/*; do
|
||||
[ -f "$f" ] || continue
|
||||
ADDR=$(basename "$f")
|
||||
[ -n "$ADDR" ] || continue
|
||||
|
||||
JSON=$(ADDR="$ADDR" php -r '$_GET["addr"] = getenv("ADDR"); include "/var/www/btc-solo/ckpool_status.php";' 2>/dev/null)
|
||||
[ -n "$JSON" ] || continue
|
||||
|
||||
ERR=$(printf '%s' "$JSON" | jq -r '.error // empty' 2>/dev/null)
|
||||
[ -n "$ERR" ] && continue
|
||||
|
||||
insert_row "$TS" "$ADDR" "$JSON"
|
||||
done
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
chmod 0755 /usr/local/sbin/btc-save-history.sh
|
||||
|
||||
echo "[***] Setting up Cron Jobs..."
|
||||
# Cron job for hashrate history logging
|
||||
cat > /etc/cron.d/btc-save-history <<'EOF'
|
||||
* * * * * www-data /usr/local/sbin/btc-save-history.sh >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/btc-save-history
|
||||
|
||||
|
||||
echo "Configuring Log Rotation"
|
||||
cat > /etc/logrotate.d/btc-solo <<'EOF'
|
||||
/opt/btc-solo/logs/*.log {
|
||||
weekly
|
||||
rotate 8
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > /etc/logrotate.d/nginx <<'EOF'
|
||||
/var/log/nginx/*.log {
|
||||
weekly
|
||||
rotate 8
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
# make ckpmsg available to PHP
|
||||
ln -sf ${APP_ROOT}/${CKPOOL_USER}/src/ckpmsg /usr/local/bin/ckpmsg
|
||||
@ -3015,119 +3126,6 @@ ln -sf /etc/nginx/sites-available/btc-solo /etc/nginx/sites-enabled/btc-solo
|
||||
rm -f /etc/nginx/sites-enabled/default || true
|
||||
systemctl restart nginx
|
||||
|
||||
echo "[***] Setting up SQLite Databases"
|
||||
|
||||
# Create SQLite DB for hashrate history
|
||||
if [ ! -e "$APP_ROOT/db" ]; then
|
||||
mkdir -p "$APP_ROOT/db"
|
||||
fi
|
||||
HISTDB="$APP_ROOT/db/hashrate_history.sqlite"
|
||||
|
||||
if [ ! -f "$HISTDB" ]; then
|
||||
sqlite3 "$HISTDB" <<'EOSQL'
|
||||
CREATE TABLE IF NOT EXISTS history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ts INTEGER NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
payload TEXT NOT NULL -- base64-encoded JSON from status.php
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_history_addr_ts ON history(address, ts);
|
||||
EOSQL
|
||||
|
||||
fi
|
||||
chown www-data:www-data "$HISTDB" || true
|
||||
|
||||
# Save history script
|
||||
cat > /usr/local/sbin/btc-save-history.sh <<'EOF'
|
||||
#!/bin/bash
|
||||
APP_ROOT="/opt/btc-solo"
|
||||
HISTDB="$APP_ROOT/db/hashrate_history.sqlite"
|
||||
USERS_DIR="$APP_ROOT/logs/users"
|
||||
CKPOOL_PHP="/var/www/btc-solo/ckpool_status.php"
|
||||
|
||||
# bail quietly if prerequisites are missing
|
||||
for bin in sqlite3 jq php; do
|
||||
command -v "$bin" >/dev/null 2>&1 || exit 0
|
||||
done
|
||||
|
||||
[ -f "$HISTDB" ] || exit 0
|
||||
[ -d "$USERS_DIR" ] || exit 0
|
||||
[ -f "$CKPOOL_PHP" ] || exit 0
|
||||
|
||||
TS=$(date +%s)
|
||||
|
||||
insert_row() {
|
||||
local ts="$1" addr="$2" json="$3" b64
|
||||
if base64 --help 2>&1 | grep -q '\-w'; then
|
||||
b64=$(printf '%s' "$json" | base64 -w0)
|
||||
else
|
||||
b64=$(printf '%s' "$json" | base64)
|
||||
fi
|
||||
sqlite3 "$HISTDB" \
|
||||
"INSERT INTO history (ts,address,payload) VALUES ($ts,'$addr','$b64');" \
|
||||
2>/dev/null || true
|
||||
}
|
||||
|
||||
# 1) Pool snapshot (no addr = global pool)
|
||||
POOL_JSON=$(php "$CKPOOL_PHP" 2>/dev/null)
|
||||
if [ -n "$POOL_JSON" ]; then
|
||||
ERR=$(printf '%s' "$POOL_JSON" | jq -r '.error // empty' 2>/dev/null)
|
||||
if [ -z "$ERR" ]; then
|
||||
insert_row "$TS" "__POOL__" "$POOL_JSON"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2) Per-address snapshots for worker history
|
||||
for f in "$USERS_DIR"/*; do
|
||||
[ -f "$f" ] || continue
|
||||
ADDR=$(basename "$f")
|
||||
[ -n "$ADDR" ] || continue
|
||||
|
||||
JSON=$(ADDR="$ADDR" php -r '$_GET["addr"] = getenv("ADDR"); include "/var/www/btc-solo/ckpool_status.php";' 2>/dev/null)
|
||||
[ -n "$JSON" ] || continue
|
||||
|
||||
ERR=$(printf '%s' "$JSON" | jq -r '.error // empty' 2>/dev/null)
|
||||
[ -n "$ERR" ] && continue
|
||||
|
||||
insert_row "$TS" "$ADDR" "$JSON"
|
||||
done
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
chmod 0755 /usr/local/sbin/btc-save-history.sh
|
||||
|
||||
echo "[***] Setting up Cron Jobs..."
|
||||
# Cron job for hashrate history logging
|
||||
cat > /etc/cron.d/btc-save-history <<'EOF'
|
||||
* * * * * www-data /usr/local/sbin/btc-save-history.sh >/dev/null 2>&1
|
||||
EOF
|
||||
chmod 0644 /etc/cron.d/btc-save-history
|
||||
|
||||
|
||||
echo "Configuring Log Rotation"
|
||||
cat > /etc/logrotate.d/btc-solo <<'EOF'
|
||||
/opt/btc-solo/logs/*.log {
|
||||
weekly
|
||||
rotate 8
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > /etc/logrotate.d/nginx <<'EOF'
|
||||
/var/log/nginx/*.log {
|
||||
weekly
|
||||
rotate 8
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
echo "[***] Done"
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user