Web Server & Me
- All
- Sun
Web Server 7: Type Less, Do More from the Command Line
The Sun Java System Web Server 7 Technology Preview release has many
new and cool features, one of which is its much improved command
line administration support. Previous releases of the web server had very
limited command line support for administration tasks. Web Server 7's primary command line administration tool is called wadm and it provides support for 280+ administration tasks!! I am very happy
with the extensive command line support in the new release.
I started using wadm (wadm is located in the bin subdirectory of your web server installation) without knowing anything about its syntax.
% wadm Usage: wadm [--user=admin-user] [--password-file=admin-pswd-file] [--host=admin-host] [--port=admin-port] [--no-ssl] [--rcfile=rcfile] [--no-prompt] [--help] [--commands-file=filename] CLI014 user is a required option.
This didn't really tell me a lot, so I tried
% wadm -help Usage: wadm [--user=admin-user] [--password-file=admin-pswd-file] [--host=admin-host] [--port=admin-port] [--no-ssl] [--rcfile=rcfile] [--no-prompt] [--help] [--commands-file=filename] CLI011 Invalid option, e
Still no luck. I then noticed that -- was used to specify options and so I tried
% wadm --help
Voila! About 20 pages of help documentation scrolled past my eyes! I used a pager to read the help documentation.
% wadm --help | more
To get extended help on a specific command, all I had to do was to specify the command and the --help option
% wadm list-webapps --help | more
Quite intuitive and easy.
I discovered that wadm required that the administration server be running, so I started the administration server.
I found that wadm's
command lines were quite long because of
the various parameters that had to be specified for each command. Even using the abbreviated command line options (e.g. -u instead of --user, -h instead of --host
etc.) I still felt that the amount of text that I had to type
repeatedly was too much! For example, this is the command I had to type
in order to list the Java web applications that were deployed on my
server.
% wadm list-webapps --vs test --config test --user admin --host foobar --port 8989 --passwordfile /home/foobar/admin.passwd
And this is the command to add a Java web application archive to my server configuration
% wadm add-webapp --vs test --config test --user admin --host foobar --port 8989 --password-file /home/foobar/admin.passwd --uri /foo foo.war
Instead of the above, wouldn't it be cool if I could just type
% wadm add-webapp --uri /foo foo.war
to add a Java web application, or type
% wadm list-webapps
to list the Java web applications deployed on my server? I don't
want to repeatedly type the parameter values that I know will never change and are common to
most commands.
It turns out that wadm provides some nifty ways to facilitate this. This is what I found from reading wadm's help documentation.
Any option can be supplied to wadm using shell variables. The variable name equivalent for an option is derived by prefixing wadm_ to the option name and replacing all hyphens(-) in the option name with underscores(_). For example
| Command Line Option Name | Shell Variable Name |
| user | wadm_user |
| password-file | wadm_password_file |
| receive-buffer-size | wadm_receive_buffer_size |
Shell variables can be set in the following ways in their increasing order of precedence:
- Using environment variables in the shell from which wadm is invoked
- From within a .wadmrc file residing in the user's home directory
- Using set/unset commands within the wadm shell
I prefer not to use environment variables and so did not consider option #1 above. Instead, I tried #2 and #3.
Specifying command line option values in .wadmrc (option #2)
I created a file called .wadmrc in my home directory with my favourite editor and added the following to it:
set wadm_user admin set wadm_password_file /home/foobar/admin.passwd set wadm_port 8989 set wadm_vs test set wadm_config test set wadm_host foobar
Now when I use wadm, I never have to specify --user or --password-file or --port or --vs or --config or --host to any of my wadm commands! wadm automatically picks up these values from my .wadmrc file. (If you call the .wadmrc file by some other name or put it somewhere other than in your home directory, you must use the --rcfile option of wadm to identify your .wadmrc file.)
Specifying command line option values in the wadm shell (option #3)
I found that if I used the wadm shell then I needn't even type wadm!
To invoke the wadm shell, I simply type wadm at the command line and
this enters the wadm shell. You can tell its the wadm shell because the
prompt changes from % to 'wadm> ' At the wadm> prompt, I simply type wadm commands. The shell allows me to override values specified in my .wadmrc file.
% wadm Sun Java System Web Server 7.0 B05/09/2006 18:10 wadm> wadm> help wadm> list-virtual-servers test wadm> list-webapps /foo /bar wadm> set wadm_vs foo wadm> list-webapps ADMIN3961: Specified virtual-server not found: foo wadm> add-<TAB> add-search-docs add-webapp wadm> set wadm_uri /test /test wadm> add-webapp foo.war CLI201 Command 'add-webapp' ran successfully wadm> list-webapps /foo /bar /test wadm> quit %
As you can see from the sample session above, the wadm shell is an interactive shell that is very easy to use. It also has quite a powerful command line editor. For example you can use the arrow keys to go up and down your command history or you can use the TAB key to complete commands or see the available options (see the add-<TAB> example above).
You can also do some pretty advanced Tcl scripting using wadm's --command-file option. I hope to write about this in a separate blog in the near future.
Overall, I had a pretty good experience using Web Server 7's wadm
tool and I hope that you too will find it equally useful. I hope you
will take Web Server 7 out for a test drive and send me feedback about
it.
Posted at 02:04AM May 17, 2006 by arvindsrinivasan in Sun | Comments[4]