@@ -90,6 +90,10 @@ class BatchSpawnerBase(Spawner):
9090 # override default server ip since batch jobs normally running remotely
9191 ip = Unicode ("0.0.0.0" , help = "Address for singleuser server to listen at" ).tag (config = True )
9292
93+ exec_prefix = Unicode ('sudo -E -u {username}' , \
94+ help = "Standard executon prefix (e.g. the default sudo -E -u {username})"
95+ ).tag (config = True )
96+
9397 # all these req_foo traits will be available as substvars for templated strings
9498 req_queue = Unicode ('' , \
9599 help = "Queue name to submit job to resource manager"
@@ -177,7 +181,8 @@ def cmd_formatted_for_batch(self):
177181 @gen .coroutine
178182 def submit_batch_script (self ):
179183 subvars = self .get_req_subvars ()
180- cmd = self .batch_submit_cmd .format (** subvars )
184+ cmd = self .exec_prefix + ' ' + self .batch_submit_cmd
185+ cmd = cmd .format (** subvars )
181186 subvars ['cmd' ] = self .cmd_formatted_for_batch ()
182187 if hasattr (self , 'user_options' ):
183188 subvars .update (self .user_options )
@@ -207,7 +212,8 @@ def read_job_state(self):
207212 return self .job_status
208213 subvars = self .get_req_subvars ()
209214 subvars ['job_id' ] = self .job_id
210- cmd = self .batch_query_cmd .format (** subvars )
215+ cmd = self .exec_prefix + ' ' + self .batch_query_cmd
216+ cmd = cmd .format (** subvars )
211217 self .log .debug ('Spawner querying job: ' + cmd )
212218 try :
213219 out = yield run_command (cmd )
@@ -226,7 +232,8 @@ def read_job_state(self):
226232 def cancel_batch_job (self ):
227233 subvars = self .get_req_subvars ()
228234 subvars ['job_id' ] = self .job_id
229- cmd = self .batch_cancel_cmd .format (** subvars )
235+ cmd = self .exec_prefix + ' ' + self .batch_cancel_cmd
236+ cmd = cmd .format (** subvars )
230237 self .log .info ('Cancelling job ' + self .job_id + ': ' + cmd )
231238 yield run_command (cmd )
232239
@@ -420,21 +427,21 @@ class TorqueSpawner(BatchSpawnerRegexStates):
420427""" ).tag (config = True )
421428
422429 # outputs job id string
423- batch_submit_cmd = Unicode ('sudo -E -u {username} qsub' ).tag (config = True )
430+ batch_submit_cmd = Unicode ('qsub' ).tag (config = True )
424431 # outputs job data XML string
425- batch_query_cmd = Unicode ('sudo -E -u {username} qstat -x {job_id}' ).tag (config = True )
426- batch_cancel_cmd = Unicode ('sudo -E -u {username} qdel {job_id}' ).tag (config = True )
432+ batch_query_cmd = Unicode ('qstat -x {job_id}' ).tag (config = True )
433+ batch_cancel_cmd = Unicode ('qdel {job_id}' ).tag (config = True )
427434 # search XML string for job_state - [QH] = pending, R = running, [CE] = done
428435 state_pending_re = Unicode (r'<job_state>[QH]</job_state>' ).tag (config = True )
429436 state_running_re = Unicode (r'<job_state>R</job_state>' ).tag (config = True )
430437 state_exechost_re = Unicode (r'<exec_host>((?:[\w_-]+\.?)+)/\d+' ).tag (config = True )
431438
432439class MoabSpawner (TorqueSpawner ):
433440 # outputs job id string
434- batch_submit_cmd = Unicode ('sudo -E -u {username} msub' ).tag (config = True )
441+ batch_submit_cmd = Unicode ('msub' ).tag (config = True )
435442 # outputs job data XML string
436- batch_query_cmd = Unicode ('sudo -E -u {username} mdiag -j {job_id} --xml' ).tag (config = True )
437- batch_cancel_cmd = Unicode ('sudo -E -u {username} mjobctl -c {job_id}' ).tag (config = True )
443+ batch_query_cmd = Unicode ('mdiag -j {job_id} --xml' ).tag (config = True )
444+ batch_cancel_cmd = Unicode ('mjobctl -c {job_id}' ).tag (config = True )
438445 state_pending_re = Unicode (r'State="Idle"' ).tag (config = True )
439446 state_running_re = Unicode (r'State="Running"' ).tag (config = True )
440447 state_exechost_re = Unicode (r'AllocNodeList="([^\r\n\t\f :"]*)' ).tag (config = True )
@@ -487,10 +494,10 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
487494{cmd}
488495""" ).tag (config = True )
489496 # outputs line like "Submitted batch job 209"
490- batch_submit_cmd = Unicode ('sudo -E -u {username} sbatch --parsable' ).tag (config = True )
497+ batch_submit_cmd = Unicode ('sbatch --parsable' ).tag (config = True )
491498 # outputs status and exec node like "RUNNING hostname"
492- batch_query_cmd = Unicode ("sudo -E -u {username} squeue -h -j {job_id} -o '%T %B'" ).tag (config = True ) #
493- batch_cancel_cmd = Unicode ('sudo -E -u {username} scancel {job_id}' ).tag (config = True )
499+ batch_query_cmd = Unicode ("squeue -h -j {job_id} -o '%T %B'" ).tag (config = True ) #
500+ batch_cancel_cmd = Unicode ('scancel {job_id}' ).tag (config = True )
494501 # use long-form states: PENDING, CONFIGURING = pending
495502 # RUNNING, COMPLETING = running
496503 state_pending_re = Unicode (r'^(?:PENDING|CONFIGURING)' ).tag (config = True )
@@ -532,10 +539,10 @@ class GridengineSpawner(BatchSpawnerBase):
532539""" ).tag (config = True )
533540
534541 # outputs job id string
535- batch_submit_cmd = Unicode ('sudo -E -u {username} qsub' ).tag (config = True )
542+ batch_submit_cmd = Unicode ('qsub' ).tag (config = True )
536543 # outputs job data XML string
537- batch_query_cmd = Unicode ('sudo -E -u {username} qstat -xml' ).tag (config = True )
538- batch_cancel_cmd = Unicode ('sudo -E -u {username} qdel {job_id}' ).tag (config = True )
544+ batch_query_cmd = Unicode ('qstat -xml' ).tag (config = True )
545+ batch_cancel_cmd = Unicode ('qdel {job_id}' ).tag (config = True )
539546
540547 def parse_job_id (self , output ):
541548 return output .split (' ' )[2 ]
@@ -582,10 +589,10 @@ class CondorSpawner(UserEnvMixin,BatchSpawnerRegexStates):
582589""" ).tag (config = True )
583590
584591 # outputs job id string
585- batch_submit_cmd = Unicode ('sudo -E -u {username} condor_submit' ).tag (config = True )
592+ batch_submit_cmd = Unicode ('condor_submit' ).tag (config = True )
586593 # outputs job data XML string
587594 batch_query_cmd = Unicode ('condor_q {job_id} -format "%s, " JobStatus -format "%s" RemoteHost -format "\n " True' ).tag (config = True )
588- batch_cancel_cmd = Unicode ('sudo -E -u {username} condor_rm {job_id}' ).tag (config = True )
595+ batch_cancel_cmd = Unicode ('condor_rm {job_id}' ).tag (config = True )
589596 # job status: 1 = pending, 2 = running
590597 state_pending_re = Unicode (r'^1,' ).tag (config = True )
591598 state_running_re = Unicode (r'^2,' ).tag (config = True )
@@ -618,9 +625,9 @@ class LsfSpawner(BatchSpawnerBase):
618625 ''' ).tag (config = True )
619626
620627
621- batch_submit_cmd = Unicode ('sudo -E -u {username} bsub' ).tag (config = True )
622- batch_query_cmd = Unicode ('sudo -E -u {username} bjobs -a -noheader -o "STAT EXEC_HOST" {job_id}' ).tag (config = True )
623- batch_cancel_cmd = Unicode ('sudo -E -u {username} bkill {job_id}' ).tag (config = True )
628+ batch_submit_cmd = Unicode ('bsub' ).tag (config = True )
629+ batch_query_cmd = Unicode ('bjobs -a -noheader -o "STAT EXEC_HOST" {job_id}' ).tag (config = True )
630+ batch_cancel_cmd = Unicode ('bkill {job_id}' ).tag (config = True )
624631
625632 def get_env (self ):
626633 env = super ().get_env ()
0 commit comments