Skip to content
Snippets Groups Projects
Commit 66d7dbf2 authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Utilize rc_util

parent ff962a25
No related branches found
No related tags found
6 merge requests!147Merge previous default branch feat-cod-rmq into main,!85kill nginx process running under user from login node,!51Fix acct create wait,!39WIP:Feat cod rmq,!38WIP: Feat cod rmq,!22Feat dir verify agent
...@@ -2,12 +2,16 @@ ...@@ -2,12 +2,16 @@
import sys import sys
import json import json
import shutil import shutil
import rc_util
from pathlib import Path from pathlib import Path
from rc_rmq import RCRMQ from rc_rmq import RCRMQ
task = 'dir_verify' task = 'dir_verify'
dirs = ['/home', '/data/user', '/data/scratch'] dirs = ['/home', '/data/user', '/data/scratch']
args = rc_util.get_args()
logger = rc_util.get_logger(args)
# Instantiate rabbitmq object # Instantiate rabbitmq object
rc_rmq = RCRMQ({'exchange': 'RegUsr', 'exchange_type': 'topic'}) rc_rmq = RCRMQ({'exchange': 'RegUsr', 'exchange_type': 'topic'})
...@@ -20,16 +24,23 @@ def dir_verify(ch, method, properties, body): ...@@ -20,16 +24,23 @@ def dir_verify(ch, method, properties, body):
for d in dirs: for d in dirs:
path = Path(d) / msg['username'] path = Path(d) / msg['username']
if not path.exists(): if args.dry_run:
# Make sure folder exists and with right permission logger.info(f'Checking dirs: {path}')
path.mkdir(mode=0o700)
else:
if not path.exists():
# Make sure folder exists and with right permission
path.mkdir(mode=0o700)
# Make sure ownership is correct
shutil.chown(path, msg['uid'], msg['gid'])
logger.debug(f'{path} created')
# Make sure ownership is correct
shutil.chown(path, msg['uid'], msg['gid'])
success = True success = True
except:
e = sys.exc_info()[0] except Exception as exception:
print("[{}]: Error: {}".format(task, e)) logger.error('', exc_info=True)
# send confirm message # send confirm message
rc_rmq.publish_msg({ rc_rmq.publish_msg({
...@@ -40,12 +51,15 @@ def dir_verify(ch, method, properties, body): ...@@ -40,12 +51,15 @@ def dir_verify(ch, method, properties, body):
} }
}) })
logger.debug(f'User {username} confirmation sent')
print("Start listening to queue: {}".format(task)) logger.info(f'Start listening to queue: {task}')
rc_rmq.start_consume({ rc_rmq.start_consume({
'queue': task, 'queue': task,
'routing_key': "verify.*", 'routing_key': "verify.*",
'cb': dir_verify 'cb': dir_verify
}) })
logger.info('Disconnected')
rc_rmq.disconnect() rc_rmq.disconnect()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment