comparison scriptrunner.py @ 9:77dca93454b7 draft

planemo upload for repository https://github.com/mvdbeek/docker_scriptrunner/ commit 40d6cb5308a36b00495fd6072d867ed2c5a37b3c
author mvdbeek
date Sat, 09 Jul 2016 05:07:15 -0400
parents 1b7f987270a6
children ed7cf3f35799
comparison
equal deleted inserted replaced
8:1b7f987270a6 9:77dca93454b7
373 if self.opts.make_HTML: 373 if self.opts.make_HTML:
374 self.makeHtml() 374 self.makeHtml()
375 return retval 375 return retval
376 376
377 377
378 def change_group_id(group_id): 378 def change_user_id(new_uid, new_gid):
379 """ 379 """
380 To avoid issues with wrong user ids, we change the user id of the 'galaxy' user in the container 380 To avoid issues with wrong user ids, we change the user id of the 'galaxy' user in the container
381 to the user id with which the script has been called initially. 381 to the user id with which the script has been called initially.
382 """ 382 """
383 old_gid = 1450 # specified in Dockerfile 383 cmd1 = ["/usr/sbin/usermod", "-d", "/var/home/galaxy", "galaxy"]
384 cmd = ["/usr/sbin/groupmod", "-g", group_id , "galaxy"] 384 cmd2 = ["/usr/sbin/usermod", "-u", new_uid, "galaxy"]
385 subprocess.call(cmd) 385 cmd3 = ["/usr/sbin/groupmod", "-g", "1450", new_gid]
386 386 cmd4 = ["/usr/sbin/usermod", "-d", "/home/galaxy", "galaxy"]
387 387 [subprocess.call(cmd) for cmd in [cmd1, cmd2, cmd3, cmd4]]
388 def change_user_id(new_id): 388
389 """
390 To avoid issues with wrong user ids, we change the user id of the 'galaxy' user in the container
391 to the user id with which the script has been called initially.
392 """
393 cmd = ["/usr/sbin/usermod", "-u", new_id, "galaxy"]
394 subprocess.call(cmd)
395
396
397 def update_permissions():
398 cmd = ["/bin/chown", "-R", "galaxy:galaxy", "/var/home/galaxy"]
399 subprocess.call(cmd)
400 389
401 def main(): 390 def main():
402 u = """ 391 u = """
403 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: 392 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
404 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" 393 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
433 except: 422 except:
434 pass 423 pass
435 if opts.dockerized==0: 424 if opts.dockerized==0:
436 switch_to_docker(opts) 425 switch_to_docker(opts)
437 return 426 return
438 change_user_id(opts.user_id) 427 change_user_id(opts.user_id, opts.group_id)
439 change_group_id(opts.group_id)
440 os.setgid(int(opts.group_id)) 428 os.setgid(int(opts.group_id))
441 os.setuid(int(opts.user_id)) 429 os.setuid(int(opts.user_id))
442 update_permissions()
443 r = ScriptRunner(opts) 430 r = ScriptRunner(opts)
444 retcode = r.run() 431 retcode = r.run()
445 os.unlink(r.sfile) 432 os.unlink(r.sfile)
446 if retcode: 433 if retcode:
447 sys.exit(retcode) # indicate failure to job runner 434 sys.exit(retcode) # indicate failure to job runner