-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.py
122 lines (109 loc) · 4.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from base import *
from utils.logger import *
import plex_debrid_ as p
import zurg as z
from rclone import rclone
from utils import duplicate_cleanup
from utils import auto_update
def shutdown(signum, frame):
logger = get_logger()
logger.info("Shutdown signal received. Cleaning up...")
for mount_point in os.listdir('/data'):
full_path = os.path.join('/data', mount_point)
if os.path.ismount(full_path):
logger.info(f"Unmounting {full_path}...")
umount = subprocess.run(['umount', full_path], capture_output=True, text=True)
if umount.returncode == 0:
logger.info(f"Successfully unmounted {full_path}")
else:
logger.error(f"Failed to unmount {full_path}: {umount.stderr.strip()}")
sys.exit(0)
def main():
logger = get_logger()
version = '2.9.1'
ascii_art = f'''
_______ ______ _______ _______ _______
( ____ )( __ \\ / ___ )|\\ /|( ____ )( ____ \\
| ( )|| ( \\ ) \\/ ) || ) ( || ( )|| ( \\/
| (____)|| | ) | / )| | | || (____)|| |
| _____)| | | | / / | | | || __)| | ____
| ( | | ) | / / | | | || (\\ ( | | \\_ )
| ) | (__/ ) / (_/\\| (___) || ) \\ \\__| (___) |
|/ (______/_____(_______/(_______)|/ \\__/(_______)
(_____)
Version: {version}
'''
logger.info(ascii_art.format(version=version) + "\n" + "\n")
def healthcheck():
while True:
time.sleep(10)
try:
result = subprocess.run(['python', 'healthcheck.py'], capture_output=True, text=True)
if result.stderr:
logger.error(result.stderr.strip())
except Exception as e:
logger.error('Error running healthcheck.py: %s', e)
time.sleep(50)
thread = threading.Thread(target=healthcheck)
thread.daemon = True
thread.start()
try:
if ZURG is None or str(ZURG).lower() == 'false':
pass
elif str(ZURG).lower() == 'true':
try:
if RDAPIKEY or ADAPIKEY:
try:
z.setup.zurg_setup()
z_updater = z.update.ZurgUpdate()
if ZURGUPDATE:
z_updater.auto_update('Zurg',True)
else:
z_updater.auto_update('Zurg',False)
except Exception as e:
raise Exception(f"Error in Zurg setup: {e}")
try:
if RCLONEMN:
try:
if not DUPECLEAN:
pass
elif DUPECLEAN:
duplicate_cleanup.setup()
rclone.setup()
except Exception as e:
logger.error(e)
except Exception as e:
raise Exception(f"Error in setup: {e}")
else:
raise MissingAPIKeyException()
except Exception as e:
logger.error(e)
except Exception as e:
logger.error(e)
try:
if PLEXDEBRID is None or str(PLEXDEBRID).lower() == 'false':
pass
elif str(PLEXDEBRID).lower() == 'true':
try:
p.setup.pd_setup()
pd_updater = p.update.PlexDebridUpdate()
if PDUPDATE and PDREPO:
pd_updater.auto_update('plex_debrid',True)
pass
elif PDREPO:
p.download.get_latest_release()
pd_updater.auto_update('plex_debrid',False)
else:
pd_updater.auto_update('plex_debrid',False)
except Exception as e:
logger.error(f"An error occurred in the plex_debrid setup: {e}")
except:
pass
def perpetual_wait():
stop_event = threading.Event()
stop_event.wait()
perpetual_wait()
if __name__ == "__main__":
signal.signal(signal.SIGTERM, shutdown)
signal.signal(signal.SIGINT, shutdown)
main()