Entries Tagged 'Ruby' ↓

Gitlab reque & supervisord

Gitlab needs at least one resque daemon. I always forget to start it when I boot the (virtual) pc where gitlab resides. So I installed supervisord an set up this conf file:
/etc/supervisor/conf.d/resque.conf:

[program:resque]
command=bundle exec rake environment resque:work
# Do not use BACKGROUND=No, it only checks if BACKGROUND is set
environment=QUEUE="post_receive,mailer,system_hook",RAILS_ENV="production"
process_name=resque
numprocs=1
directory=/home/gitlab.tim-online.nl/public_html
autostart=true
autorestart=true
user=gitlab.tim-online.nl

Upgrading gitlab to the new stable


cd ~/public_html/
git checkout stable
RAILS_ENV=production rake db:migrate
bundle install --without development test --deployment
sudo service nginx restart

How to install gitlab on Ubuntu Server 12.04 (precise) the right way

This weekend I’ve been installing Gitlab on a LXC guest. The host is running Ubuntu 12.04 and so is the guest. I tried to document my steps the best I could so I could share my experiences with it. Sometimes I had to go back a few steps so maybe something are garbled up but I believe this is still a good starting point on setting up gitlab on a Ubuntu server.

My main goals were:

  • use as much software from the Ubuntu repositories as possible so I don’t have to worry about security updates et cetera
  • keep the installation as simple as possible so I know when I look at it over 6 months
  • keep the software (gitolite) in the default Ubuntu location(s)
This tutorial assumes you have some good knowledge about Linux (servers) so I doesn’t spell out everything.

The steps found on the Gitlab website are quite accurate so keep them in mind:

  1. login as user, install git & generate ssh key
  2. Install ruby 1.9.2
  3. Install gitolite with umask 0007 and add your user to git group
  4. logout & login again
  5. Clone & setup gitlab (checkout project wiki on github)
  6. Start server. Enjoy!

My global setup

  • Installed Gitolite, Redis and Ruby from the default Ubuntu repositories
  • Installed Nginx (nginx-full) with Ruby/Phusion Passenger support from the Brightbox testing repositories (stable didn’t yet support Ubuntu 12.04 Precise)
  • Gitlab + dependencies are managed by bundler (build from source)
  • Nginx is running as the gitlab user

Step 1: installing Nginx with Phusion Passenger (mod_rails) support on Ubuntu 12.04

add-apt-repository ppa:brightbox/passenger-nginx-testing
apt-get update
apt-get install nginx-full
cat <<EOF > /etc/nginx/conf.d/passenger.conf
passenger_root /usr/lib/phusion-passenger;
EOF

I had some troubles with this version of Nginx from Brightbox because of some missing mime-type config file. That was quickly solved by copying it from another server.

The configuration file of my gitlab virtual host I put in: /etc/nginx/sites-available/gitlab.host.tld.

The contents of that file can be found here.

Step 2: installing dependencies from Ubuntu sources

apt-get install gitolite ruby1.9.3 redis-server ruby-budler rake

For the gitolite configure screens: just keep hitting enter

Step 3: installing build dependencies for ruby gems needed by gitlab

apt-get install make libxml2-dev g++ libicu-dev ruby2.9.1-dev libmysqlclient-dev libsqlite3-dev

Step 4: setting up your gitlab user: creating it, giving it permissions and generating a ssh key

adduser --disabled-login --disabled-password --force-badname gitlab.host.tld
usermod --append --groups gitolite gitlab.host.tld
su -s /bin/bash gitlab.host.tld
ssh-keygen
exit

Step 5: configuring gitolite with the ssh public key of your gitlab user

(as root)

dpkg-reconfigure gitolite

The question about the public key can be answered with the contents of `/home/gitlab.host.tld/.ssh/id_rsa.pub`

Step 6: loosening the permissions so the gitlab user can reach the gitolite files

Only do this when you know what you’re doing!

chmod g+rw /var/lib/gitolite/repositories --recursive
chmod g+rw /var/lib/gitolite/.gitolite.rc

This works because we added our user gitlab.host.tld to the gitolite group remember?

Next: edit /var/lib/gitolite/.gitolite.rc and change this line:

$REPO_UMASK = 0077; # gets you 'rwx------'

to:

$REPO_UMASK = 0007; # rwxrwx---

This makes sure newly created files/directories by gitolite are also writable by the gitolite group.

Step 7: installing gitlab itself

If everything worked out the system is ready and gitlab itself can be installed:

su -s /bin/bash gitlab.host.tld
cd ~/public_html
git clone git://github.com/gitlabhq/gitlabhq.git .

Step 8: Install the gitlab dependencies

This one is tricky. Maybe I forgot to list some build dependencies or maybe the added some extra dependencies since I wrote this. If this doesn’t succeed: read the logs (especially mkfm.log).

bundle install --deployment

Step 9: configure gitlab

cp config/database.yml.example config/database.yml
cp config/gitlab.yml.example config/gitlab.yml

Here is my gitlab.yml

It has admin_uri defined twice because of bug #1052
If you wouldn’t define it twice (in git_host and git) the rake task `gitlab:app:status` would always fail when you run gitolite under the user `gitolite`.

You can find out the contents of your own database.yml :)

Step 10: installing the database and compiling the assets

bundle exec rake db:setup RAILS_ENV=production
bundle exec rake db:seed_fu RAILS_ENV=production
rake assets:precompile

Step 11: check if your gitlab user has access to gitolite

RAILS_ENV=production rake gitlab:app:status

Rembember bug #1052!

Step 12: starting resque workers

Start at least one resque worker:

./resque.sh

And maybe another one:

./resque.sh

The resque workers are background workers that do `stuff` in the background. I believe for example the adding of ssh keys to gitolite and the parsing of a commit and putting that in the database.

At first I forget to start the resque workers and my keys weren’t properly added to gitolite. The solution to that was in my case:

RAILS_ENV=production rake gitlab:gitolite:update_hooks
RAILS_ENV=production rake gitlab:gitolite:update_keys
RAILS_ENV=production rake gitlab:gitolite:update_repos

Step 13: restart nginx & surf to http://gitlab.host.tld

The title says it all :)

Finally

I copied all the commands from the servers’ bash history command. The order of the commands I wrote down on top of my head so there could be some mistakes there. If you spot something wrong or missing: just contact me of leave a comment.

Some excellent resources:

Sublime Text 2

I installed sublime text on my Ubuntu 11.10 box but I had some troubled loading external python modules:

loaded 937 snippets
&gt;&gt;&gt; import distutils
Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
ImportError: No module named distutils

This is how I solved it:

Edited ~/.local/share/applications/sublime.desktop
Especially this line:

Exec="/home/leon/Software/bin/sublime" %U

/home/leon/Software/bin/sublime contains this:

#!/bin/bash
cd /usr/lib/python2.7
/home/leon/Software/SublimeText2/sublime_text

Then I installed some excellent plugins:

Choosing a new editor: Emacs vs. Vim

For php I use Zend Studio for Linux. We have a license at work for it and it is in my opinion the best editor for php. It’s relatively fast and you can use it to quickfix php over an ftp connection.

For Ruby I use netbeans. I would also like to use it for php but it doesn’t allow to quicly open a file via ftp/scp or whatever. And it can sometimes be sloooooowwww. I’ve  seen netbeans used on a Windows platform and there it is much faster.

When I right-click on a project in netbeans for the first time, it takes 5 seconds (not lying!) to render the popup-menu. Come onm take forever!

And because I was now developing with Python I decided to try a new editor. Something more hardcore and lighter. Something nerdy :) So ofcourse I only have two decent options: Vim & Emacs.

I already had try them with Ruby. But I found good Ruby (& Rails) support rather lacking by both of them. I believe that the python comminity is more hardcore and therefore are using more arcane editors :) And maybe because they aren’t afraid to hack away in another language than their own (lisp, vimscript).

I think I have been comparing the two editors for nearly two weeks now. I have spent hours and hours comparing, trying and browsing for blog posts about the two. At the end, I really didn’t know which one to choose. I really suck at deciding something :) So I made a little list of what I find to be strong points of each editor:

VIM:

  • Better syntax highlighting/theming supprt (wombat ftw!!)
  • Faster/smaller
  • No weird handling of new buffers like with emacsclient
  • No daemon like: emacs –daemon
  • Better python integration
  • Easier to make extensions
  • Preview of docstrings when using omni completion

EMACS:

  • Better python-mode
  • No commandmode/normalmode
  • Directory browser/editor
  • Debugger (better integration with external tools)
  • easier to begin
  • Everyting is a buffer™

And now I have chosen to be the editor with which I am going to work is…… (drum roll please) …….:

Gedit!

No, it’s (g)Vim :)

And while writing this article I was looking for a WordPress/blog plugin for Vim and Emacs. At a glance it looked like the wordpress plugin for Emacs was a little bit better. So already I was doubting my decision… So it could be that I switch editor in the next few months :) But I’m first going to really use gvim to see if it fits with my workflow and is really useable for me.

As cherry on the pie, a nice screenshot of my gvim in action:

Vim with python-mode

[update]
I’ve installed Netneans 6.8m2 and it feels a lot faster than 6.7 but python completion is as bad as in 6.7.
[/update]

[update2]
Found out about Vim’s netrw. So Emacs no longer got “Directory browser/editor” as a strong point.
[/update2]

Rmp -> Pmpd

monty-pythonI’ve ditched Ruby for my mpd project and started using Python. Not that I like python that much more but the Gstreamer library for python is much more complete. I really wanted gapless playback and the Ruby Gstreamer libray just doesn’t support that. If it does by the time you read this: please let me know :)

The new Pmpd project (looking for a better name) can be found on github. The hardest part so far is having to restructure the sources. Python is not a difficult language to master at all but I’m very picky on how everything fits together. My ruby project felt right on that part. But the python equivelant has some things I just don’t like enough up to now.

Ruby on Rails: custom fields on a per-user basis

I’m now developing a flexible car database for a couple of hours per week. Our first customer, a Beemer dealer, has a lot of fancy requests. Well, the hired-in Flash developer has these requests actually.

One of them is that they want to save a field in the database that contains a unique identification number for the secondhand cars they sell. But this number is set-up in a way that is unique to BMW’s. So actually, I didn’t want to add this column to the database, ’cause that will mess up my clean database tables.

But then I came up with the idea to add functionality to the website where users (dealers in this case) can add custom columns to their cars / profiles.

Instead of creating this functionality from scratch, I first wanted to know if there are any plugins that have this functionality already. I found these three:

  1. acts_as_free_form
  2. has-magic-columns
  3. acts_as_customizable

I haven’t decided (yet) which is best.

And if you want to roll your own, here’s a nice article about choosing the best structure for dynamic fields.

I realize that the story above is written in truly horrible English. But I really didn’t have the energy to make something nice of it…

Compiling jruby from source in Ubuntu Intrepid Ibex


Very easy to do:

sudo aptitude install ant openjdk-6-jdk
cd ~/src
svn co http://svn.codehaus.org/jruby/trunk/jruby/
cd jruby
ant
bin/jruby --version

Installing fcgid with suexec AND phusion passenger


It was a troublesome day today. All did not go as planned.

I had to install fcgid + suexec on one of our servers, I had delayed it too long. So I used my how-to and it still worked flawless. But I noticed I hadn’t mentioned what the right were of the suexec binary. So here it goes:

chown root:www-data suexec
chmod 4754 suexec

After the install I restarted Apache and looked at one of the sites. And it worked! I was baffled. That’s the first time I installed fcgid without hours long of searching where the flaw was.

But then I looked at our support system (Redmine) and it didn’t work too well :)

All controllers were being executed ‘n stuff. But the stylesheets, images and javascripts were not loaded. When requesting an image in the browser I got Rails 404-error page. Huh? Apache should have handled that request. At first I thought it was because of some changes I made to the virtualserver configuration of an other Rails site. But after some trial and error I couldn’t find anything that was wrong.

Then I removed the .htaccess from the public directory of Redmine. That once worked for one of my rails sites. But no cigar. Then I noticed that there were a lot of dispatch*example.rb’s in the public directory. And: after removing them, the stuff worked. So it seems like Rails or Phusion Passenger uses some kind of fuzzy matching when searching for a dispatch.rb. And it first just worked because fcgid was not installed. So I don’t know who’s to blame. But the problem is solved. Phew!

Rails vs. Merb

This will be a short post: I like merb/datamapper better. It’s cleaner and faster.

But, I have to finish a project this week and merb/datamapper is not just stable yet, has less documentation, less plugins, less helpers and less features.

For example, the “has and belongs to many” association in datamapper isn’t fully implemented (look a the tests). There are some nice backend generators for Rails. And if you have to finish a project in too little time, it’s a quick decision.

I know, I could also make/fix this stuff for merb and datamapper myself and I would love to. But there just isn’t enough time! Aaarghhh…