Ignite Your Sites with revIgniter

by Ralf Bitter on November 11, 2016 1 comment

[Editors note] This month we are celebrating the relaunch of our hosting service as LiveCode Hosting. With the spotlight on LiveCode Server I asked Ralf Bitter if he would like to write a bit about his excellent LC Server Framework, revIgniter.

Why revIgniter?

It was 2009 when the On-Rev web hosting service was introduced, long before the LiveCode Server engine was available to be installed on arbitrary web servers. Back then early adopters like me were thrilled and eager to learn about the new possibilities enabled by “a new variant of the existing technology that allows you to mix Revolution code with HTML content on the same page much in the same way as PHP”1. There was a vibrant community dedicated to server-side scripting at the forums which were rapidly flooded with lots of code samples all mixing LiveCode (formerly Revolution) code with HTML or even additionally with CSS and JavaScript.

read more
Ralf BitterIgnite Your Sites with revIgniter

Keeping an eye on your server

by David Williams on May 13, 2014 3 comments

Knowing how to interrogate your machines and get the *precise* information you need from them is a pretty wide-ranging topic. There are any number of ways of approaching this depending on what you need the data for. I’m going to go through some of the ways we keep an eye on our hardware, and where necessary, get detailed data from the server for analysis. Please note that the tools and servers we’re looking at here are Linux and may not be applicable to other server environments.

One of the main things we need to be aware of to get a gauge of how well the server is running is the server load average. This is essentially CPU usage calculated over time intervals (usually 1 minute, 5 minute, and 15 minute). We can see the load averages at a glance using the ‘uptime’ command:

root@jasmine [~]# uptime
15:41:41 up 126 days, 1:40, 2 users, load average: 0.10, 0.07, 0.05

This displays (among a few other things), the 3 load averages. A load average of 1 for a computer with 1 CPU core means that the CPU is fully used – anything over 1 means it’s overloaded. Our machines have 8-core CPUs, so we can see that this machine is very calm at the moment – a load of >8 would indicate overloading.

However, this command doesn’t give us much, and is entirely static. A better command for keeping an eye on the load and the rest of the system utilization is the ‘top’ command, perhaps the single most useful all-rounder for seeing system status at a glance:

topscreenshot

This command gives us an interactive and continuously updated display with the uptime, load averages, number (and status) of running tasks (processes), the CPU usage, the memory usage, and then a list of running processes which we can order in various ways. It’s essentially a command-line analogue of the task manager (windows) or activity monitor (osx), albeit a lot more flexible in some ways.

This shows us a sampling of the current running processes, but what if we need to see a comprehensive list of every single running process on the machine? We can use the ps command. The ps command is used for getting information about processes in various ways, in this instance we want to use the a u and x arguments to give us a detailed list of every single running process. The output of ‘ps -aux’ looks something like this:

psaux

We can look through this to get more of an idea of everything that’s currently running, and if we know what we’re looking for we can search through the output (via the ‘grep’ command for example) to determine whether the expected processes are there or not. This is great, but it’s very hard to read if we just want a summary of the current processlist. There are various utilities that do this, but why not write a quick one that does exactly what we want in LiveCode Server?

#!/usr/local/cpanel/cgi-sys/livecode-server

put $0 into tUserFilter
put shell("ps aux") into tProcessList

repeat for each line tLine in tProcessList
if tUserFilter <> empty and word 1 of tLine <> tUserFilter 
then next repeat
add 1 to tOutputArray[word 1 of tLine][word 11 to -1 of tLine]
end repeat

repeat for each key tUser in tOutputArray
put tUser & ":" & return
repeat for each key tProcName in tOutputArray[tUser]
put tab & tProcName & ":" && 
tOutputArray[tUser][tProcName] & return
end repeat
put return
end repeat

This little script gives us a nice summary of what the running processes are for each user and how many of those processes are running. We can also give it a user to filter by if we only want to see processes from that user using the $x variables – command line arguments passed to a LiveCode app are accessible by using $ and their position in the argument list (in this instance we use $0 to access the first argument passed, which we expect to be a username).

psdigest

The above tells us all about load and processes, but what if we want to know about what those processes are doing with the disk? There is some standard functionality in Linux for this, but we often use a great utility called ‘iotop’ (non-standard) to get this info, which functions in a similar way to top:

iotop

We can see, again, that this server isn’t very busy. One other thing we may want to know about is the current open connections and their status, which we can check using netstat. We almost always use netstat with the -n argument, as otherwise it will try and lookup the hostnames of the addresses involved, which is time-consuming.

netstat

This information contains a list of all the open TCP and UDP connections on the server, with the local address:port and the remote address:port pairs for each. This is very useful as we can quickly look through or parse this data for various purposes, for example we can see all the current mysql connections by using grep (the Linux search command) with the mysql port number:

netstat -n | grep 3306

This is useful as we can see where all these connections are coming from, which can aid in diagnosing certain types of issue. We could expand on this slightly to simply get the number of current mysql connections using the wc (word count) command with the -l (count lines) option:

netstat -n | grep 3306 | wc -l

These are some of the basic command line utilities we use to gather information about the system. There are many many more tools of various complexity that we use which would most likely take a small novel’s worth of blog posts to cover. At the heart of it, being able to query the system for specific information at the command line is often more fast an effective than using a complex GUI-based program that may not tell you precisely what you’re looking for.

read more
David WilliamsKeeping an eye on your server

Livecode.org email addresses and talking to PHP from LiveCode Server

by David Williams on April 3, 2014 2 comments

One of the things we’ve introduced recently was the LiveCode Membership product, one of the benefits of which is a livecode.org email address of your choosing. This meant that we needed to set up the livecode.org domain to use with email accounts on one of our servers, and then set up some way for the livecode.com store to communicate with it in order to set up the email accounts. This is made simpler by the fact that we make use of cPanel/WHM, meaning we can use the cPanel API for this kind of operation.

The cPanel API is written in PHP and allows you to perform a wide range of operations. The problem here, of course, is that it’s written in PHP – we want to talk to the API using LiveCode Server! So this raises the question – how do we interact with PHP scripts from LiveCode Server? This is a question that comes up every now and again for the reason that many utilities and systems are written in PHP.

In this instance, the API performs and action and returns a result (as either JSON or XML). For very simple instances where we just want to, for example, be able to get a list of all email accounts, we can set up the PHP script that performs the relevant API call, and then execute it directly using shell() from our LiveCode Server script:

...
put shell("php check_email_accounts.php") into tAccountsXML
...

This method is appropriate when we don’t need to pass information to the script, and where we also don’t need to use the CGI environment, which isn’t initiated if we execute it in command-line mode. Another way is to set up the script to handle data posted to the script:

...
post "user=" & tUser & "&pass=" & tPass & "&auth=r34l1ygr34TaU7h5tr1nG" to url("http://mail.somelivecodedomain.com/create_mail_script.php")
...
    

The script that the data is posted to should then be set up to take the values from $_POST and use them as parameters in the API call.
This way we also have access to the CGI environment in the PHP script should we need it. Security can be accomplished quite easily as we know where the post is coming from and can use .htaccess directives to restrict how the file can be accessed, as well as the standard types of script-based authentication we might use with this.

Ideally, in this instance, we would set up a single PHP script to which we would post the name of the desired API function and a list of parameters, which would be processed into the correct format and then passed directly into the api query function into that script. In this way we could implement a single callCPanelAPI() function in our LiveCode Server script.

read more
David WilliamsLivecode.org email addresses and talking to PHP from LiveCode Server

LiveCode Server

by David Williams on March 6, 2014 5 comments

Here at On-Rev, we make extensive use of LiveCode Server internally for scripting – you’ll see a lot more filenames ending in .lc than you might in .sh, purely for the reason that LiveCode Server is great for making scripts that are a lot more readable than, say, a bash script, and we can drop in shell commands with ease where necessary.

One recent feature that was introduced in LiveCode 6.6 was the ability to use hashbangs (#! /path/to/livecode) in LiveCode server scripts instead of script open and close tags (<?lc ?>). This means that we can have scripts which look like this:

#!/path/to/livecode-server
put “hello world at” && the millisecs

Instead of this:

<?lc
put “hello world at” && the millisecs
?>

The difference is that the latter has to be passed as a file to the LC Server exectuable, which then parses the code for output. This makes sense where LC Server is integrated into a web server software for serving webpages, but if we were doing this in a command line, it would look like this:

root@mybox [~]# /path/to/livecode-server ./script.lc

Whereas by using hashbangs, we can now execute the script directly, as the script contains the information for how it should be executed:

root@mybox [~]# ./script.lc

This seems like a minor change, but it brings the LC Server engine closer to how scripting for system utilities should function in a Unix environment, and allows me to tidy up some of the internal systems we use a little bit.

Additionally, work on the On-Rev client has been ongoing and we hope to release an update as soon as some of the last technical hurdles are overcome – we hope to send out a notification about this to all our On-Rev customers in the near future.

read more
David WilliamsLiveCode Server