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 lets you start/stop the service from the command line.
If you want to install the Mako Server as a Linux service quickly, use the Ansible Mako Server Installation Script.
Running the Mako Server in the background is super easy; all you have to do is to add the -d switch:
mako -d additional-commands
As shown above, Starting the Mako Server in the background makes the server run until Linux reboots. We can automate the Mako Server startup when Linux powers on by either creating an init.d script or a systemd script.
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 must download and install the Mako Server. You can skip this step if you have already copied Mako Server to your /usr/local/bin directory. The following commands download Mako Server for x86 (32 or 64) bit. Download the appropriate version for other platforms or cross-compile the source for your target platform.
Copy the following commands and paste into your terminal window.
The next step is creating a dedicated Mako Server user. 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 if you use a username other than '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.
Open the following file in an editor, such as nano:
Copy the following and paste the content into mako.sh:
You should now be able to start and stop the Mako Server as a background process from the command line:
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:
In addition to the start and stop command shown above, you should now also be able to start and stop the service as follows:
Create a service unit file called mako.service in the /etc/systemd/system/ directory using the following command:
Copy the following and paste the content into mako.service:
Restart systemd:
Start, check status, and stop the Mako Server:
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:
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 to create 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.
When nano is running, copy the following and paste into the nano editor.
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.
We can now restart the server. The two following commands exit user mako (back to root) and restart the server.
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/dav/. 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:'.
Copy the following content into the editor (index.lsp) and save the file.
You should now see "Hello Browser" if you visit your home page using your browser.
Function trace normally prints to the console, but you have no console when the server runs as a background service. When the server runs as a background service, the Mako Server inserts the information printed to the console into the file mako.log. This log can also be viewed in real time if TraceLogger is enabled. The TraceLogger was enabled in the above Mako Server configuration script. Navigate to http://servername/rtl/tracelogger/ and log in using the credentials you entered when you modified the mako configuration file. You should see the following:
Notice how the message "Hello Trace" and the line number are printed each time you navigate (using a different browser window) to your main index page.
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 simplify the calculations using the following LSP script. Copy the following content and paste it into an LSP page that you can run on your server instance.
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 it into mako.conf:
users = { mako={"072fa416feb977c8c2d7464e50a32122"} }
Xedge is a powerful IDE designed for developing web and embedded applications with the Mako Server. When the Mako Server runs as a background service, using Xedge becomes highly convenient because it allows for:
The following mako.conf file should be used when using Xedge:
Xedge turns Mako Server into a robust, efficient platform for fast, continuous development.
The tutorial Setting up an IoT Broker explains how to install the Mako Server on a low cost online VPS.