Tag: Ruby

Installing Rhodes on Ubuntu and making it run on Ruby 2.1

People who want to use Rhodes are recommended to use it under Ruby 1.9.3. But to me it seems kinda old. This is a way to install and run it on 2.1:

Oracle Java

Oracle Java is a recommended one to use with Rhodes, so just:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

SDK and NDK

Download both SDK and NDK. After that extract them in the same directory.

Rhodes gem

ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
gem install rhodes --no-ri --no-rdoc
# This will take some time...
Fetching: extlib-0.9.16.gem (100%)
Successfully installed extlib-0.9.16
Fetching: templater-1.0.0.gem (100%)
Successfully installed templater-1.0.0
# Bla bla bla...
7 gems installed

and now the harder part...

Rhodes setup

rhodes-setup
We will ask you a few questions below about your dev environment.
JDK path (required) (): /usr/lib/jvm/java-8-oracle
Android SDK path (blank to skip) (): /home/user/Android/android-sdk-linux
Android NDK path (blank to skip) (): /home/user/Android/android-ndk-r10
Windows Mobile 6 SDK CabWiz (blank to skip) (): 
BlackBerry JDE 4.6 (blank to skip) (): 
BlackBerry JDE 4.6 MDS (blank to skip) (): 
BlackBerry JDE 4.2 (blank to skip) (): 
BlackBerry JDE 4.2 MDS (blank to skip) (): 

Rhodes test app

Now we need a test app that will tell us what errors do we have related to our Ruby version:

rhodes app testapp
cd ./testapp

If you try to run rake -T you won't see any tasks. Instead you'll see path to your Rhodes gem sources:

rake -T
/home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12
# go there
cd /home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12

Rakefile changes

We need to make some changes to few files. To see rake tasks, we need to change one thing in Rhodes rakefile:

# I assume you're in Rhodes gem dir
# cd /home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12
# vim Rakefile

# Around line 33 - remove all of this:
module Rake
  class Task
    attr_accessor :comment
  end
end

Now in our app dir we can:

rake -T
rake build:android:eclipsebundle        # Build RhoBundle for Eclipse project
rake build:android:extensions           # Building native extensioons
rake build:android:rhobundle            # Build RhoBundle for android
rake build:symbian:rhobundle            # Build symbian rhobundle
rake build:wp8:rhobundle                # Build WP8 rhobundle
rake build:wp:rhobundle                 # Build WP7 rhobundle
rake clean:android                      # Clean Android
rake clean:bb                           # Clean bb
rake clean:bbsim                        # Clean bb and simulator
rake clean:iphone                       # Clean iphone
rake clean:win32                        # Clean win32
rake clean:wince                        # Clean windows ce
rake clean:wm                           # Clean wm
rake clean:wp                           # Clean wp
rake clean:wp8                          # Clean wp
rake config:checkbb                     # Check local blackberry configuration
rake device:android:debug               # Build debug self signed for device
rake device:android:production          # Build production signed for device
rake device:bb:debug                    # Build debug for device
rake device:bb:production               # Build production for device
rake device:iphone:production           # Builds and signs iphone for production
rake device:symbian:production          # Build production for device
rake device:win32:production            # Build installer for Windows
rake device:wince:production            # Build production for device or emulator
rake device:wm:production               # Build production for device or emulator
rake device:wp8:production              # Build production for device or emulator
rake device:wp:production               # Build production for device or emulator
rake run:android                        # build and launch emulator
rake run:android:device                 # build and install on device
rake run:android:rhosimulator           # Run application on RhoSimulator
# a lot of tasks...
rake uninstall:android                  # uninstall from emulator
rake uninstall:android:device           # uninstall from device

Android SDK setup

Go to your Android SDK dir and:

chmod +x ./tools/android
./tools/android

And use the Android 4.2.2 (API 17). Below you can see a printscreen of all the elements you need to have installed. If you have a Android L or any higher API than API 17, please remove them. Rhodes seems to have some issues with them.

android

androidcommon.rb changes

If you try to run your testapp, you will end up with following error:

Can't detect NDK toolchain path (corrupted NDK installation?)
/home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/androidcommon.rb:88:in `setup_ndk'
/home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/android.rake:388:in `block (2 levels) in <top (required)>'
/home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => run:android => run:android:emulator => config:android:emulator => config:android
(See full trace by running task with --trace)

edit androidcommon.rb and change:

@@ -71,8 +71,9 @@ def setup_ndk(ndkpath,apilevel)
   $ndktools = nil
   $ndkabi = "unknown"
   $ndkgccver = "unknown"
-  ["arm-linux-androideabi-4.4.3", "arm-eabi-4.4.0", "arm-eabi-4.2.1"].each do |abi|
+  ["arm-linux-androideabi-4.6", "arm-eabi-4.4.0", "arm-eabi-4.2.1"].each do |abi|
     variants = []
     variants << File.join(ndkpath, "toolchains", abi, "prebuilt", $ndkhost)
     variants << File.join(ndkpath, "build/prebuilt", $ndkhost, abi)
     variants.each do |variant|
@@ -118,6 +119,7 @@ def setup_ndk(ndkpath,apilevel)
   end
 
   variants.each do |variant|
     sysroot = File.join(ndkpath, variant, "android-#{last_api_level}/arch-arm")
     next unless File.directory? sysroot
     $ndksysroot = sysroot
@@ -244,7 +246,8 @@ def cc_run(command, args, chdir = nil)
   cmdstr = argv.map! { |x| x.to_s }.map! { |x| x =~ / / ? '' + x + '' : x }.join(' ')
   puts cmdstr
   $stdout.flush
-  argv = cmdstr if RUBY_VERSION =~ /^1\.[89]/
+  argv = cmdstr if RUBY_VERSION =~ /^(1\.[89]|2\.[0-9])/
   IO.popen(argv) do |f|
     while data = f.gets
       puts data

android_tools.rb changes

If you get this error:

NoMethodError: undefined method `rm_f' for AndroidTools:Module
/home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/android_tools.rb:211:in `run_emulator'
/home/user/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/android.rake:1971:in `block (3 levels) in <top (required)>'
/home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => run:android => run:android:emulator
(See full trace by running task with --trace)

Here's fix for that (in android_tools.rb):

@@ -208,7 +208,7 @@ module_function :is_device_running
 def  run_emulator(options = {})
   system("\"#{$adb}\" start-server")
 
-  rm_f $applog_path if !$applog_path.nil?
+  FileUtils.rm_f $applog_path if !$applog_path.nil?
   logcat_process()
   
   unless is_emulator_running

Android SDK tools symlinks and changes

Apkbuilder

In your Android SDK dir run:

cat android | sed -e 's/com.android.sdkmanager.Main/com.android.sdklib.build.ApkBuilderMain/g' > apkbuilder
chmod a+x apkbuilder

Zipalign

cp ./build-tools/19.1.0/zipalign ./tools

aapt and lib

ln -s /home/mencio/Software/Android/android-sdk-linux/build-tools/19.1.0/aapt ./platform-tools/
ln -s /home/mencio/Software/Android/android-sdk-linux/build-tools/19.1.0/lib ./platform-tools/

error: device not found

Last thing to change. If you get this error:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: device not found
- waiting for device -
rake aborted!
Unable to create AVD image. No appropriate target API for SDK version: 2.1
/home/mencio/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/android_tools.rb:231:in `run_emulator'
/home/mencio/.rvm/gems/ruby-2.1.2/gems/rhodes-3.5.1.12/platform/android/build/android.rake:1971:in `block (3 levels) in <top (required)>'
/home/mencio/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/mencio/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => run:android => run:android:emulator
(See full trace by running task with --trace)

you need to edit your build.yml file and change:

android:
  version: 2.1

to 4.2.2 (or any other that you use)

android:
  version: 4.2.2

After all of that, you should be able to run:

rake run:android

NameError: uninitialized constant Gem::Builder

If you have this issue and you still want to build Rhodes from sources (Github), please downgrade:

gem update --system 1.8.25

Then just:

rake gem
gem install ./rhodes-5.0.2.gem

and get back to new gem version:

gem update --system

Running GitLab 7.1 using Puma instead of a Unicorn

Warning

Warning! Before you do this, please read why you should'nt: why did gitlab 6 switch back to unicorn?

So now, when

you-have-been-warned

let's get started...

Gemfile updates

Nothing special here. Just add:

gem 'puma'

and then:

# From /home/gitlab/gitlab
sudo bundle install --no-deployment
sudo -u gitlab -H bundle install --deployment --without development test postgres

Puma config

Create a puma.rb file in your gitlab config dir and copy/paste this:

app_path = File.expand_path(File.dirname(File.dirname(__FILE__)))

rails_env = ENV['RAILS_ENV'] ||  'production'
environment rails_env

threads 4, 32
workers 2

daemonize true
bind                 "unix://#{app_path}/tmp/puma/sock"
state_path           "#{app_path}/tmp/puma/state"
pidfile              "#{app_path}/tmp/puma/pid"
activate_control_app "unix://#{app_path}/tmp/puma/ctlsock"
stdout_redirect      "#{app_path}/log/puma_access.log", "#{app_path}/log/puma_error.log"

preload_app!

and

mkdir /home/git/gitlab/tmp/puma

At this point, you should be able to execute puma worker:

# You should execute this from a git user
cd /home/git/gitlab && exec bundle exec puma -C /home/git/gitlab/config/puma.rb

[4419] Puma starting in cluster mode...
[4419] * Version 2.9.0 (ruby 2.1.2-p95), codename: Team High Five
[4419] * Min threads: 4, max threads: 32
[4419] * Environment: production
[4419] * Process workers: 2
[4419] * Preloading application
[4419] * Listening on unix:///home/git/gitlab/tmp/puma/sock

Init Script

To manage my Pumas I use Jungle. You can read more about it here. From this point, I assume that you have figured out a way to autostart GitLab Puma process (if not, you'll have to start it each time manually - good luck!).

Unfortunately it is not all. Default GitLab init script (provided with GitLab sources) will try to run Unicorn, so we need to silent it (but we need to keep the Sidekiq part).

To do so, we have to change the /etc/init.d/gitlab script.

start_gitlab() method (line 165) - we have to comment the else case:

  # Then check if the service is running. If it is: don't start again.
  if [ "$web_status" = "0" ]; then
    echo "The Unicorn web server already running with pid $wpid, not restarting."
  # else
    # Remove old socket if it exists
    # rm -f "$socket_path"/gitlab.socket 2>/dev/null
    # Start the web server
    # RAILS_ENV=$RAILS_ENV bin/web start
  fi

wait_for_pids() method (line 78) - we have to remote the first condition from while loop. We no longer check for web_server_pid_path:

wait_for_pids(){
  # We are sleeping a bit here mostly because sidekiq is slow at writing it's pid
  i=0;
  while [ ! -f $sidekiq_pid_path ]; do
    sleep 0.1;
    i=$((i+1))
    if [ $((i%10)) = 0 ]; then
      echo -n "."
    elif [ $((i)) = 301 ]; then
      echo "Waited 30s for the processes to write their pids, something probably went wrong."
      exit 1;
    fi
  done
  echo
}

There are some other places that you could modify - so you would not get any warnings, but hey! Those are just warnings. What I did above is an absolute minimum for starting/stopping Sidekiq without any Unicorn errors.

Nginx server block

And an example Nginx server block (virtual host) config:

upstream git.server.name {
  server unix:///home/git/gitlab/tmp/puma/sock;
}

server {
  server_name git.server.name;
  client_max_body_size 32M;

  keepalive_timeout 5;

  root /home/git/gitlab/public;
  access_log /var/log/nginx/git.server.name.access.log;
  error_log  /var/log/nginx/git.server.name.error.log;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;

    if (-f $request_filename) {
      break;
    }

    if (!-f $request_filename) {
      proxy_pass http://git.server.name;
      break;
    }
  }
}

After that - you are ready to go! Good luck!

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑