Mini Shell
Direktori : /proc/self/root/sbin/ |
|
Current File : //proc/self/root/sbin/pamsock_ready_check |
#!/opt/imunify360/venv/bin/python3
#
# Wait for PAM socket is ready
#
import socket as s
import sys
import time
from pam_i360.internals import (CONFIG,
pam_imunify_config,
logger_init)
PAMSOCK_PATH = '/opt/i360_pam_imunify/pam_imunify360.sock'
DELAY = 1
TIMEOUT_DEFAULT = 120
logger = logger_init()
if __name__ == '__main__':
pamsock = s.socket(s.AF_UNIX, s.SOCK_STREAM)
t0 = time.time()
try:
timeout = float(pam_imunify_config()['socket_readycheck_timeout'])
except KeyError:
timeout = TIMEOUT_DEFAULT
except ValueError as e:
timeout = TIMEOUT_DEFAULT
logger.error("%s 'socket_readycheck_timeout=...' key parsing error: %s",
CONFIG,
e)
while True:
try:
pamsock.connect(PAMSOCK_PATH)
except (ConnectionRefusedError, FileNotFoundError) as e:
logger.info("Waiting for PAM to start (%s)", e)
if time.time() >= t0 + timeout:
break
time.sleep(DELAY)
else:
logger.info("PAM socket is ready.")
sys.exit(0)
logger.error("Failed to connect PAM socket in time.")
sys.exit(1)
Zerion Mini Shell 1.0