@@ -265,6 +265,7 @@ def read_locals(self) -> dict:
265265 if not node :
266266 raise FatalException (f'No configuration found for node { self .name } in { config_file } !' )
267267 dirty = False
268+
268269 # check if we need to secure the database URL
269270 database_url = node .get ('database' , {}).get ('url' )
270271 if database_url :
@@ -276,6 +277,16 @@ def read_locals(self) -> dict:
276277 f"{ url .scheme } ://{ url .username } :SECRET@{ url .hostname } :{ port } { url .path } ?sslmode=prefer"
277278 dirty = True
278279 self .log .info ("Database password found, removing it from config." )
280+ else :
281+ # if we have a cluster.pkl, rename that
282+ cluserdb_pkl = os .path .join (self .config_dir , '.secret' , 'clusterdb.pkl' )
283+ if os .path .exists (cluserdb_pkl ):
284+ database_pkl = os .path .join (self .config_dir , '.secret' , 'database.pkl' )
285+ # remove existing target to ensure a clean move
286+ if os .path .exists (database_pkl ):
287+ os .remove (database_pkl )
288+ os .replace (cluserdb_pkl , database_pkl )
289+
279290 if 'DCS' in node :
280291 password = node ['DCS' ].pop ('dcs_password' , node ['DCS' ].pop ('password' , None ))
281292 if password :
@@ -310,18 +321,28 @@ async def check_db(url: str) -> str | None:
310321
311322 cpool_url = self .config .get ("database" , self .locals .get ('database' ))['url' ]
312323 lpool_url = self .locals .get ("database" , self .config .get ('database' ))['url' ]
324+
313325 try :
314- password = utils .get_password ('clusterdb ' , self .config_dir )
326+ lpool_pwd = utils .get_password ('database ' , self .config_dir )
315327 except ValueError :
328+ self .log .critical (
329+ "Please replace the SECRET keyword in your database URL with a password!"
330+ )
331+ exit (SHUTDOWN )
332+
333+ if cpool_url != lpool_url :
316334 try :
317- password = utils .get_password ('database' , self .config_dir )
318- utils .set_password ('clusterdb' , password , self .config_dir )
335+ cpool_pwd = utils .get_password ('clusterdb' , self .config_dir )
319336 except ValueError :
320- self .log .critical ("You need to replace the SECRET keyword in your database URL with a proper password!" )
337+ self .log .critical (
338+ "Please replace the SECRET keyword in your database URL in main.yaml with a password!"
339+ )
321340 exit (SHUTDOWN )
341+ else :
342+ cpool_pwd = lpool_pwd
322343
323- cpool_url = cpool_url .replace ('SECRET' , quote (password ) or '' )
324- lpool_url = lpool_url .replace ('SECRET' , quote (utils . get_password ( 'database' , self . config_dir ) ) or '' )
344+ cpool_url = cpool_url .replace ('SECRET' , quote (cpool_pwd ) or '' )
345+ lpool_url = lpool_url .replace ('SECRET' , quote (lpool_pwd ) or '' )
325346
326347 version = await check_db (lpool_url )
327348 if lpool_url != cpool_url :
@@ -1026,6 +1047,7 @@ async def check_nodes():
10261047 return True
10271048 # The master is not alive, take over
10281049 elif not master or not await is_node_alive (master , config .get ('heartbeat' , 30 )):
1050+ self .log .warning ("The master node is not responding, taking over ..." )
10291051 await take_over ()
10301052 return True
10311053 # Master is alive, but we are the preferred one
0 commit comments