SHA256
Обновить HEADER, теги CORE и конфигурацию основного сервера
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
|
||||
ssh "$REMOTE_HOST" 'python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
config = Path('/etc/caddy/Caddyfile')
|
||||
old = ''' @backend path /status /api/status /ws /ws/* /api/files/user-server /api/files/prepare /api/dm-files/prepare /files/* /dm-files/*
|
||||
handle @backend {
|
||||
reverse_proxy 127.0.0.1:7105
|
||||
}
|
||||
handle {
|
||||
root * /home/player/SHiNE/main/UI
|
||||
try_files {path} {path}/index.html /index.html
|
||||
file_server
|
||||
}
|
||||
}'''
|
||||
new = ''' @backend path /status /api/status /ws /ws/* /api/files/user-server /api/files/prepare /api/dm-files/prepare /dm-files/*
|
||||
handle @backend {
|
||||
reverse_proxy 127.0.0.1:7105
|
||||
}
|
||||
@publicFilesRead {
|
||||
method GET HEAD
|
||||
path_regexp public_file ^/files/[0-9a-f]{64}$
|
||||
}
|
||||
handle @publicFilesRead {
|
||||
uri strip_prefix /files
|
||||
root * /home/player/SHiNE/main/server/data/public-files
|
||||
header {
|
||||
Cache-Control "public, max-age=31536000, immutable"
|
||||
Access-Control-Allow-Origin "*"
|
||||
Cross-Origin-Resource-Policy "cross-origin"
|
||||
}
|
||||
file_server
|
||||
}
|
||||
@publicFilesWrite {
|
||||
method PUT OPTIONS
|
||||
path /files/*
|
||||
}
|
||||
handle @publicFilesWrite {
|
||||
reverse_proxy 127.0.0.1:7105
|
||||
}
|
||||
handle {
|
||||
root * /home/player/SHiNE/main/UI
|
||||
try_files {path} {path}/index.html /index.html
|
||||
file_server
|
||||
header -Etag
|
||||
header {
|
||||
Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
|
||||
Pragma "no-cache"
|
||||
Expires "0"
|
||||
}
|
||||
}
|
||||
}'''
|
||||
text = config.read_text()
|
||||
if text.count(old) != 1:
|
||||
raise SystemExit('Expected shineup.me Caddy block not found exactly once')
|
||||
Path('/home/player/SHiNE/main/server/data/public-files').mkdir(parents=True, exist_ok=True)
|
||||
subprocess.run(['sudo', '-n', 'cp', str(config), '/etc/caddy/Caddyfile.before-shine-main-align'], check=True)
|
||||
tmp = Path('/tmp/shine-main-Caddyfile-align')
|
||||
tmp.write_text(text.replace(old, new))
|
||||
subprocess.run(['sudo', '-n', 'install', '-o', 'player', '-g', 'player', '-m', '0664', str(tmp), str(config)], check=True)
|
||||
tmp.unlink()
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n systemctl reload caddy; sudo -n systemctl is-active --quiet caddy'
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
|
||||
ssh "$REMOTE_HOST" 'python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
t2 = Path('/home/player/t2/server/application.properties')
|
||||
main = Path('/home/player/SHiNE/main/server/application.properties')
|
||||
keys = ('r2.endpoint', 'r2.accessKeyId', 'r2.secretAccessKey', 'r2.publicBucket', 'r2.dmBucket')
|
||||
source = {}
|
||||
for line in t2.read_text().splitlines():
|
||||
if '=' in line and not line.lstrip().startswith('#'):
|
||||
k, v = line.split('=', 1)
|
||||
source[k.strip()] = v.strip()
|
||||
if any(not source.get(k) for k in keys):
|
||||
raise SystemExit('t2 R2 settings incomplete; no change')
|
||||
original = main.read_text()
|
||||
if any(line.startswith('r2.endpoint=') and line.split('=', 1)[1].strip() for line in original.splitlines()):
|
||||
raise SystemExit('Production R2 already configured; refusing to overwrite')
|
||||
backup = main.with_name('application.properties.before-r2')
|
||||
if backup.exists():
|
||||
raise SystemExit('R2 backup already exists; no change')
|
||||
shutil.copy2(main, backup)
|
||||
updated = []
|
||||
seen = set()
|
||||
for line in original.splitlines():
|
||||
key = line.split('=', 1)[0].strip()
|
||||
if key in keys:
|
||||
updated.append(key + '=' + source[key])
|
||||
seen.add(key)
|
||||
else:
|
||||
updated.append(line)
|
||||
for key in keys:
|
||||
if key not in seen:
|
||||
updated.append(key + '=' + source[key])
|
||||
main.write_text('\n'.join(updated) + '\n')
|
||||
main.chmod(0o600)
|
||||
print('Production R2 settings copied from t2 without exposing credentials')
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
path = Path('/etc/caddy/Caddyfile')
|
||||
text = path.read_text()
|
||||
old = ''' handle {
|
||||
root * /home/player/SHiNE/main/UI
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
}'''
|
||||
new = ''' @backend path /status /api/status /ws /ws/* /api/files/user-server /api/files/prepare /api/dm-files/prepare /files/* /dm-files/*
|
||||
handle @backend {
|
||||
reverse_proxy 127.0.0.1:7105
|
||||
}
|
||||
handle {
|
||||
root * /home/player/SHiNE/main/UI
|
||||
try_files {path} {path}/index.html /index.html
|
||||
file_server
|
||||
}
|
||||
}'''
|
||||
if text.count(old) != 1:
|
||||
raise SystemExit('Expected shineup.me Caddy block not found exactly once; no change')
|
||||
backup = Path('/etc/caddy/Caddyfile.before-shine-main-r2')
|
||||
if backup.exists():
|
||||
raise SystemExit('Caddy backup already exists; no change')
|
||||
subprocess.run(['sudo', '-n', 'cp', str(path), str(backup)], check=True)
|
||||
tmp = Path('/tmp/shine-main-Caddyfile-r2')
|
||||
tmp.write_text(text.replace(old, new))
|
||||
subprocess.run(['sudo', '-n', 'install', '-o', 'player', '-g', 'player', '-m', '0664', str(tmp), str(path)], check=True)
|
||||
tmp.unlink()
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n systemctl reload caddy; sudo -n systemctl is-active --quiet caddy'
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
JAR="$ROOT_DIR/SHiNE-server/build/libs/shine-server.jar"
|
||||
BACKUP_DIR="$ROOT_DIR/deploy/backup/archive"
|
||||
|
||||
if ! find "$BACKUP_DIR" -mindepth 2 -maxdepth 2 -name MANIFEST.txt -print -quit | grep -q .; then
|
||||
echo "Свежий production-бэкап с MANIFEST.txt обязателен" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "${BUILD_JAR:-1}" == 1 ]]; then
|
||||
(cd "$ROOT_DIR" && ./gradlew shadowJar)
|
||||
fi
|
||||
[[ -s "$JAR" ]] || { echo "Серверный JAR отсутствует" >&2; exit 1; }
|
||||
rsync -az "$JAR" "$REMOTE_HOST:/home/player/SHiNE/main/server/shine-server.jar"
|
||||
ssh "$REMOTE_HOST" 'sudo -n systemctl restart shine-main.service'
|
||||
@@ -75,7 +75,7 @@ if [[ -f "$DEPLOY_CONFIG_FILE" ]]; then
|
||||
perl -0pi -e "s/export const defaultSolanaCluster = '.*?';/export const defaultSolanaCluster = '$DEPLOY_SOLANA_CLUSTER_NORMALIZED';/s" "$DEPLOY_CONFIG_FILE"
|
||||
fi
|
||||
if [[ -n "$DEPLOY_SOLANA_ENDPOINT" ]]; then
|
||||
perl -0pi -e "s|export const defaultSolanaEndpoint = '.*?';|export const defaultSolanaEndpoint = '$DEPLOY_SOLANA_ENDPOINT';|s" "$DEPLOY_CONFIG_FILE"
|
||||
perl -0pi -e "s|export const defaultSolanaEndpoint = .*?;|export const defaultSolanaEndpoint = '$DEPLOY_SOLANA_ENDPOINT';|s" "$DEPLOY_CONFIG_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
import os, shutil
|
||||
|
||||
source = Path('/etc/shine/shine-t2.env')
|
||||
target = Path('/etc/shine/shine-main.env')
|
||||
if target.exists():
|
||||
raise SystemExit('Main environment file already exists; refusing to overwrite')
|
||||
key_lines = [l for l in source.read_text().splitlines() if l.startswith('RESEND_API_KEY=')]
|
||||
if len(key_lines) != 1 or not key_lines[0].split('=', 1)[1].strip():
|
||||
raise SystemExit('Resend API key not available on t2')
|
||||
fd = os.open(target, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
|
||||
with os.fdopen(fd, 'w') as stream:
|
||||
stream.write(key_lines[0] + '\n')
|
||||
os.chown(target, 0, 0)
|
||||
props = Path('/home/player/SHiNE/main/server/application.properties')
|
||||
backup = props.with_name('application.properties.before-external-registrar')
|
||||
if backup.exists():
|
||||
raise SystemExit('Registrar backup already exists; refusing to overwrite')
|
||||
text = props.read_text()
|
||||
required = {
|
||||
'freeRegistration.enabled': 'true',
|
||||
'freeRegistration.namespace': 'free',
|
||||
'freeRegistration.signerMode': 'external',
|
||||
'freeRegistration.email.allowTestCode': 'false',
|
||||
'freeRegistration.email.allowReuse': 'false',
|
||||
'server.SHiNE.login': 'shineupme@shine',
|
||||
}
|
||||
shutil.copy2(props, backup)
|
||||
lines = []
|
||||
seen = set()
|
||||
for line in text.splitlines():
|
||||
name = line.split('=', 1)[0].strip()
|
||||
if name in required:
|
||||
lines.append(name + '=' + required[name])
|
||||
seen.add(name)
|
||||
else:
|
||||
lines.append(line)
|
||||
for name, value in required.items():
|
||||
if name not in seen:
|
||||
lines.append(name + '=' + value)
|
||||
props.write_text('\n'.join(lines) + '\n')
|
||||
props.chmod(0o600)
|
||||
print('External registrar configuration prepared')
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n mkdir -p /etc/systemd/system/shine-main.service.d; sudo -n tee /etc/systemd/system/shine-main.service.d/registrar-env.conf >/dev/null' <<'EOF'
|
||||
[Service]
|
||||
EnvironmentFile=/etc/shine/shine-main.env
|
||||
EOF
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n systemctl daemon-reload'
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Подготавливает отдельный production-инстанс на общем VPS без запуска Java.
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
ssh "$REMOTE_HOST" 'python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
import os, shutil, subprocess
|
||||
|
||||
base = Path('/home/player/SHiNE/main')
|
||||
server = base / 'server'
|
||||
ui = base / 'UI'
|
||||
for path in (base, server, ui, server / 'data', server / 'logs'):
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
base.chmod(0o711) # Caddy должен проходить к UI, не читая закрытые файлы.
|
||||
secret = {}
|
||||
for line in (base / 'postgres.env').read_text().splitlines():
|
||||
if '=' in line:
|
||||
k, v = line.split('=', 1)
|
||||
secret[k] = v
|
||||
source = Path('/home/player/t2/server/application.properties')
|
||||
entries = []
|
||||
values = {}
|
||||
for line in source.read_text().splitlines():
|
||||
if '=' in line and not line.lstrip().startswith('#'):
|
||||
k, v = line.split('=', 1)
|
||||
k = k.strip()
|
||||
entries.append(k)
|
||||
values[k] = v.strip()
|
||||
key = parse_qs(urlparse(values['solana.rpcUrl']).query)['api-key'][0]
|
||||
values.update({
|
||||
'server.port': '7105',
|
||||
'db.url': 'jdbc:postgresql://127.0.0.1:5432/shine_main_db',
|
||||
'db.user': 'shine_main',
|
||||
'db.password': secret['DB_PASSWORD'],
|
||||
'db.path': 'data/shine.sqlite',
|
||||
'solana.cluster': 'mainnet-beta',
|
||||
'solana.rpcUrl': 'https://mainnet.helius-rpc.com/?api-key=' + key,
|
||||
'server.info.url': 'https://shineup.me',
|
||||
'server.info.description': 'Основной сервер SHiNE',
|
||||
'server.info.origin': 'mainnet-beta',
|
||||
'server.ui.indexPath': str(ui / 'index.html'),
|
||||
'solana.users.sync.rpcUrl': 'https://mainnet.helius-rpc.com/?api-key=' + key,
|
||||
'solana.users.sync.wsUrl': 'wss://mainnet.helius-rpc.com/?api-key=' + key,
|
||||
'solana.users.sync.databaseUrl': 'jdbc:postgresql://127.0.0.1:5432/shine_main_db',
|
||||
'solana.users.sync.dbUser': 'shine_main',
|
||||
'solana.users.sync.dbPassword': secret['DB_PASSWORD'],
|
||||
'server.SHiNE.login': 'shineupme@shine',
|
||||
'test.freeAvatar.enabled': 'false',
|
||||
'archive.publish.enabled': 'false',
|
||||
'arweave.blocks.publish.enabled': 'false',
|
||||
'freeRegistration.enabled': 'false',
|
||||
'freeRegistration.email.allowTestCode': 'false',
|
||||
'freeRegistration.email.allowReuse': 'false',
|
||||
})
|
||||
for k in list(values):
|
||||
if k.startswith(('test.freeAvatar.wallet', 'archive.arweave.wallet', 'archive.solana.rootKey',
|
||||
'archive.solana.clientKey', 'arweave.blocks.publish.wallet',
|
||||
'arweave.blocks.publish.turbo.wallet', 'arweave.blocks.publish.turbo.paidBy',
|
||||
'freeRegistration.registrarSeed', 'call.ice.turn')):
|
||||
values[k] = ''
|
||||
target = server / 'application.properties'
|
||||
if target.exists():
|
||||
raise SystemExit('Existing production application.properties; refusing to overwrite')
|
||||
target.write_text('\n'.join(k + '=' + values[k] for k in entries) + '\n')
|
||||
target.chmod(0o600)
|
||||
for name in ('shine-server.jar', 'allowed-email-domains.txt'):
|
||||
shutil.copy2(source.parent / name, server / name)
|
||||
print('Production server files prepared; Java service not started')
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n tee /etc/systemd/system/shine-main.service >/dev/null' <<'EOF'
|
||||
[Unit]
|
||||
Description=SHiNE Server (shineup.me)
|
||||
After=network.target docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=player
|
||||
Group=player
|
||||
WorkingDirectory=/home/player/SHiNE/main/server
|
||||
ExecStart=/usr/bin/java -Dserver.port=7105 -jar /home/player/SHiNE/main/server/shine-server.jar
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
ssh "$REMOTE_HOST" 'sudo -n systemctl daemon-reload; sudo -n systemctl disable shine-main.service >/dev/null 2>&1 || true'
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="${REMOTE_HOST:-player@t2.shineup.me}"
|
||||
|
||||
ssh "$REMOTE_HOST" 'python3 -' <<'PY'
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
import subprocess
|
||||
|
||||
app = Path('/home/player/SHiNE/main/server/application.properties').read_text()
|
||||
rpc = next(line.split('=', 1)[1].strip() for line in app.splitlines() if line.startswith('solana.rpcUrl='))
|
||||
key = parse_qs(urlparse(rpc).query)['api-key'][0]
|
||||
env = Path('/tmp/shine-main-caddy.env')
|
||||
env.write_text('SHINE_MAINNET_HELIUS_KEY=' + key + '\n')
|
||||
env.chmod(0o600)
|
||||
subprocess.run(['sudo', '-n', 'install', '-o', 'root', '-g', 'caddy', '-m', '0640', str(env), '/etc/caddy/shine-mainnet.env'], check=True)
|
||||
env.unlink()
|
||||
caddy = Path('/etc/caddy/Caddyfile')
|
||||
current = caddy.read_text()
|
||||
if '\nshineup.me {' in current or current.startswith('shineup.me {'):
|
||||
raise SystemExit('shineup.me block already exists; refusing to overwrite')
|
||||
block = '''
|
||||
shineup.me {
|
||||
encode zstd gzip
|
||||
@rpc path /solana-rpc
|
||||
handle @rpc {
|
||||
rewrite * /?api-key={$SHINE_MAINNET_HELIUS_KEY}
|
||||
reverse_proxy https://mainnet.helius-rpc.com {
|
||||
header_up Host mainnet.helius-rpc.com
|
||||
}
|
||||
}
|
||||
handle {
|
||||
root * /home/player/SHiNE/main/UI
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
}
|
||||
'''
|
||||
new = Path('/tmp/shine-main-Caddyfile')
|
||||
new.write_text(current.rstrip() + '\n' + block)
|
||||
subprocess.run(['sudo', '-n', 'install', '-o', 'player', '-g', 'player', '-m', '0664', str(new), '/etc/caddy/Caddyfile'], check=True)
|
||||
new.unlink()
|
||||
PY
|
||||
|
||||
ssh "$REMOTE_HOST" 'sudo -n mkdir -p /etc/systemd/system/caddy.service.d; sudo -n tee /etc/systemd/system/caddy.service.d/shine-mainnet.conf >/dev/null' <<'EOF'
|
||||
[Service]
|
||||
EnvironmentFile=/etc/caddy/shine-mainnet.env
|
||||
EOF
|
||||
|
||||
ssh "$REMOTE_HOST" 'set -e; sudo -n systemctl daemon-reload; sudo -n systemctl restart caddy; sudo -n systemctl is-active --quiet caddy'
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REMOTE_HOST="player@t2.shineup.me" \
|
||||
REMOTE_UI_DIR="/home/player/SHiNE/main/UI" \
|
||||
EXPECTED_CADDY_UI_ROOT="/home/player/SHiNE/main/UI" \
|
||||
EXPECTED_CADDY_SITE="shineup.me" \
|
||||
DEPLOY_SERVER_LOGIN="shineupme@shine" \
|
||||
DEPLOY_SERVER_ADDRESS="shineup.me" \
|
||||
DEPLOY_SOLANA_CLUSTER="mainnet-beta" \
|
||||
DEPLOY_SOLANA_ENDPOINT="https://shineup.me/solana-rpc" \
|
||||
TARGET_URL="https://shineup.me" \
|
||||
REQUIRE_BACKUP="1" \
|
||||
bash "$(dirname "$0")/deploy_ui.sh"
|
||||
Reference in New Issue
Block a user