Running your own server

Running your own server

You may find that your work or research requires functionality that the CSE servers don't support. For instance, to take 2 common requests, we have no publicly available database, nor does our webserver support java servlets (JSP). Instead we provide a 'server server' ie. a (physical) server computer that you can use to run your (logical) server on. Currently this physical server is called Grieg. Access to it has to be requested from SS; if you are a student you will have to get your supervisor to ask it on your behalf (as with any allocation of extra computing resources).

You can log into Grieg using SSH and your CSE username and password. Once logged in you will be able to use the files in your CSE home directory.

Once on grieg you have a choice as to how to proceed:

  • You can run your server in the normal way; it will be allocated a non-privileged port (>1024) but will only be accessible from the CSE network.
  • If you want or need to use a privileged port, however, then you will need to run priv srvr. This allocates a dedicated IP address to you; it also creates a directory local to grieg which can be accessed from anywhere on the CSE (trusted) network by cd'ing to /srvr/username. The dedicated IP address will be in the range 149.171.x.y where x and y are calculated from the user's UID. The domain name for this IP address will be username.srvr.
The shell that calls priv srvr, and all new children of that shell will be able to bind to privileged ports on this IP. For instance, from that shell you can run a webserver on port 80 and access it on the CSE network via the URI http://username.srvr/. To use the IP from a new login you will need to run priv srvr again.

Use grieg ONLY for running your server, not for editing, compiling or other work. It may look like your private server but its resources have to be shared among many users. In particular, it is used to teach several courses.

Web services

The URI http://username.srvr/ is not accessible outside CSE. If you need to access a web site from outside the CSE network, you must run it in the priv srvr environment bound to port 80. It can then by accessed using the fully qualified URI http://username.srvr.cse.unsw.edu.au/.

Automatically starting your server

The services server is occasionally rebooted for maintenance reasons. If your application is providing a service to the wider community, then you probably want it to automatically restart when the server is rebooted. This should be done using a @reboot directive in a crontab. Please read how to set up a crontab at this link.

To run jobs at start-up add a line like this to the crontab file by running crontab -e: @reboot     /path/to/command arg1 arg2 … The command will be run whenever the server starts up after a reboot. Take note that cron does not provide many environment variables, and your script should set any it needs itself. If it needs to be run in a priv srvr environment, then it should also run that command (in full: /usr/local/bin/priv srvr) before running the service.

Running Tomcat

A basic script is provided on Grieg which will set up a Tomcat7 instance: /usr/bin/tomcat7-srvr-instance-create.

It will automatically install a fresh set of configuration files in /srvr/username/tomcat7/ and start the service. You will have to configure the instance yourself to get it to do what you want.

The actions it performs are similar to these below…

Using the local Tomcat installation

You should set the values of environment variables $CATALINA_BASE and $CATALINA_HOME so that you make use of the Tomcat installation already on Grieg. $CATALINA_HOME should point to the Grieg installation, located in /usr/share/tomcat6, while $CATALINA_BASE points to the location of the non-common files located in your directory. To set $CATALINA_HOME: export CATALINA_HOME=/usr/share/tomcat6 To set $CATALINA_BASE: export CATALINA_BASE=/srvr/foo/apache-tomcat-6.0.32 Replace foo with your username, and edit the full path according to the location of your Tomcat installation. If you would like to read more about this, you can read the /usr/share/doc/tomcat6-common/RUNNING.txt.gz file on Grieg.

Starting and stopping Tomcat

To start Tomcat: $CATALINA_HOME/bin/startup.sh You should then be able to access the page from within the CSE network at http://foo.srvr:8080/ (where foo is your username). To stop Tomcat: $CATALINA_HOME/bin/shutdown.sh Note: If you configure the server to be visible from outside of the CSE network, the shut down process and the address is slightly different. See the section below for more information.

Making server visible from outside the CSE network

If you would like be able to see your server from outside of the CSE network then you will need to modify your server.xml file, which lives in the conf folder in your Tomcat installation (e.g. /srvr/foo/apache-tomcat-6.0.32/conf/server.xml). Open the file and make the changes below.
  • Set the address in the Connector tag. Find the following line: Connector port="8080" protocol="HTTP/1.1" Change the port to 80 and add the address of the server: Connector port="80" protocol="HTTP/1.1" address="foo.srvr"
  • Disable the shutdown port as this seems to connect to the wrong IP and there isn't much you can do about it. Find the following line: Server port="8005" shutdown="SHUTDOWN" And replace it with: Server port="-1" Because of this change the regular shutdown.sh script will not work properly, so the shutdown sequence will need to be changed. See the Modified shutdown sequence section below.
Once these changes have been made, you can access the server from within the CSE network at http://foo.srvr/ (the 8080 is no longer required as it is now running on port 80) and from outside the CSE network at http://foo.srvr.cse.unsw.edu.au/. As always, substitute your username for foo

Telling Tomcat the address of proxied requests

From: the online Tomcat Documentation When you are running behind a proxy server (or a web server that is configured to behave like a proxy server), you will sometimes prefer to manage the values returned by these calls. In particular, you will generally want the hostname and port number to reflect that specified in the original request, not the one on which the Connector itself is listening. You can use the proxyName and proxyPort attributes on the <Connector> element to configure these values. <Connector port="80" ... proxyName="foo.srvr.cse.unsw.edu.au" proxyPort="80"/>

Modified shutdown sequence

You should first specify an appropriate location for $CATALINA_PID, which keeps track of the process ID of the Tomcat process. Having this file around makes it easier to find the process you are running. To set $CATALINA_PID: export CATALINA_PID=$CATALINA_BASE/logs/catalina.pid Note that you can place this anywhere, but it would make sense if you place it somewhere within your Tomcat directory. Once you have set this value, you can start your server as per normal. To stop the server without having to manually determine the process ID, create a script somewhere appropriate (I would suggest something like $CATALINA_BASE/bin/force-shutdown.sh) and copy the following lines into the file: #!/bin/sh # check if file exists and filesize is greater than 0 if [ -s $CATALINA_PID ]; then # check if process is running kill -0 `cat $CATALINA_PID` if [ $? == 0 ]; then # kill Catalina process kill -USR1 `cat $CATALINA_PID` # remove PID file rm $CATALINA_PID else echo Catalina process not running. fi else echo File $CATALINA_PID does not exist fi Don't forget to change the permissions so that the file is executable. chmod u+x $CATALINA_BASE/bin/force-shutdown.sh
Last edited by robertd 30/06/2015

Tags for this page:

database, server, grieg, mysql, postgresql, apache