forked from mvberg/ib-gateway-docker
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrestart-docker-vm.py
More file actions
25 lines (20 loc) · 1010 Bytes
/
restart-docker-vm.py
File metadata and controls
25 lines (20 loc) · 1010 Bytes
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
import os
import signal
import subprocess
from supervisor import childutils
### This script will clear out temp and encrypted IB log locations before restarting the container, when Supervisor gets a stopped state from IB
# Taken from here: https://stackoverflow.com/questions/28175011/supervisor-docker-how-to-exit-supervisor-if-a-service-doesnt-start
def main():
while True:
headers, payload = childutils.listener.wait()
childutils.listener.ok()
if headers['eventname'] != 'PROCESS_STATE_FATAL':
continue
print("Clearing out temp space")
subprocess.run(["tmpreaper", "--all", "--showdeleted", "--force", "1h", "/tmp"], capture_output=True)
print("Emptying log directories")
subprocess.run(["find", "./myfolder", "-mindepth", "1", "!", "-regex", "'^/root/Jts/ibgateway\(/.*\)?'", "-delete"], capture_output=True)
print("Killing supervisor")
os.kill(os.getppid(), signal.SIGTERM)
if __name__ == "__main__":
main()