@@ -78,6 +78,10 @@ class BatchSpawnerBase(Spawner):
7878 # override default server ip since batch jobs normally running remotely
7979 ip = Unicode ("0.0.0.0" , help = "Address for singleuser server to listen at" ).tag (config = True )
8080
81+ exec_prefix = Unicode ('sudo -E -u {username}' , \
82+ help = "Standard executon prefix (e.g. the default sudo -E -u {username})"
83+ ).tag (config = True )
84+
8185 # all these req_foo traits will be available as substvars for templated strings
8286 req_queue = Unicode ('' , \
8387 help = "Queue name to submit job to resource manager"
@@ -205,7 +209,8 @@ def run_command(self, cmd, input=None, env=None):
205209 @gen .coroutine
206210 def submit_batch_script (self ):
207211 subvars = self .get_req_subvars ()
208- cmd = format_template (self .batch_submit_cmd , ** subvars )
212+ cmd = self .exec_prefix + ' ' + self .batch_submit_cmd
213+ cmd = format_template (cmd , ** subvars )
209214 subvars ['cmd' ] = self .cmd_formatted_for_batch ()
210215 if hasattr (self , 'user_options' ):
211216 subvars .update (self .user_options )
@@ -235,7 +240,8 @@ def read_job_state(self):
235240 return self .job_status
236241 subvars = self .get_req_subvars ()
237242 subvars ['job_id' ] = self .job_id
238- cmd = format_template (self .batch_query_cmd , ** subvars )
243+ cmd = self .exec_prefix + ' ' + self .batch_query_cmd
244+ cmd = format_template (cmd , ** subvars )
239245 self .log .debug ('Spawner querying job: ' + cmd )
240246 try :
241247 out = yield self .run_command (cmd )
@@ -254,7 +260,8 @@ def read_job_state(self):
254260 def cancel_batch_job (self ):
255261 subvars = self .get_req_subvars ()
256262 subvars ['job_id' ] = self .job_id
257- cmd = format_template (self .batch_cancel_cmd , ** subvars )
263+ cmd = self .exec_prefix + ' ' + self .batch_cancel_cmd
264+ cmd = format_template (cmd , ** subvars )
258265 self .log .info ('Cancelling job ' + self .job_id + ': ' + cmd )
259266 yield self .run_command (cmd )
260267
@@ -448,21 +455,21 @@ class TorqueSpawner(BatchSpawnerRegexStates):
448455""" ).tag (config = True )
449456
450457 # outputs job id string
451- batch_submit_cmd = Unicode ('sudo -E -u {username} qsub' ).tag (config = True )
458+ batch_submit_cmd = Unicode ('qsub' ).tag (config = True )
452459 # outputs job data XML string
453- batch_query_cmd = Unicode ('sudo -E -u {username} qstat -x {job_id}' ).tag (config = True )
454- batch_cancel_cmd = Unicode ('sudo -E -u {username} qdel {job_id}' ).tag (config = True )
460+ batch_query_cmd = Unicode ('qstat -x {job_id}' ).tag (config = True )
461+ batch_cancel_cmd = Unicode ('qdel {job_id}' ).tag (config = True )
455462 # search XML string for job_state - [QH] = pending, R = running, [CE] = done
456463 state_pending_re = Unicode (r'<job_state>[QH]</job_state>' ).tag (config = True )
457464 state_running_re = Unicode (r'<job_state>R</job_state>' ).tag (config = True )
458465 state_exechost_re = Unicode (r'<exec_host>((?:[\w_-]+\.?)+)/\d+' ).tag (config = True )
459466
460467class MoabSpawner (TorqueSpawner ):
461468 # outputs job id string
462- batch_submit_cmd = Unicode ('sudo -E -u {username} msub' ).tag (config = True )
469+ batch_submit_cmd = Unicode ('msub' ).tag (config = True )
463470 # outputs job data XML string
464- batch_query_cmd = Unicode ('sudo -E -u {username} mdiag -j {job_id} --xml' ).tag (config = True )
465- batch_cancel_cmd = Unicode ('sudo -E -u {username} mjobctl -c {job_id}' ).tag (config = True )
471+ batch_query_cmd = Unicode ('mdiag -j {job_id} --xml' ).tag (config = True )
472+ batch_cancel_cmd = Unicode ('mjobctl -c {job_id}' ).tag (config = True )
466473 state_pending_re = Unicode (r'State="Idle"' ).tag (config = True )
467474 state_running_re = Unicode (r'State="Running"' ).tag (config = True )
468475 state_exechost_re = Unicode (r'AllocNodeList="([^\r\n\t\f :"]*)' ).tag (config = True )
@@ -520,10 +527,10 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
520527{{epilogue}}
521528""" ).tag (config = True )
522529 # outputs line like "Submitted batch job 209"
523- batch_submit_cmd = Unicode ('sudo -E -u {username} sbatch --parsable' ).tag (config = True )
530+ batch_submit_cmd = Unicode ('sbatch --parsable' ).tag (config = True )
524531 # outputs status and exec node like "RUNNING hostname"
525- batch_query_cmd = Unicode ("sudo -E -u {username} squeue -h -j {job_id} -o '%T %B'" ).tag (config = True ) #
526- batch_cancel_cmd = Unicode ('sudo -E -u {username} scancel {job_id}' ).tag (config = True )
532+ batch_query_cmd = Unicode ("squeue -h -j {job_id} -o '%T %B'" ).tag (config = True ) #
533+ batch_cancel_cmd = Unicode ('scancel {job_id}' ).tag (config = True )
527534 # use long-form states: PENDING, CONFIGURING = pending
528535 # RUNNING, COMPLETING = running
529536 state_pending_re = Unicode (r'^(?:PENDING|CONFIGURING)' ).tag (config = True )
@@ -565,10 +572,10 @@ class GridengineSpawner(BatchSpawnerBase):
565572""" ).tag (config = True )
566573
567574 # outputs job id string
568- batch_submit_cmd = Unicode ('sudo -E -u {username} qsub' ).tag (config = True )
575+ batch_submit_cmd = Unicode ('qsub' ).tag (config = True )
569576 # outputs job data XML string
570- batch_query_cmd = Unicode ('sudo -E -u {username} qstat -xml' ).tag (config = True )
571- batch_cancel_cmd = Unicode ('sudo -E -u {username} qdel {job_id}' ).tag (config = True )
577+ batch_query_cmd = Unicode ('qstat -xml' ).tag (config = True )
578+ batch_cancel_cmd = Unicode ('qdel {job_id}' ).tag (config = True )
572579
573580 def parse_job_id (self , output ):
574581 return output .split (' ' )[2 ]
@@ -615,10 +622,10 @@ class CondorSpawner(UserEnvMixin,BatchSpawnerRegexStates):
615622""" ).tag (config = True )
616623
617624 # outputs job id string
618- batch_submit_cmd = Unicode ('sudo -E -u {username} condor_submit' ).tag (config = True )
625+ batch_submit_cmd = Unicode ('condor_submit' ).tag (config = True )
619626 # outputs job data XML string
620627 batch_query_cmd = Unicode ('condor_q {job_id} -format "%s, " JobStatus -format "%s" RemoteHost -format "\n " True' ).tag (config = True )
621- batch_cancel_cmd = Unicode ('sudo -E -u {username} condor_rm {job_id}' ).tag (config = True )
628+ batch_cancel_cmd = Unicode ('condor_rm {job_id}' ).tag (config = True )
622629 # job status: 1 = pending, 2 = running
623630 state_pending_re = Unicode (r'^1,' ).tag (config = True )
624631 state_running_re = Unicode (r'^2,' ).tag (config = True )
@@ -651,9 +658,9 @@ class LsfSpawner(BatchSpawnerBase):
651658 ''' ).tag (config = True )
652659
653660
654- batch_submit_cmd = Unicode ('sudo -E -u {username} bsub' ).tag (config = True )
655- batch_query_cmd = Unicode ('sudo -E -u {username} bjobs -a -noheader -o "STAT EXEC_HOST" {job_id}' ).tag (config = True )
656- batch_cancel_cmd = Unicode ('sudo -E -u {username} bkill {job_id}' ).tag (config = True )
661+ batch_submit_cmd = Unicode ('bsub' ).tag (config = True )
662+ batch_query_cmd = Unicode ('bjobs -a -noheader -o "STAT EXEC_HOST" {job_id}' ).tag (config = True )
663+ batch_cancel_cmd = Unicode ('bkill {job_id}' ).tag (config = True )
657664
658665 def get_env (self ):
659666 env = super ().get_env ()
0 commit comments