Commits

Nate Coraor committed 4f12603

Galaxy can now read an environment file before executing jobs on the cluster, useful if your DRM does not give you an easy way to do this directly.

  • Participants
  • Parent commits 2aa9272

Comments (0)

Files changed (5)

lib/galaxy/config.py

         self.drmaa_external_runjob_script = kwargs.get('drmaa_external_runjob_script', None )
         self.drmaa_external_killjob_script = kwargs.get('drmaa_external_killjob_script', None)
         self.external_chown_script = kwargs.get('external_chown_script', None)
-        self.TMPDIR = kwargs.get('TMPDIR', None)
+        self.environment_setup_file = kwargs.get( 'environment_setup_file', None )
         self.use_heartbeat = string_as_bool( kwargs.get( 'use_heartbeat', 'False' ) )
         self.use_memdump = string_as_bool( kwargs.get( 'use_memdump', 'False' ) )
         self.log_actions = string_as_bool( kwargs.get( 'log_actions', 'False' ) )

lib/galaxy/jobs/__init__.py

     def get_session_id( self ):
         return self.session_id
 
+    def get_env_setup_clause( self ):
+        if self.app.config.environment_setup_file is None:
+            return ''
+        return '[ -f "%s" ] && . %s' % ( self.app.config.environment_setup_file, self.app.config.environment_setup_file )
+
     def get_input_dataset_fnames( self,  ds ):
         filenames = []
         filenames = [ ds.file_name ]

lib/galaxy/jobs/runners/drmaa.py

 %s
 cd %s
 %s
-%s
 """
 def __lineno__():
     """Returns the current line number in our program."""
         # external_runJob_script can be None, in which case it's not used.
         self.external_runJob_script = app.config.drmaa_external_runjob_script
         self.external_killJob_script = app.config.drmaa_external_killjob_script
-        self.TMPDIR  =  app.config.TMPDIR
-        self.userid = []
+        self.userid = None
 
     def get_native_spec( self, url ):
         """Get any native DRM arguments specified by the site configuration"""
         native_spec = self.get_native_spec( runner_url )
         if native_spec is not None:
             jt.nativeSpecification = native_spec
-        #set and export galaxy user PATH enviroment to actual user if submitting jobs as actual user
+
+        # fill in the DRM's job run template
+        script = drm_template % ( job_wrapper.galaxy_lib_dir,
+                                  job_wrapper.get_env_setup_clause(),
+                                  os.path.abspath( job_wrapper.working_directory ),
+                                  command_line )
+
         try:
-            if self.external_runJob_script:
-               export_path = 'export PATH=%s:$PATH' %(os.environ['PATH'])
-            else:
-               export_path = ''
+            fh = file( jt.remoteCommand, "w" )
+            fh.write( script )
+            fh.close()
+            os.chmod( jt.remoteCommand, 0755 )
         except:
-            export_path = ''
-        
-        if self.TMPDIR:
-            export_tmp = 'export TMPDIR=%s' %self.TMPDIR
-        else:
-            export_tmp = ''	   
-
-        script = drm_template % ( job_wrapper.galaxy_lib_dir, export_path, os.path.abspath( job_wrapper.working_directory ), export_tmp, command_line )
-
-        fh = file( jt.remoteCommand, "w" )
-        fh.write( script )
-        fh.close()
-        os.chmod( jt.remoteCommand, 0755 )
+            job_wrapper.fail( "failure preparing job script", exception=True )
+            log.exception( "failure running job %s" % job_wrapper.get_id_tag() )
+            return     
 
         # job was deleted while we were preparing it
         if job_wrapper.get_state() == model.Job.states.DELETED:

lib/galaxy/jobs/runners/pbs.py

         export PYTHONPATH="$GALAXY_LIB"
     fi
 fi
+%s
 cd %s
 %s
 """
     [ ! -d $dir ] && mkdir -p $dir
     [ ! -e $dataset ] && ln -s %s/$file $dataset
 done
+%s
 cd %s
 %s
 """
 
         # write the job script
         if self.app.config.pbs_stage_path != '':
-            script = pbs_symlink_template % (job_wrapper.galaxy_lib_dir, " ".join(job_wrapper.get_input_fnames() + output_files), self.app.config.pbs_stage_path, exec_dir, command_line)
+            script = pbs_symlink_template % ( job_wrapper.galaxy_lib_dir,
+                                              " ".join( job_wrapper.get_input_fnames() + output_files ),
+                                              self.app.config.pbs_stage_path,
+                                              job_wrapper.get_env_setup_clause(),
+                                              exec_dir,
+                                              command_line )
         else:
-            script = pbs_template % ( job_wrapper.galaxy_lib_dir, exec_dir, command_line )
+            script = pbs_template % ( job_wrapper.galaxy_lib_dir,
+                                      job_wrapper.get_env_setup_clause(),
+                                      exec_dir,
+                                      command_line )
         job_file = "%s/%s.sh" % (self.app.config.cluster_files_directory, job_wrapper.job_id)
         fh = file(job_file, "w")
         fh.write(script)

universe_wsgi.ini.sample

 # currently available are 'pbs' and 'drmaa'.
 #start_job_runners = None
 
-# Uncomment drmaa_external_runjob_script , drmaa_external_killjob_script, and external_chown_script pameters and have them point to the
-# absolute path for scripts/drmaa_external_runner.py and scripts/drmaa_external_killer.py.
-# The scripts directory is located in the top level galaxy directory. The parameters when
-# uncommented allow for submission to the drmaa queue with the user name of the user submitting
-# the job and not the galaxy user. In order for this to work the actual user must log into galaxy
-# and the galaxy authentication must be consistent with the authentication on the server in which the
-# drmaa queue is running (i.e. the username must have an account on the server and be allowed to
-# submit jobs to the queue). The galaxy user must also be given sudo permission to execute
-# scripts/drmaa_external_runner.py and scripts/drmaa_external_killer.py in /etc/sudoers
-# Example:
-# galaxy  ALL = (root) NOPASSWD: SETENV: /opt/galaxy/scripts/drmaa_external_runner.py
-# galaxy  ALL = (root) NOPASSWD: SETENV: /opt/galaxy/scripts/drmaa_external_killer.py
-# Also the
-# Defaults    requiretty
-# in /etc/sudoers must be commented out
+# For sites where all users in Galaxy match users on the system on which Galaxy
+# runs, the DRMAA job runner can be configured to submit jobs to the DRM as the
+# actual user instead of as the user running the Galaxy server process.  For
+# details on these options, see the documentation at:
+#
+# http://galaxyproject.org/wiki/Admin/Config/Performance/Cluster
+#
 #drmaa_external_runjob_script = scripts/drmaa_external_runner.py
 #drmaa_external_killjob_script = scripts/drmaa_external_killer.py
 #external_chown_script = scripts/external_chown_script.py
 
-#important if running as actual user since enviromental variables are not passed
-#will supercede an other definition of TMPDIR if using drmaa
-#TMPDIR = /opt/galaxy/database/tmp
-
+# File to source to set up the environment when running jobs.  By default, the
+# environment in which the Galaxy server starts is used when running jobs
+# locally, and the environment set up per the DRM's submission method and
+# policy is used when running jobs on a cluster (try testing with `qsub` on the
+# command line).  environment_setup_file can be set to the path of a file on
+# the cluster that should be sourced by the user to set up the environment
+# prior to running tools.  This can be especially useful for running jobs as
+# the actual user, to remove the need to configure each user's environment
+# individually.  This only affects cluster jobs, not local jobs.
+#environment_setup_file = None
 
 # The URL for the default runner to use when a tool doesn't explicitly define a
 # runner below.