Installing Mako Server as a Service on Linux

Installing Mako Server as a service (aka daemon) on Linux is straightforward. The following example shows how to create a dedicated user for the Mako Server and create a boot script that starts the Mako Server when Linux starts. This script also enables you to start/stop the service from the command line.

Note, all commands below must be run as user root. If you are not root, you can become root by using the command su or sudo sh.

First, we need to download and install the Mako Server. You can skip this step if you have already copied Mako Server to your /bin directory. The following commands download Mako Server for x86 (32 or 64) bit. For other platforms, download the appropriate version or cross compile the source for your target platform.

Copy the following commands and paste into your terminal window.

cd /tmp; export XBIT=`getconf LONG_BIT`; wget http://makoserver.net/download/mako.linux-x$XBIT.tar.gz; tar xvzf mako.linux-x$XBIT.tar.gz; cp mako mako.zip /bin;

The next step is to create a dedicated user for the Mako Server. We will use the name 'mako' as the Linux user. You can choose any username or simply run the server under your existing user account. However, you must modify the service script (downloaded in the next step) if you use a username other than 'mako'.

useradd -G daemon -m -s /bin/bash mako

You should now have a new user with the home directory /home/mako. We are now ready to install the Mako Server's boot script. This script starts the Mako Server as a Linux service (aka daemon) -- that is, the server runs in the background.

Copy the following instructions into your terminal window to install the startup script.

cd /etc/init.d/; wget http://makoserver.net/download/scripts/mako.sh; chmod +x mako.sh; cd;

You should now be able to start and stop the Mako Server as a background process from the command line:

/etc/init.d/mako.sh start /etc/init.d/mako.sh stop

Although you can start and stop the server from the command line, the server will not start if you reboot your Linux computer. For this to work, the following command must be run:

update-rc.d mako.sh defaults

Read the Making scripts run at boot time with Debian tutorial if your Linux distribution does not come with update-rc.d.

Configuring Your First Application

If you started Mako Server as instructed above, you will get a 404 not found response if you visit the server using a browser. We need to install at least one LSP application in the server. The following example shows how to create one app that simulates a standard web server's www directory.

Run the following command in your console Window:

su mako; cd; whoami;

You should now be running as the user 'mako' and be in the /home/mako directory. The next step is to create a mako configuration file that loads one app. You can use any editor when creating the configuration file. We are using the 'nano' editor in the following example. If you get an error when running nano, install nano as follows: apt-get install nano.

nano mako.conf

When nano is running, copy the following and paste into the nano editor.

apps = { { name="", path="www", dav=true, auth=true }, } users = { mako="123456" } tracelogger = { auth=true }

Using the nano editor, modify the username "mako" to your username and the password "123456" to a more suitable password. Press Ctrl-X and save the file (Y). You should now be back at the command prompt.

The above configuration file sets up one root application using the path 'www' (that is /home/mako/www). We must create this directory before restarting the server. Type the following command at the Linux command prompt.

mkdir www

We can now restart the server. The two following commands exit user mako (back to root) and restart the server.

exit; /etc/init.d/mako.sh restart;

You will still get a 404 page if you visit the server using a browser. What we need is an index page in the new www directory.

Create index.lsp in the www directory.

Map/mount the server using WebDAV if the Mako Server runs on an online VPS (cloud server)

To map/mount the online server as a file system, use the URL: http://server-address/fs/. In Windows, you can go to Map Network Drive and enter the URL to map the online server as a drive in Windows. See the WebDAV information page for the BarracudaDrive product for more information on how to map/mount a WebDAV drive. The above Mako Server configuration script (mako.conf) enabled WebDAV for your application. The WebDAV username/password (default mako/123456) is what you put into the modified Mako Server configuration script.

When you have mapped/mounted WebDAV, use any editor on your host computer (PC) and open/create a new file on the mapped/mounted drive.

The following example shows how to do this on Windows using Notepad. The online server is mapped as 'Z:'.

notepad z:\index.lsp

Copy the following content into the editor (index.lsp) and save the file.

<h1><?lsp print"Hello Browser" trace"Hello Trace" ?></h1>

You should now see "Hello Browser" if you visit your home page using your browser.

Function trace would normally print to the console, but you have no console when the server runs as a background service. The Mako Server inserts the information printed to the console into the file mako.log when the server runs as a background service. This log can also be viewed in real time if the TraceLogger is enabled. The TraceLogger was enabled in the above Mako Server configuration script. Navigate to http://servername/rtl/tracelogger/ and login using the credentials you entered when you modified the mako configuration file. You should see the following:

image

Notice how the message "Hello Trace" and the line number is printed each time you navigate (using a different browser window) to your main index page.

Hash Encrypted Passwords

We stored the passwords in clear text in the above Mako Server configuration file (mako.conf). You can also store the passwords as an MD5 hash. The MD5 hash must be computed as explained in the Barracuda App Server manual: Storing passwords as a hash value.

You may use the following LSP script to simplify the calculations. Copy the following content and paste it into an LSP page that you can run on your server instance.

<?lsp local d = request:data() if d.u and d.p then local realm="Barracuda Server" -- For Mako Server DAV and TraceLogger local ha1=ba.crypto.hash"md5"(d.u)":"(realm)":"(d.p)(true,"hex") response:write(d.u,'={"',ha1,'"}') else print"Username and password required" end ?>

When you run the page, enter the following:

http://servername/pagename.lsp?u=mako&p=123456

'mako' and '123456' must be substituted with your own credentials.

Executing the page with the above credentials produces the following result:

mako={"072fa416feb977c8c2d7464e50a32122"}

Copy the produced result and paste into mako.conf:

users = { mako={"072fa416feb977c8c2d7464e50a32122"} }


Installing Mako Server on an Online VPS

Since the Mako Server is very light on resources (memory and CPU), a Bare Minimum Virtual Private Server (VPS) can in many cases be sufficient when running an online (cloud) solution based on the Mako Server.

As a first step, we recommend reading the reviews on LowEndbox.com.

One of the services we have used is Secure Dragon. You can find several great reviews on lowendtalk.com or by simply Googling Secure Dragon Review.

Posted in Tutorials by bd