2025-10-15 07:30:31 +02:00
|
|
|
import os, time, requests
|
|
|
|
|
|
|
|
|
|
COUCHDB_URL = 'http://couchdb:5984'
|
|
|
|
|
USER = os.getenv('COUCHDB_USER', 'admin')
|
|
|
|
|
PASSWORD = os.getenv('COUCHDB_PASSWORD', 'password')
|
|
|
|
|
|
|
|
|
|
for _ in range(30):
|
|
|
|
|
try:
|
|
|
|
|
r = requests.get(COUCHDB_URL)
|
|
|
|
|
if r.ok:
|
|
|
|
|
break
|
|
|
|
|
except Exception:
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
else:
|
|
|
|
|
print('❌ CouchDB n\'est pas joignable')
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
print('🚀 Vérification de la configuration...')
|
|
|
|
|
try:
|
|
|
|
|
dbs = requests.get(f'{COUCHDB_URL}/_all_dbs', auth=(USER, PASSWORD))
|
|
|
|
|
if dbs.ok and '_users' in dbs.json():
|
|
|
|
|
print('✅ CouchDB déjà initialisé.')
|
|
|
|
|
exit(0)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
print('🛠 Initialisation du mode single-node...')
|
|
|
|
|
payload = {
|
|
|
|
|
"action": "enable_single_node",
|
|
|
|
|
"username": USER,
|
|
|
|
|
"password": PASSWORD,
|
|
|
|
|
"bind_address": "0.0.0.0"
|
|
|
|
|
}
|
2025-10-15 23:33:08 +02:00
|
|
|
r1 = requests.post(f'{COUCHDB_URL}/_cluster_setup', auth=(USER, PASSWORD), json=payload)
|
2025-10-15 07:30:31 +02:00
|
|
|
|
2025-10-15 23:33:08 +02:00
|
|
|
if r1.ok:
|
2025-10-15 07:30:31 +02:00
|
|
|
print('✅ CouchDB initialisé avec succès.')
|
|
|
|
|
else:
|
2025-10-15 23:33:08 +02:00
|
|
|
print('❌ Erreur lors de l\'initialisation :', r1.text)
|