Archive for category Linux

Differences between Amazon instances

It has now been more than a year I am using Amazon Cloud for websites hosting. I have to admit that it works pretty well and I am quite happy about their services.
However, I got a strange problem a few days ago.

I was deploying an application on two different large instances of Amazon Cloud, one would be the UAT (User Acceptance Testing) server and the other one would be the Production server.
Strangely enough, the version running on the Production server was running slower than on the UAT server! 😯 Why?

At first, I thought I missed something with the server configurations. But no, everything was absolutely identical! So where does this difference of speed come from?

After some more investigation, I had the brilliant idea to execute the following command:

cat /proc/cpuinfo

On the Production server, this command was returning the following:

processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 65
model name	: Dual-Core AMD Opteron(tm) Processor 2218 HE
stepping	: 3
cpu MHz		: 2599.998
cache size	: 1024 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
bogomips	: 5202.40
TLB size	: 1024 4K pages
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc

processor	: 1
vendor_id	: AuthenticAMD
cpu family	: 15
model		: 65
model name	: Dual-Core AMD Opteron(tm) Processor 2218 HE
stepping	: 3
cpu MHz		: 2599.998
cache size	: 1024 KB
physical id	: 1
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow up pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
bogomips	: 5202.40
TLB size	: 1024 4K pages
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc

And on the UAT server, it was returning the following:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 23
model name	: Intel(R) Xeon(R) CPU           E5430  @ 2.66GHz
stepping	: 10
cpu MHz		: 2666.762
cache size	: 6144 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu de tsc msr pae cx8 apic sep cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc pni ssse3 cx16 lahf_lm
bogomips	: 5337.55
clflush size	: 64
cache_alignment	: 64
address sizes	: 38 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 23
model name	: Intel(R) Xeon(R) CPU           E5430  @ 2.66GHz
stepping	: 10
cpu MHz		: 2666.762
cache size	: 6144 KB
physical id	: 1
siblings	: 1
core id		: 0
cpu cores	: 1
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu de tsc msr pae cx8 apic sep cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc up pni ssse3 cx16 lahf_lm
bogomips	: 5337.55
clflush size	: 64
cache_alignment	: 64
address sizes	: 38 bits physical, 48 bits virtual
power management:

As you can see, these two servers actually don’t have the same CPU model name. But the biggest difference is probably the CPU MHz (2666.762 on UAT and 2599.998 on Production) and the cache size (6MB on UAT and only 1MB on Production).

So what does that mean? Two large instances of Amazon Cloud actually don’t have the same power?

The answer of this question is actually on the Amazon instance types description (http://aws.amazon.com/ec2/instance-types/) under the ‘Measuring Compute Resources’ chapter:

Amazon EC2 uses a variety of measures to provide each instance with a consistent and predictable amount of CPU capacity. In order to make it easy for developers to compare CPU capacity between different instance types, we have defined an Amazon EC2 Compute Unit. The amount of CPU that is allocated to a particular instance is expressed in terms of these EC2 Compute Units. We use several benchmarks and tests to manage the consistency and predictability of the performance of an EC2 Compute Unit. One EC2 Compute Unit provides the equivalent CPU capacity of a 1.0-1.2 GHz 2007 Opteron or 2007 Xeon processor.

In conclusion, two identical instance types of Amazon Cloud have the same number of EC2 Compute Units but because a EC2 Compute Unit is equivalent to a CPU capacity between 1.0Ghz and 1.2Ghz, the actual speed of the instance will be slightly different!
Mystery solved. 😉

, , , ,

No Comments

run-parts gives an exec format error

I got a problem the other day with a Linux script I made.
Basically, the script was working perfectly fine if I executed it directly from the command line but whenever I tried to run it with run-parts it failed!

This is the error message it returned:

%prompt> run-parts --report /etc/cron.daily
/etc/cron.daily/myscript:
run-parts: failed to exec /etc/cron.daily/myscript: Exec format error
run-parts: /etc/cron.daily/myscript exited with return code 1
%prompt>

Actually, the answer of this problem is quite simple! 🙂
I simply forgot the shebang on the first line of the script…

So, if you get the same error than me, make sure you have the following line at the beginning of your script:

#!/bin/sh

, , , , ,

5 Comments

Redmine 1.1.3 on HostMonster

Did you guys ever hear about Redmine? It is an open source project management web application written using Ruby on Rails framework. I already used it in the past and it is quite powerful!

I wanted to install the last version (1.1.3) on my HostMonster account. I would lie if I say that it has been easy… However, after a few try and some help from the HostMonster support, I finally got it to work. 🙂

These instructions are basically a copy of the ones I found on GetTaskDone but updated with additional steps (in red):

  1. Create MySQL Database and Username
    Login to CPanel and click on MySQL Database Wizard, it will prompt you for database name, then ask you to make a user, make sure you GRANT ALL privileges. Remember these database details, we will use them later.
  2. Create a Sub-Domain
    For the purposes of this tutorial, name it redmine, point this sub domain to ~/public_html/redmine.
    Do NOT copy any files into this directory, we will be deleting it later.
  3. Make sure you have the right version of Rails installed
    In case it is different from what you need you can install a specific Rails version on your machine by running:

    %prompt> gem install rails -v=2.3.5
    
  4. Create RoR directory
    It is not recommended that you put your RoR apps within the ~/public_html directory, as users would be able to see the rb files. So we are going to create a rails directory.

    %prompt> cd ~
    %prompt> mkdir rails
    
  5. Create Rails App
    You create a rails app on HostMonster just like you would on your system, by using the rails command. We are creating the rails project inside of the rails directory.

    %prompt> cd rails
    %prompt> rails -D redmine
    

    We need -D to let rails know that we want custom dispatch.rb, dispatch.cgi and dispatch.fcgi files for later steps.

  6. Create a Sym-Link for Sub-Domain
    Since the HostMonster interface won’t let you select a directory outside of public_html, we are going to create a symbolic link from the ~/public_html/redmine folder to ~/rails/redmine. To do this we will be deleting the ~/public_html/redmine directory. The symbolic link will recreate it.

    %prompt> cd ~/public_html
    %prompt> rm -R redmine
    %prompt> ln -s ~/rails/redmine/public redmine
    

    Please note the space between ~/rails/redmine/public and redmine This command says create a new folder named redmine that points to ~/rails/redmine/public

  7. Do a Smoke-Test
    Goto subdomain.yourdomain.com, you should see the default rails welcome page. This is fine, this is what you should see right now.
  8. Prepare Redmine
    Download the latest final release of Redmine (it’s 1.1.3 now). Extract this to your desktop, you should now have a folder name redmine on your desktop. Login to your CPanel and goto File Manager. You’ll want to navigate to ~/rails/redmine/public, you’ll want to download the following files and put them in your local copy of redmine. Which should be ~/Desktop/redmine/public. Download dispatch.rb, dispatch.cgi and dispatch.fcgi.
    Now edit your database.yml file with the database, username and password you created in step one. You only have to change those three values for production and development configurations. To do so copy config/database.yml.example into config/database.yml and edit the latter. Comment out all the rest lines.
    Now inside of your local redmine folder select all the files and folders and right click and select ‘Compress all the items…’. What we are doing is uploading this archive, I seem to have problems every time I try to upload redmine file by file.
  9. Upload Redmine
    If you don’t have File Manager open still then login to CPanel and open it again. Navigate to your ~/rails/redmine folder and click the check boxes on all items and click delete. Now, upload your archive. Once it’s done uploading click on the archive in File Manager and hit extract.
  10. Finish install
    Now ssh into your server, you’re going to want to chmod 755 your ~/rails/redmine/public folder.

    %prompt> cd ~/rails/redmine
    %prompt> chmod 755 public
    

    Next, you must create a custom .htaccess file for Apache to handle this directory properly. First remove any .htaccess file that may already be in the ~/rails/redmine/public directory.

    %prompt> cd public
    %prompt> rm .htaccess
    

    Download file from here: http://www.gettaskdone.com/redmine-htaccess/htaccess.txt into ~/rails/redmine/public directory and save it as .htaccess.
    Best way to do this is by typing following set of commands:

    %prompt> cd ~/rails/redmine/public
    %prompt> wget http://www.gettaskdone.com/redmine-htaccess/htaccess.txt
    %prompt> mv htaccess.txt .htaccess
    
  11. Edit Rakefile
    RubyGems 1.6.x is incompatible with the bundled rails 2.3.5. It’s documented in the RubyGems release notes that “RubyGems no longer requires ‘thread’. Rails < 3 will need to add require ‘thread’ to their applications.”
    So we need to add require 'thread' to the Rakefile after the line require 'rake/rdoctask'.
  12. Generate a session store secret
    This is required on the trunk version of Redmine at r2493 or above and the released 0.8.7 version or above.
    Redmine stores session data in cookies by default, which requires a secret to be generated. This can be done by running:

    %prompt> cd ~/rails/redmine
    %prompt> RAILS_ENV=production rake config/initializers/session_store.rb
    
  13. Edit config/enviroment.rb
    Insert the following code between the bootstrap and the initialize sections in the config/enviroment.rb file:

    if Gem::VERSION >= "1.3.6" 
        module Rails
            class GemDependency
                def requirement
                    r = super
                    (r == Gem::Requirement.default) ? nil : r
                end
            end
        end
    end
    
  14. Setup Database
    We have to give redmine its database structure and default values.

    %prompt> cd ~/rails/redmine
    %prompt> RAILS_ENV=production rake db:migrate
    
  15. Insert default configuration data in database
    Run the following command:

    %prompt> RAILS_ENV=production rake redmine:load_default_data
    

    This step is optional but highly recommended, as you can define your own configuration from scratch. It will load default roles, trackers, statuses, workflows and enumerations.

  16. Rename the ‘vendor/rails’ folder
    Run the following command:

    %prompt> mv vendor/rails vendor/rails.old
    

    The vendor directory generally takes precedence over the other locations where Rails looks for libraries, and if it contains different versions of gems or other items, it can cause conflicts.

For your information, these are the links I used to write this article:

, , , ,

1 Comment

Permissions ignored with Samba

After the issue regarding the ntpd process, I encountered another problem with my D-Link DNS-313. This time it was about permissions problem using Samba.

Because I have multiple user accounts sharing the same data, I added the following lines into the Samba configuration file (smb.conf):

create mask = 0774
directory mask  = 0775
force create mode = 0774
force directory mode = 0775

With these properties, a user will have the permission to read any files created by another user and will also be able to edit them if both users are part of the same group.

However, it appeared that these properties had been ignored by Samba! 🙁 Please note that the client was a Mac OS X 10.6.6 (Snow Leopard) and the Samba version on the NAS was 3.0.25a.

After some googling on the web, I found the following explanation on the contribs.org forum:

Samba 3.0.2x has the ‘unix extensions’ option set to ‘on’ by default. This allows Unix users who write to the Samba shares to set their own permissions bits. Mac OS X up until now has never attempted to do this, but from Leopard, any directory that gets created on a Samba share, get chmod’ed through this Samba extension.

Alright, this is clear enough! This means that we have to set the ‘unix extensions’ option to ‘no’ in our Samba configuration file:

unix extensions = no

The problem should be gone after restarting Samba. 🙂

, , , , , ,

7 Comments

ntpd process on D-Link DNS-313

During the configuration of a D-Link DNS-313 which is basically a NAS (Network-Attached Storage), I got a serious but easy-to-fix problem. 🙂

In order to get access to the box by command line, I installed the Fonz fun_plug. I then wanted to automatically synchronise the internal time with some NTP Pool Time Servers. But, for some reason, the version of the ntpd process provided with fun_plug is completely freezing the NAS. I wasn’t able to find the root cause of it, trust me, I tried everything I could think of!
Please also note that the same process is working perfectly fine on his brother, the D-Link DNS-323. As I said, I can’t explain why… 🙄

But there is a good news! The ntpd process is actually part of the D-Link DNS-313 firmware. And it is working fine! 😀 After double-checking, this process is however NOT part of the D-Link DNS-323 firmware. Why is that? Maybe D-Link got complaints from DNS-313 users and fixed it? Who knows…

Anyway, in order to get the ntpd process to work on the D-Link DNS-313, you need to replace the content of your ntpd startup script (/ffp/start/ntpd.sh) by the one below:

#!/ffp/bin/sh

# PROVIDE: ntpd
# REQUIRE: SERVERS
# BEFORE: LOGIN

. /ffp/etc/ffp.subr

name="ntpd"
command="/usr/sbin/ntpd"
ntpd_flags="-f /ffp/etc/ntpd.conf"
required_files="/ffp/etc/ntpd.conf"
start_cmd="ntpd_start"

ntpd_start()
{
    # remove rtc and daylight cron jobs
    crontab -l | grep -vw '/usr/sbin/daylight' | grep -vw '/usr/sbin/rtc' | crontab -

    proc_start $command
}

run_rc_command "$1"

, , , , , , , , ,

1 Comment