aBinaryMind

Some thoughts, some info, some rants

Archive for the ‘Linux/Unix’ Category

Redmine installation guide (Ubuntu)

Following is a guid to install Redmine (svn trunk) on Ubuntu 9.10.

The assumed location of Redmine is /srv/redmine

Phase 1: Setup Redmine

Step 1
Install required packages.

$ sudo apt-get install ruby rake ruby-dev rubygems libmysqlclient-dev libopenssl-ruby

Step 2
Check out Redmine trunk.

$ cd /srv
$ sudo svn co http://redmine.rubyforge.org/svn/trunk redmine

Step 3
Install required ruby gems:

$ sudo gem install rails mongrel mongrel_cluster daemons mysql actionmailer

Note 1: We may need to update Rails RAILS_GEM_VERSION in file [redmine]/config/environment.rb to reflect actual version of Rails gems installed.

Note 2: We may need to create soft link for rails & mongrel executables for convenient

$ sudo ln -s /var/lib/gems/1.8/bin/mongrel_rails /usr/local/bin/
$ sudo ln -s /var/lib/gems/1.8/bin/rails /usr/local/bin/
$ sudo ln -s /var/lib/gems/1.8/bin/mongrel_cluster_ctl /usr/local/bin/

Step 4
Create mysql database

$ mysql -u root -p
# Enter mysql root password when prompted

Run the following code in mysql, substitute your own database name, password, …

CREATE DATABASE redmine character SET utf8;
CREATE user 'redmine'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL privileges ON redmine.* TO 'redmine'@'localhost';

Step 5
Create/Update database parameters in [redmine]/config/database.yml accordingly to prior step info.

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: redmine
  password: my_password
  encoding: utf8

Step 6
Initialize the database

# Initialize session hash
$ sudo rake config/initializers/session_store.rb

# Load db schema
$ sudo rake db:migrate RAILS_ENV="production"

$ sudo rake redmine:load_default_data RAILS_ENV="production"

Step 7
Create redmine user & setting up directory permission

# Context: root:[redmine_dir]
$ sudo useradd redmine
$ sudo mkdir tmp public/plugin_assets
$ sudo chown -R redmine:redmine  files log tmp
$ sudo chmod -R 755 files log tmp public

Step 8
Testing the application server

$ sudo ruby script/server -e production

The server is listening on [http://localhost:3000].

Phase 2: Setup Apache & Mongrel Cluster

Step 1
Create mongrel cluster configuration files for Redmine.

$ sudo mongrel_rails cluster::configure -e production -p 3000 -N 3 -c /srv/redmine -a 127.0.0.1 --user redmine --group redmine

# Test mongrel_installation
$ sudo mongrel_rails cluster::start

Step 2
Create apache virtual host file at /etc/apache/sites-available/

<VirtualHost *:80>
  ServerName your.virtual-host.com
  DocumentRoot /srv/redmine

  <Directory /srv/redmine/public>
    AllowOverride FileInfo Indexes
  </Directory>

  RewriteEngine On

  # Redirect all non-static requests to Mongrel
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://redmine_cluster%{REQUEST_URI} [P,QSA,L]

  ProxyPassReverse / balancer://redmine_cluster
  ProxyPreserveHost on

  <Proxy balancer://redmine_cluster>
    BalancerMember http://localhost:3000
    BalancerMember http://localhost:3001
    BalancerMember http://localhost:3002
  </Proxy>

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  # Block access to .svn directories
  <DirectoryMatch "^/.*/\.svn/">
    ErrorDocument 403 /404.html
    Order allow,deny
    Deny from all
    Satisfy All
  </DirectoryMatch>
</VirtualHost>

Step 3
Turn on the virtual host and required modules

$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo a2enmod proxy_balancer
$ sudo a2ensite <your-virtualhost-file>

# Restart web server
$ sudo /etc/init.d/apache2 restart

Phase 3: Surviving the reboot & G!Mail SMTP

Step 1
Create global mongrel_cluster configuration

$ sudo mkdir /etc/mongrel_cluster
$ cd /etc/mongrel_cluster
$ sudo ln -s /srv/redmine/config/mongrel_cluster.yml /etc/mongrel_cluster/redmine.yml

Step 2
Update the services

$ cd /etc/init.d
$ sudo cp /var/lib/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/
$ sudo chmod +x /etc/init.d/mongrel_cluster
$ sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults

Step 3
Configure G!Mail

$ sudo ruby script/plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git
# File: config/email.yml
production:
  delivery_method: :smtp
  smtp_settings:
    tls: true
    address: "smtp.gmail.com"
    port: '587'
    domain: "smtp.gmail.com"
    authentication: :plain
    user_name: "your_email@gmail.com"
    password: "your_password"

References

  1. http://www.redmine.org/wiki/redmine/RedmineInstall
  2. http://ubuntuforums.org/showthread.php?t=674598
  3. http://azureusonrails.rubyforge.org/wiki/wiki.pl?Install/Mongrel_Cluster_With_Apache_2.2
  4. http://redmineblog.com/articles/setup-redmine-to-send-email-using-gmail/

Automatic virtual host with Apache

When developing with CakePHP, we can setup Apache to automatically redirect a domain to a specific CakePHP application.

We can set computer’s aliases using hosts file. Apache will automatically map aliases to different DocumentRoot:

app1.mybox.com -> /var/www/cakephp/app1.mybox.com/webroot
app2.somewhere.com -> /var/www/cakephp/app2.somewhere.com/webroot

Step 1: Enable the mod_vhost_alias:

$ sudo a2enmod vhost_alias

Step 2: Replace the DocumentRoot statement in default virtualhost configuration file with two lines:

UseCanonicalName    Off
VirtualDocumentRoot /var/www/cakephp/%0/webroot

(If you use a different virtualhost, make sure that you’re editing the right configuration file)

Step 3: However, the mod_rewrite doesn’t play nice with mod_vhost_alias. We need to edit the .htaccess file in {APP}/webroot folder.

    RewriteEngine On
    RewriteBase /   # << Add this line
    RewriteCond %{REQUEST_FILENAME} !-d

Step 4: Restart Apache.

sudo service apache2 restart

Below is my default virtual host configuration for your reference:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

        UseCanonicalName Off
    VirtualDocumentRoot /var/www/cakephp/%0/webroot

    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
</VirtualHost>
  • 0 Comments
  • Filed under: Linux/Unix
  • How to hide files in Nautilus

    In Linux, files which name start by a dot ‘.’ are hidden by default in most file managers. However, there are cases when we want to hide dot-file from our view. For examples:

    • Desktop folder in our home folder.
    • Dropbox
    • lost+found directory at the partition root

    In Nautilus (default GNOME file manager) there’s a way. Add a file named

    .hidden

    with each line is the name of the file/folder you want to hide.

    For example, if you want to hide Desktop from home folder you may type this command in the terminal:

    $ echo "Desktop" > ~/.hidden

    Note: This trick only works in Nautilus. It won’t work in Konqueror or Dolphin. I don’t know if it works in other file managers or not.

    gnome-colors

    The GNOME-Colors is a project that aims to make the GNOME desktop as elegant, consistent and colorful as possible.

    The current goal is to allow full color customization of themes, icons, GDM logins and splash screens. There are already five full color-schemes available; Brave (Blue), Human (Orange), Wine (Red), Noble (Purple) and Wise (Green).

    GNOME-Colors is mostly inspired/based on Tango, GNOME, Elementary, Tango-Generator and many other open-source projects.

    via gnome-colors – Google Code.

    Here is a way to rename files in bash, from upper case filenames to lowercase ones

    for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done

    via Rename files from upper case filename to lower case (in bash).

    Pyinotify

    Pyinotify is a pure Python module for monitoring filesystems changes. Pyinotify relies on inotify, a Linux Kernel functionnality (since kernel 2.6.13). inotify is an event-driven notification mechanism, its notifications are exported to user space through three system calls. Pyinotify binds these system calls and provides an implementation on top of them.

    via Pyinotify.

    Giữ một phiên làm việc SSH

    Khi bạn làm việc với máy chủ thông qua SSH thì bạn sẽ thường gặp một vấn đề nhỏ. Đó là dịch vụ SSH sẽ đóng kết nối của bạn sau một khoảng thời gian nhất định. Để ngăn dịch vụ SSH đóng kết nối thì chúng ta có cách sau:

    Sửa file

    /etc/ssh/ssh_config

    hoặc

    $HOME/.ssh/config

    và thêm vào đó dòng dưới đây

    ServerAliveInterval 60

    Chương trình C nhỏ dưới đây có thể giúp bạn tạm giữ một phiên làm việc bằng cách in ra một thanh xoay trong lúc chạy.

    #include <stdio.h>
    int i;
    char spin[4] = { '|', '/', '-', 0x5c };
    int main() {
        for(i=0;;usleep(300000), fflush(stdout))
            printf("%c\x08", spin[++i%4]);
        return 0;
    }
  • 0 Comments
  • Filed under: Linux/Unix, Tips
  • About Me

    I'm an introvert & a geek. If you have enough time, patience and curiosity, please read this and this . After that, I'm sure we're gonna get along very well ;-)

    Bookmarks