|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /proc/self/root/opt/alt-old/python37/lib/python3.7/site-packages/clwpos/ |
Upload File : |
#!/opt/alt/python37/bin/python3 -bb
# -*- coding: utf-8 -*-
# clwposcron Utility to scan domains for Cloudlinux WPOS requirements by cron
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
# pylint: disable=no-absolute-import
# import sys
import os
import time
import subprocess
class CloudlinuxWposReqScanner(object):
"""
Class for run clwposcron functionality
"""
TIMEOUT_24H_SECONDS = 24 * 3600
def __init__(self):
self._file_flag_force_check = '/var/lve/clwpos/cl_wpos_scan_req_force'
self._scan_req_scan_last_ts = '/var/lve/clwpos/cl_wpos_scan_req_last_ts'
def run(self):
"""
Run command action
"""
if not os.path.exists(self._file_flag_force_check):
# force start flag file absent, check 24h timeout
ts_now = time.time()
if os.path.exists(self._scan_req_scan_last_ts):
try:
with open(self._scan_req_scan_last_ts, 'r') as f:
s_last_ts = f.read()
last_ts = float(s_last_ts)
except (OSError, IOError, ValueError):
last_ts = 0
if ts_now - last_ts < self.TIMEOUT_24H_SECONDS:
# 24h not passed from last run this script - do nothing
return
# timestamp file old/absent, create it
with open(self._scan_req_scan_last_ts, 'w') as f:
f.write(str(ts_now))
else:
# Force start
try:
os.remove(self._file_flag_force_check)
except (OSError, IOError):
pass
# Run file generation
# TODO: Remove try/except in LU-2453
try:
# /usr/bin/clwpos-admin generate-report --all --quiet
subprocess.Popen(['/usr/bin/clwpos-admin', 'generate-report', '--all', '--quiet'],
shell=False,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except (OSError, IOError):
pass
return 0