How to expose shell scripts as web services?

Introduction

Shell scripts allow sys-admins to write utility programs to speed up recurrent administration tasks. Usually they are faster compared to an equalent version from a traditional programming language & provides the expected functionality using few lines of code.
 
But often these scripts can only be accessed using a shell console. Following tutorial shows how you can extend the accessibility scope of your shell scripts by using WSO2's Web Services Application Server(WSAS).
 
This solution exposes shell scripts as web services, thus broadening the accessibility scope of your shell scripts. worried about the security?...WSAS has many options to secure services deployed on top it. So your guranteed that only users/systems withrequired credentials access your shell scripts.
 
Be creative & lying head are amazing monitoring/administration opportunities, waiting to be unleashed by YOU!!!.

 

It's just few steps away...Let's get started

Step 1 : Download latest version of WSAS (2.2.1 as of now)- http://wso2.org/projects/wsas/java
Step 2 : Download shellscriptdeployer-0.1.jar.zip attached bellow & extract it to a temporary location
Step 3 : Extract WSAS distribution to a location of your choice - Hereafter this location will be reffered as WSAS_HOME
Step 4 : Copy shellscriptdeployer-0.1.jar (from step2) to WSAS_HOME/lib/patches 
Step 5 : Open WSAS_HOME/conf/axis2.xml 
Step 6 : Add following line,
<deployer extension="sh" directory="shellservices" class="org.wso2.deployers.ShellScriptDeployer"/>

after

<axisconfig name="AxisJava2.0"> 

element.

Step 7 : Create a folder called 'shellservices' inside WSAS_HOME/repository.
Step 8 : Create a BASH script called 'DiskUsageMonitor.sh' & save it inside WSAS_HOME/repository/shellservices folder
Step 9 : It should contain following text.
#!/bin/bash

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location

echo "-----------------------------"
echo "Results of disk usage search"
echo "-----------------------------"

du --max-depth=1 -m $1
Step 10 : Try executing this simple script from command line & observe the result.
eg:
./DiskUsageMonitor.sh /tmp
Step 11 : Now lets see how WSAS can extend the accesibility scope of our script. First start WSAS server by executing WSAS_HOME/bin/wso2wsas.sh
 
Step 12 : Open up a browser window & enter following URL.
http://localhost:9762/services/DiskUsageMonitor/getUsage?location=/tmp
 
Results
Note : 9762 is the default port unless you have changed.
 
Step 13 : You will see the output of your shell script in the browser. Try using alternative values for '/tmp'.
eg:
http://localhost:9762/services/DiskUsageMonitor/getUsage?location=/home


Detailed analysis of DiskUsageMonitor.sh

It is a typical BASH script, except for following three non-executing entries.

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location


if your script has multiple input parameters, you can add them as follows.

#@webservice.name=DiskUsageMonitor
#@webmethod.name=getUsage
#@webmethod.param1=location
#@webmethod.param2=max-depth
#@webmethod.param3=block-size

Make sure you increment the number after 'param' for every new parameter. 

Limitations as of this release

This project is in inception stages. Therefore several must have functionalities are still being developed.

  • WSDL for the service is not generated correctly
  • Support for DOS bat files is not enabled in this release
  • Multiple extensions of scripts are not supported (A limitation comming from Axis2)
  • Scripts need to be copied to WSAS_HOME/repository/shellservices
  • REST support is not available
feliduca's picture

Actually wrapping shell

Actually wrapping shell scripts as a Web service is very common in scientific community, and I have been working on a project (extreme.indiana.edu/gfac/ see user guide for detail) that does exactly that for more than a year. Big idea is that there are tons of scientific code (usually written in FORTRAN) that can be executed as shell scripts, and by wrapping them with web services, we can bring them to the SOA world. With in SOA world, they can benefits from things like security, notifications, access control, auditing and workflows act. Aforementioned project is part of the LEAD project, where we wrap weather forecast models as Web services; compose workflows, making them available for many others. For an example, we using this method we expose WRF forecasting model, the state of art in weather predication, to a wider community. Same idea works for any other domain. Actually, we just got a paper accepted on this topic in TG08 (Workflow Infrastructure for Multi-scale Science Gateways). I cannot link the paper until it is published in June, but if anyone is interested, please drop me a mail.

To summerize, it is a very nice feature for Axis2, and actually using annotations to describe parameters is a nice new way to get parameters! (I can not recall seeing anyone doing this with annotation, including us).

___________________
Submited by : Libros Gratis

Latest Webinar
In this webinar we'll share the range of concerns we've heard from the industry, and survey some of the new and sometimes subtle types of lock-in associated with cloud technologies.
Wednesday, 8 September, 10.00 AM (PDT)