Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/227420

Change subject: labstore: Daemonize create-dbusers
......................................................................

labstore: Daemonize create-dbusers

- Runs every 60s
- Runs only for toollabs users
- Does not recover from crashes automatically! Need monitoring
  to alert whenever it crashes, however - will be added in a
  followup patch

Change-Id: Ifb81756974d2cfc83520dcbf232e005b619d9eef
---
M modules/labstore/files/create-dbusers
1 file changed, 26 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/20/227420/1

diff --git a/modules/labstore/files/create-dbusers 
b/modules/labstore/files/create-dbusers
index 244deda..e54ca3a 100755
--- a/modules/labstore/files/create-dbusers
+++ b/modules/labstore/files/create-dbusers
@@ -22,6 +22,7 @@
 import random
 import configparser
 import io
+import time
 
 
 class User:
@@ -138,12 +139,14 @@
 
 
 if __name__ == '__main__':
-    PROJECTS = ['tools']
-
     argparser = argparse.ArgumentParser()
     argparser.add_argument('--config', help='Path to YAML config file')
     argparser.add_argument('--debug', help='Turn on debug logging',
                            action='store_true')
+    argparser.add_argument('--project', help='Project name to create db users 
for',
+                           default='tools')
+    argparser.add_argument('--delay', help='Number of seconds to wait between 
runs',
+                           default=60)
     args = argparser.parse_args()
 
     logging.basicConfig(format='%(message)s',
@@ -159,26 +162,30 @@
         auto_bind=True,
         password=config['ldap']['password'])
 
-    servicegroups = User.from_ldap_servicegroups(conn, 'tools')
     cgen = CredentialCreator(
         config['mysql']['hosts'],
         config['mysql']['username'],
         config['mysql']['password']
     )
 
-    for sg in servicegroups:
-        # FIXME: for non tools/maps projects this path is different
-        replica_path = os.path.join(
-            '/srv/project/', sg.project, 'project',
-            re.sub(r'^%s\.' % sg.project, '', sg.name),
-            'replica.my.cnf'
-        )
-        if not os.path.exists(replica_path):
-            if not cgen.check_user_exists(sg):
-                # No replica.my.cnf and no user in db
-                # Generate new creds and put them in there!
-                logging.info('Creating DB accounts for %s with db username 
%s', sg.name, sg.db_username)
-                cgen.write_credentials_file(replica_path, sg)
-                logging.info("Created replica.my.cnf for %s, with username 
%s", sg.name, sg.db_username)
-            else:
-                logging.info('Missing replica.my.cnf for user %s despite 
grants present in db', sg.name)
+    while True:
+        logging.info('Starting createdb-users run')
+        servicegroups = User.from_ldap_servicegroups(conn, args.project)
+        for sg in servicegroups:
+            # FIXME: for non tools/maps projects this path is different
+            replica_path = os.path.join(
+                '/srv/project/', sg.project, 'project',
+                re.sub(r'^%s\.' % sg.project, '', sg.name),
+                'replica.my.cnf'
+            )
+            if not os.path.exists(replica_path):
+                if not cgen.check_user_exists(sg):
+                    # No replica.my.cnf and no user in db
+                    # Generate new creds and put them in there!
+                    logging.info('Creating DB accounts for %s with db username 
%s', sg.name, sg.db_username)
+                    cgen.write_credentials_file(replica_path, sg)
+                    logging.info("Created replica.my.cnf for %s, with username 
%s", sg.name, sg.db_username)
+                else:
+                    logging.info('Missing replica.my.cnf for user %s despite 
grants present in db', sg.name)
+        logging.info('Completed createdb-users run')
+        time.sleep(args.delay)

-- 
To view, visit https://gerrit.wikimedia.org/r/227420
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb81756974d2cfc83520dcbf232e005b619d9eef
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Yuvipanda <yuvipa...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to