-
Notifications
You must be signed in to change notification settings - Fork 0
/
load
executable file
·55 lines (46 loc) · 1.41 KB
/
load
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
#!/usr/bin/env python3
import os
import sys
import subprocess
import time
def run_cmd(cmd, silent=False):
if silent:
# CRIU shows errors even when it works. Suppress it.
return subprocess.check_call(cmd, shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
else:
return subprocess.check_call(cmd, shell=True)
if not len(sys.argv) == 2:
print('Usage: load savename. View saves with "ls /saves/".')
sys.exit(1)
savename = sys.argv[1]
savedir = savename
if not savedir.startswith('/'):
savedir = '/saves/' + savedir
if not os.path.isdir(savedir):
print('Could not find {} in /saves/.'.format(savename))
sys.exit(1)
# check if tmux is running already
try:
pid = subprocess.check_output(["pidof", "tmux"])
pid = pid.decode("ascii").strip()
except:
pid = None
if pid is not None:
print('Found existing tmux with pid(s): [{}]. Exit or kill that first.'.format(pid))
sys.exit(1)
# load
cmd = 'criu restore --images-dir {} &'.format(savedir)
run_cmd(cmd, silent=True)
try:
time.sleep(0.2)
subprocess.check_output(["pidof", "tmux"])
except:
print("""
Could not load {}.
If this is a new container, run "tmux attach" once before loading.
This will initialize the tmux socket, allowing the load to succeed.
""".format(savename))
sys.exit(1)
print('Loaded {}. Run "tmux attach" to play.'.format(savename))