41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
|
|
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"
|
||
|
|
}
|
||
|
|
r1 = requests.post(f'{COUCHDB_URL}/_cluster_setup', json=payload)
|
||
|
|
r2 = requests.post(f'{COUCHDB_URL}/_cluster_setup', json={"action": "finish_cluster"})
|
||
|
|
|
||
|
|
if r1.ok and r2.ok:
|
||
|
|
print('✅ CouchDB initialisé avec succès.')
|
||
|
|
else:
|
||
|
|
print('❌ Erreur lors de l\'initialisation :', r1.text, r2.text)
|