March 18, 2009
I use RVideo gem a lot for a video processing application I have been building in Rails which will be open sourced soon on github. Using the gem you can create a RVideo::Inspector object to gather information about the uploaded file including its fps and content type.
If you use the latest version of ffmpeg (mine is SVN-r16905), I find that I keep getting nil values whenever I run the inspector objects. I googled around and found that this is due to a regular expression mismatch in the source. Change line 53 in inspector.rb in the source to:
metadata = /(Input \#.*)\n(Must|At\sleast)/m.match(@raw_response)
March 18, 2009
This is a re-deux of an earlier article I wrote on how to install nginx on os x via macports. It has been a while since I got my hands dirty with server installs and configuration so I thought why not do an update to the latest version of nginx while learning how to install it from source?
These are the steps I took:
sudo mkdir nginx_source
sudo curl -O http://sysoev.ru/nginx/nginx-0.6.35.tar.gz
sudo tar xvzf nginx-0.6.35.tar.gz
sudo ./configure --add-module=../nginx_uploadprogress_module/ --prefix=/usr/local --with-http_ssl_mmodule
sudo make install
Once the above is successful, you should be able to type which nginx on your terminal and it should show up as ‘/usr/local/sbin/nginx’. If not you need to add /usr/local/sbin to your environment path.
To start it just type sudo nginx. The install will put a default config file in /usr/local/conf/nginx.conf and a html file in /usr/local/html. Type http://localhost into the browser and it should show the welcome page if all the paths are correct.
Note that I added the ‘add-module’ option in the configure step. This is to load any third party external modules into the compilation process. The module is the upload progress module which tracks and provides real-time feedback of your file uploads on the server side. I can verify it works as advertised.
To add additional modules simply chain the add module commands like so:
sudo ./configure --add-module=/path/to/first module --add-module=/path/to/second module There are plenty of configuration and installation instructions on http://wiki.nginx.org/
Check back for part two of this series where I will discuss and show how to use external modules such as the uploadprogressmodule and configuration files and how they work.
February 19, 2009
MountView, a questionnaire dispatch and monitoring system of which I am a co-developer has been launched. You can find more information here:
This is my second commercial Rails application which is still under heavy development.
The first commercial Rails application which is an implementation of MountView is for EssexKarting. Screenshots and more description coming soon.
P/S EssexKARTING is a bespoke application so sorry can’t provide logins
September 26, 2008
If you have just completed an application, its more than likely you would like to have an admin portal to administer users. The easiest way to do this in Merb is to use the ‘merb-gen resource_controller’ command in your application directory to generate a CRUD controller and views for the resource. This is similar to using scaffold in rails.
Say for instance I have a resource called Posts and I want to generate an admin front-end to it. All I need to do is change to the application directory and type:
merb-gen resource_controller admin/posts
This creates a subfolder called ‘admin’ within your controllers and a new posts controller within that to handle all the CRUD functions. However, on MERB 0.9.5, the controller is missing the module keyword and if you try to run the above you would receive a namespace or controller not found error.
To fix this, open up ‘admin/posts’ controller and add ‘module Admin’ to the file:
module Admin class Posts < Application .... end end
Next add the required namespace to the ‘config/router.rb’ file:
Merb::Router.prepare do |r| r.namespace :admin do |admin| admin.resources :posts end end
Fire up your app and it should all work. I’m not certain if this is fixed in subsequent versions of Merb but I did notice a ticket has been submitted for nested namespaces error. If anyone reading this has more information on the official line, please do leave a comment
Just received an up-to-date comment from one of the MERB framework developers who read this post and confirmed that the latest version of ‘merb-gen’ has been fixed to prevent the error above. So upgrade your version of Merb to prevent it. And you still have to add in the namespace in your router file manually.
September 9, 2008
There are a wealth of plugins or modules you could add to your existing nginx installation. I have been testing one of them recently – the NGINX Upload module by Valery Kholodkov.The beauty of this module is to capture and parse the mime headers before sending the parsed information onto your application backend. Your application only has to handle the parsed information which is formatted in a POST request header. This is defintely a powerful module to have if your application deals with large volumes of user uploads.
If you have an existing macport installation of nginx, it is a very straightforward process. All we need to do is to replace the default binary installtion with a new compiled version that includes the plugin.
Firstly, you would need to grab the source of nginx which is located here. The most current version is 0.6.32. Extract the source to your local directory. Next, grab the module you want to include – in this example we are using the upload module as mentioned above.
Open up the command prompt and change into the nginx sources folder and issue the following commands:
cd nginx-0.6.32 sudo ./configure --add-module=../nginx_upload_module-2.0.6/ --prefix=/opt/local --conf-path=etc/nginx/nginx.conf --sbin-path=sbin/ --with-http_ssl_module
The last command above uses the ‘add-module’ directive to include the module you want to add by specifying the path where it is located – in this case in the folder above the current directory called ‘nginx_upload_module’. The rest of the paramaters are pretty self-explanatory – it is pointing to where the default macport installtion of nginx resides namely /opt/local/sbin. The last parameter compiles the new nginx binary with ssl support.
If the command runs successfully, you should see the following on the screen:
Configuration summary + threads are not used + using system PCRE library + using system OpenSSL library + md5 library is not used + sha1 library is not used + using system zlib library nginx path prefix: "/opt/local" nginx binary file: "/opt/local/sbin/" nginx configuration file: "/opt/local/etc/nginx/nginx.conf" nginx pid file: "/opt/local/logs/nginx.pid" nginx error log file: "/opt/local/logs/error.log" nginx http access log file: "/opt/local/logs/access.log"
Lastly, run sudo make and sudo make install to complete the installation process. I restarted nginx using the following commands:
sudo launchctl stop org.macports.nginx sudo launchctl start org.macports.nginx
You would need to refer to nginx.conf to alter the configuration option suited to the module you just added.
The entire process is semaless once you get your head round it but all it involves is just recompiling a new nginx binary to replace the one installed by macports. I think for those of you who have tried to compile new modules with apache would appreciate how easy it is to do the same thing with nginx – and I did not have to shut down the server for the entire process.
August 31, 2008
It is true that producing a rails application is half the batttle won- there are plenty of resources online and in books to guide a newbie through the process. Deploying a complete rails application is another challenge altogether. It requires a well-thought out plan and having the guts to deal with obscure error messages and grappling with the innards of server OS to get it right. It is an art in itself but it can be mastered by anyone with some patience and willingness to learn to get it right.
The traditional reply which I will provide anyone when ask how to deploy a rails application is to use Apache server as a shared host. However, I have recently discovered there are several disadvantages with this approach:
- Apache server requires mod_proxy module in order to run a cluster of mongrel servers. This means a default installation with the module already compiled or having to rebuild the entire server. Most shared host providers will not (in my experience) be willing to do that.
- Any changes made to the configuration file require starting and restarting the server which means downtime for your application.
- The configuration file (httpd.conf) is confusing – it relies on tags which in my experience is daunting and more error prone than a natural language syntax as in Ruby.
Now I have not run any benchmark tests as of this writing but will do in subsequent post as to the speed it handles request but as it stands, a lot of major host providers(Engine Yard) and even some application providers(37signals,wordpress) are using it and commenting on significant improvements on performance.
I have setup nginx as a development server on my macbook and from what I understand by reading the wiki, there are two main approaches to installing it on osx.
- Using macports
(sudo port install nginx)
- Downloading the latest stable tarball , extract and compile it.
I tried both approaches and only the first seems to work for me. I will document in a subsequent post as to the result of the second approach.
It would be wise to stop apache server on your localhost if you have it setup previously before installing nginx.
Macports automatically installs nginx executable into ‘/opt/local/sbin/nginx’. The configuration file is located at ‘/opt/local/etc/nginx/nginx.conf.default’ – you need to copy and rename this file to ‘nginx.conf’ before the server will start else you will get an error message on the terminal saying the conf file is not found.
To start or restart nginx I use the following commands on terminal:
sudo launchctl start org.macports.nginx (to start it)
sudo launchctl start org.macports.nginx (to stop it)
Fire up your browser and type in ‘http://localhost/’ and you should see the following screen appear:
The default configuration points to ‘/opt/local/share/nginx/html/’ but can be changed.
In part 2, I will showcase a configuration for a localhost deployment of a rails application including configuring your own mongrel_clusters.
Here are some links to find out more: