This repository was archived by the owner on Apr 7, 2026. It is now read-only.
forked from Charcoal-SE/SmokeDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnocrash.py
More file actions
executable file
·110 lines (87 loc) · 2.93 KB
/
nocrash.py
File metadata and controls
executable file
·110 lines (87 loc) · 2.93 KB
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
#!/usr/bin/python
# This script replaces the original nocrash.sh functionality with a pure Python approach.
from sh import git
import os
import subprocess as sp
from time import sleep
import sys
from debugging import Debugging
# Get environment variables
ChatExchangeU = os.environ.get('ChatExchangeU')
ChatExchangeP = os.environ.get('ChatExchangeP')
if ChatExchangeU is None:
ChatExchangeU = str(input("Username: ")).strip('\r\n')
os.environ['CEU'] = "h"
if ChatExchangeP is None:
ChatExchangeP = str(input("Password: ")).strip('\r\n')
persistent_arguments = list({"charcoal-hq-only"} & set(sys.argv))
count = 0
crashcount = 0
stoprunning = False
switch_to_standby = False
ecode = None # Define this to prevent errors
# Make a clean copy of existing environment variables, to pass down to subprocess.
environ = os.environ.copy()
# Add debug environment variables to environment copy in variable 'environ', if Debugging is enabled
if Debugging.enabled:
for (key, value) in Debugging.environ_dict.iteritems():
environ[key] = str(value)
while stoprunning is False:
# print "[NoCrash] Switch to Standby? %s" % switch_to_standby
if count == 0:
if switch_to_standby or ("standby" in sys.argv):
switch_to_standby = False # Necessary for the while loop
command = 'python ws.py standby'.split()
else:
command = 'python ws.py first_start'.split()
else:
if not switch_to_standby:
command = 'python ws.py'.split()
else:
switch_to_standby = False
command = 'python ws.py standby'.split()
try:
ecode = sp.call(command + persistent_arguments, env=environ)
except KeyboardInterrupt:
# print "[NoCrash] KeyBoard Interrupt received.."
ecode = 6
if ecode == 3:
# print "[NoCrash] Pull in new updates."
git.checkout('deploy')
git.pull()
git.submodule('update')
count = 0
crashcount = 0
elif ecode == 4:
# print "[NoCrash] Crashed."
count += 1
sleep(5)
if crashcount == 2:
# print "[NoCrash] Going to reverted state."
git.checkout('HEAD~1')
count = 0
crashcount = 0
else:
crashcount += 1
elif ecode == 5:
# print "[NoCrash] Rebooting."
count = 0
elif ecode == 6:
# print "[NoCrash] Stopping"
stoprunning = True
elif ecode == 7:
# print "[NoCrash] Go to Standby Restart Called"
switch_to_standby = True
elif ecode == 8:
# print "[NoCrash] Checkout Deploy"
git.checkout('deploy')
count = 0
crashcount = 0
elif ecode == 10:
# print "[NoCrash] Socket failure, let network settle before restart."
sleep(5)
count = 0
else:
# print "[NoCrash] Died by unknown reason, check logs; restarting in 5 seconds."
sleep(5)
count += 1