M-Script is a project intended to combine the flexibility of traditional Unix approach, simplicity of Unix shell and power of native Linux system utilities to a single server management solution.
M-Script is, basically, a collection of shell scripts for various server management tasks. Each of the scripts can be run separately when/if needed, but bound together they form a well-integrated solution, still flexible because it is easy to combine/pipe/edit shell scripts to make them do exactly what you need.
It is based upon the main Unix Way principles :
- Write programs that do one thing and do it well.
- Write programs to work together.
- Write programs to handle text streams, because that is a universal interface.
- And, of course, the KISS principle
M-Script is designed to help in:
- Monitoring
- Backups
- Administration tasks scripting
- Cloud and clusters management: auto-scalability based on monitoring, tasks execution on multiple servers, synchronizing files and folders across multiple servers (clusters, super-clusters, cluster groups, regions, clouds)
- Pluggable monitoring modules
- 3-level alerting system with filtering
- Easy watchdogs creation
- Monitoring data database (SQLite)
- Monitoring data graphs
- Flexible multi-config databases/files backups, local and/or remote
- Remote backups: to/from, FTP, SCP, Rsync, S3, EC2 EBS snapshots
- Cloud servers management: servers and images creation/deletion, auto-scalability, programmable deployment system, load balancing, EC2 Route53 DNS support
- Dashboard web interface, easily scriptable to allow custom monitors/actions integration
You found out that you get the users activity peak each time it gets rainy in London. So what you want is to start one additional Amazon EC2 instance and add it to your application servers cluster.
First you need a custom monitoring plugin. In our case it is going to be a London weather monitoring plugin.
All it has to do is provide output lines starting with if the weather is sunny, or one of three alert levels if not, like this:
- Weather in London: Sunny
- <*> Weather in London: Rainy
- <**> Weather in London: Heavy Rain
- <***> Weather in London: Rain / Thunder
So here is the plugin (in Unix shell, but you can use whatever you think is a better fit):
#!/bin/bash
weather=`/usr/bin/curl -s http://rss.weather.com/weather/rss/local/UKXX0085 \
| grep \<description\> | grep wxicons | awk -F'/>' '{print $2}' | sed 's|For more.*$||'`
[[ $weather =~ Sunny ]] && echo "<OK> Weather in London: Sunny" && exit 0
[[ $weather =~ Rain ]] && [[ $weather =~ Thunder ]] && \
echo "<***> Weather in London: Rain / Thunder" && exit 0
[[ $weather =~ Heavy\ Rain ]] && echo "<**> Weather in London: Heavy Rain" && exit 0
[[ $weather =~ Rain ]] && echo "<*> Weather in London: Rainy" && exit 0
echo "<OK> Weather in London: Cloudy"
Now, you want to start one additional application server if it becomes rainy, two servers if the rain is heavy, and three servers if it’s a thunderstorm. This is done in the actions configuration file conf/actions.conf:
Weather\ in\ London|1|create_node --cluster=application --number=1
Weather\ in\ London|2|create_node --cluster=application --number=2
Weather\ in\ London|3|create_node --cluster=application --number=3
Weather\ in\ London|0|destroy_node --cluster=application --last
where ‘application’ is your application servers cluster name defined in conf/cluster.conf
That’s all.
This is only one of possible scalability scenarios. You can make it less aggressive starting up one server at a time, define how often servers can start, minimal and maximal numbers and so on. See M-Script Wiki for details.