Job submission using PHP and shell scripts
From EGEE-see WIki
PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP is powerful and modern server-side scripting language producing HTML or XML output which easily can be accessed by everyone via web interface (with the browser of your choice). PHP can execute shell scripts on the server side. The shell scripts contains gLite and globus commands for obtaining proxy certificate, job submission, data management etc. Using this technique we can easily create web interface to the Grid infrastructure.
Contents |
Executing shell commands from PHP
PHP exec() function executes the given command. Description of exec() is:
string exec ( string $command [, array &$output [, int &$return_var]] )
The parameters are:
command - the command that will be executed.
output - if the output argument is present, then the specified array will be filled with every line of output from the command.
return_var - if the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.
Example:
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
Also system() and shell_exec() can be used to execute commands.
Shell scripts
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. Usually, shell script refers to scripts written for a Unix shell. There are several types of scripting languages among them bash, tcl, expect, perl etc. With combination of the gLite commands we can produce powerful scripts that can simplify the usage of the Grid infrastructure.
Example:
#!/bin/bash # outputs the username that owns the script whoami
suPHP
SuPHP is a tool for executing PHP scripts with the permissions of their owners. It consists of an Apache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apache module to change the UID of the process executing the PHP interpreter. As PHP was the programming technology of choice, the suPHP module was compiled and installed. The following one-line script demonstrates PHP scripts being run as the user who owns them.
<?php echo exec("whoami"); ?>
Configuration of suPHP:
##############################################
# PHP config
##############################################
LoadModule suphp_module modules/mod_suphp.so
<IfModule mod_suphp.c>
AddHandler x-httpd-php .php .php3 .php4 .phtml .phpm
suPHP_Engine on
DirectoryIndex index.php
</IfModule>
Obtaining a proxy certificate
Rather than storing your Grid credentials on each machine you use to access the Grid, you can store them in a MyProxy repository and retrieve a proxy credential from the MyProxy repository when needed. To store a credential in the MyProxy repository, run the myproxy-init command on a computer where your Grid credentials are located. For example:
[gorgik@grid-wn gorgik]$ myproxy-init
Your identity: /DC=ORG/DC=SEE-GRID/O=People/O=Ss Cyril and Methodius Skopje Faculty of Electrical Engineering/CN=Gorgi Kakasevski Enter GRID pass phrase for this identity: Creating proxy .............................. Done Proxy Verify OK Your proxy is valid until: Sun Sep 9 14:17:41 2007 Enter MyProxy pass phrase: Verifying password - Enter MyProxy pass phrase: A proxy valid for 168 hours (7.0 days) for user gorgik now exists on myproxy.grid.auth.gr.
Once you've stored a credential in the MyProxy repository, you can retrieve a proxy credential whenever you need one with the myproxy-get-delegation command. For example:
[gorgik@grid-wn gorgik]$ myproxy-get-delegation
Enter MyProxy pass phrase: A proxy has been received for user gorgik in /tmp/x509up_u501
The myproxy-get-delegation command prompts for the pass phrase you set previously with myproxy-init, retrieves a proxy credential for you, and stores it in the correct default location for use with Globus. The default lifetime of a proxy credential is 12 hours or that specified with the -t option when creating the stored credential with the myproxy-init command.
Job submission
For job submission we use the command:
glite-job-submit [options] <jdl_file>
where <jdl file> is a file containing the job description, usually with extension .jdl.
Additional arguments that can be used with this command are:
--vo <vo name> : perform submission with a different VO than the UI default one.
--output, -o <output file> save the jobId on a file.
PHP web portal for job submission
Upon submission of the login form the ‘myproxy-get-delegation’ command retrieves the proxy certificate from the MyProxy server using the username and password supplied. If the login information successfully retrieves a proxy cert, then a copy of the proxy cert is written to a specific directory on the web portal file system under the name ‘USERNAME.cred’. If a proxy file was supplied this file is uploaded to the same directory.
