@@ -41,10 +41,9 @@ def load_plotting_summary():
41
41
except TimeoutExpired :
42
42
proc .kill ()
43
43
proc .communicate ()
44
- abort ( 500 , description = "The timeout is expired! " )
44
+ raise Exception ( "The timeout expired during plotman status. " )
45
45
if errs :
46
- app .logger .error (errs .decode ('utf-8' ))
47
- abort (500 , description = errs .decode ('utf-8' ))
46
+ raise Exception ("Errors during plotman status:\n {0}" .format (errs .decode ('utf-8' )))
48
47
cli_stdout = outs .decode ('utf-8' )
49
48
return plotman .PlottingSummary (cli_stdout .splitlines (), get_plotman_pid ())
50
49
@@ -76,14 +75,16 @@ def action_plots(job):
76
75
#app.logger.info("About to {0} plots: {1}".format(action, plot_ids))
77
76
for plot_id in plot_ids :
78
77
try :
79
- suffix = ""
78
+ param = ""
80
79
if action == "kill" :
81
- suffix = "--force"
80
+ param = "--force"
82
81
logfile = "/root/.chia/plotman/logs/plotman.log"
83
82
log_fd = os .open (logfile , os .O_RDWR | os .O_CREAT )
84
83
log_fo = os .fdopen (log_fd , "a+" )
85
- proc = Popen ("{0} {1} {2} {3}" .format (PLOTMAN_SCRIPT , action , suffix , plot_id ),
84
+ proc = Popen ("{0} {1} {2} {3}" .format (PLOTMAN_SCRIPT , action , param , plot_id ),
86
85
shell = True , universal_newlines = True , stdout = log_fo , stderr = log_fo )
86
+ # Plotman regressed on cleaning temp after kill so do it here:
87
+ clean_tmp_dirs_after_kill (plot_id )
87
88
except :
88
89
app .logger .info ('Failed to {0} selected plot {1}.' .format (action , plot_id ))
89
90
app .logger .info (traceback .format_exc ())
@@ -98,16 +99,12 @@ def get_plotman_pid():
98
99
def start_plotman ():
99
100
app .logger .info ("Starting Plotman run..." )
100
101
check_config ()
101
- try :
102
- if len (load_plotting_summary ().rows ) == 0 : # No plots running
103
- clean_tmp_dirs_before_run ()
104
- logfile = "/root/.chia/plotman/logs/plotman.log"
105
- proc = Popen ("nohup {0} {1} < /dev/tty >> {2} 2>&1 &" .format (PLOTMAN_SCRIPT , 'plot' , logfile ),
106
- shell = True , stdin = DEVNULL , stdout = None , stderr = None , close_fds = True )
107
- app .logger .info ("Completed launch of plotman." )
108
- except :
109
- app .logger .info ('Failed to start Plotman plotting run!' )
110
- app .logger .info (traceback .format_exc ())
102
+ if len (load_plotting_summary ().rows ) == 0 : # No plots running
103
+ clean_tmp_dirs_before_run ()
104
+ logfile = "/root/.chia/plotman/logs/plotman.log"
105
+ proc = Popen ("nohup {0} {1} < /dev/tty >> {2} 2>&1 &" .format (PLOTMAN_SCRIPT , 'plot' , logfile ),
106
+ shell = True , stdin = DEVNULL , stdout = None , stderr = None , close_fds = True )
107
+ app .logger .info ("Completed launch of plotman." )
111
108
112
109
def clean_tmp_dirs_before_run ():
113
110
try :
@@ -126,15 +123,28 @@ def clean_tmp_dirs_before_run():
126
123
p .unlink ()
127
124
except Exception as ex :
128
125
app .logger .info ("Skipping deletion of temp files due to {0}." .format (traceback .format_exc ()))
129
-
126
+
127
+ def clean_tmp_dirs_after_kill (plot_id ):
128
+ try :
129
+ with open ("/root/.chia/plotman/plotman.yaml" ) as f :
130
+ config = yaml .safe_load (f )
131
+ if 'directories' in config :
132
+ if 'tmp' in config ['directories' ]:
133
+ for tmp_dir in config ['directories' ]['tmp' ]:
134
+ for p in pathlib .Path (tmp_dir ).glob ("*{0}*.tmp" .format (plot_id )):
135
+ app .logger .info ("After kill, deleting stale tmp file: {0}" .format (p ))
136
+ p .unlink ()
137
+ if 'tmp2' in config ['directories' ]:
138
+ tmp_dir = config ['directories' ]['tmp2' ]
139
+ for p in pathlib .Path (tmp_dir ).glob ("*{0}*.tmp" .format (plot_id )):
140
+ app .logger .info ("After kill, deleting stale tmp file: {0}" .format (p ))
141
+ p .unlink ()
142
+ except Exception as ex :
143
+ app .logger .info ("Skipping deletion of temp files due to {0}." .format (traceback .format_exc ()))
130
144
131
145
def stop_plotman ():
132
146
app .logger .info ("Stopping Plotman run..." )
133
- try :
134
- os .kill (get_plotman_pid (), signal .SIGTERM )
135
- except :
136
- app .logger .info ('Failed to stop Plotman plotting run!' )
137
- app .logger .info (traceback .format_exc ())
147
+ os .kill (get_plotman_pid (), signal .SIGTERM )
138
148
139
149
def get_archiver_pid ():
140
150
for proc in psutil .process_iter (['pid' , 'name' , 'cmdline' ]):
@@ -145,49 +155,39 @@ def get_archiver_pid():
145
155
def start_archiver ():
146
156
app .logger .info ("Starting archiver run..." )
147
157
check_config ()
148
- try :
149
- logfile = "/root/.chia/plotman/logs/archiver.log"
150
- app .logger .info ("About to start archiver..." )
151
- proc = Popen ("nohup {0} {1} < /dev/tty >> {2} 2>&1 &" .format (PLOTMAN_SCRIPT , 'archive' , logfile ),
152
- shell = True , stdin = DEVNULL , stdout = None , stderr = None , close_fds = True )
153
- app .logger .info ("Completed launch of archiver." )
154
- except :
155
- app .logger .info ('Failed to start Plotman archiving run!' )
156
- app .logger .info (traceback .format_exc ())
158
+ logfile = "/root/.chia/plotman/logs/archiver.log"
159
+ app .logger .info ("About to start archiver..." )
160
+ proc = Popen ("nohup {0} {1} < /dev/tty >> {2} 2>&1 &" .format (PLOTMAN_SCRIPT , 'archive' , logfile ),
161
+ shell = True , stdin = DEVNULL , stdout = None , stderr = None , close_fds = True )
162
+ app .logger .info ("Completed launch of archiver." )
157
163
158
164
def stop_archiver ():
159
165
app .logger .info ("Stopping Archiver run..." )
160
- try :
161
- os .kill (get_archiver_pid (), signal .SIGTERM )
162
- except :
163
- app .logger .info ('Failed to stop Plotman archiving run!' )
164
- app .logger .info (traceback .format_exc ())
166
+ os .kill (get_archiver_pid (), signal .SIGTERM )
165
167
166
168
def load_config ():
167
169
return open ('/root/.chia/plotman/plotman.yaml' ,'r' ).read ()
168
170
169
171
def save_config (config ):
170
- try :
171
- # Validate the YAML first
172
- yaml .safe_load (config )
173
- # Save a copy of the old config file
174
- src = "/root/.chia/plotman/plotman.yaml"
175
- dst = "/root/.chia/plotman/plotman." + \
176
- time .strftime ("%Y%m%d-%H%M%S" )+ ".yaml"
177
- shutil .copy (src , dst )
178
- # Now save the new contents to main config file
179
- with open (src , 'w' ) as writer :
180
- writer .write (config )
181
- except Exception as ex :
182
- app .logger .info (traceback .format_exc ())
183
- raise Exception ('Updated plotman.yaml failed validation!\n ' + str (ex ))
184
- else : # Restart services if running
185
- if get_plotman_pid ():
186
- stop_plotman ()
187
- start_plotman ()
188
- if get_archiver_pid ():
189
- stop_archiver ()
190
- start_archiver ()
172
+ # Validate the YAML first
173
+ yaml .safe_load (config )
174
+ # Save a copy of the old config file
175
+ src = "/root/.chia/plotman/plotman.yaml"
176
+ dst = "/root/.chia/plotman/plotman." + \
177
+ time .strftime ("%Y%m%d-%H%M%S" )+ ".yaml"
178
+ shutil .copy (src , dst )
179
+ # Now save the new contents to main config file
180
+ with open (src , 'w' ) as writer :
181
+ writer .write (config )
182
+ # Now try to validate config by calling plotman status
183
+ load_plotting_summary ()
184
+ # Finally restart plotman and archiver if they are running
185
+ if get_plotman_pid ():
186
+ stop_plotman ()
187
+ start_plotman ()
188
+ if get_archiver_pid ():
189
+ stop_archiver ()
190
+ start_archiver ()
191
191
192
192
def find_plotting_job_log (plot_id ):
193
193
dir_path = '/root/.chia/plotman/logs'
0 commit comments