Ruby doesn't execute and show source

Discussion in 'Installation/Configuration' started by minttux, Mar 14, 2016.

  1. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    Create the old mod_ruby.so for apache 2.4 using Ubuntu 14.04

    Make sure you're using ruby 1.9 - it unlikely will work with newer versions!
    Some logging and probably auth informations will not work. This module is considered obsolete and nobody will give you support if something goes wrong.
    There is no guarantee this will work for you or the results are as expected.
    I would not recommend using it on productive systems. It probably is useless but ....



    We need a few build tools and dev packages

    Code:
    apt-get install cmake libaprutil1-dev libapr1-dev ruby ruby-dev apache2-dev
    



    Prepare folders and build dir.
    Code:
    mkdir /usr/local/src/mod_ruby_old
    cd /usr/local/src/mod_ruby_old
    wget https://github.com/shugo/mod_ruby/archive/master.zip
    unzip master.zip
    


    Put the attached patch to the current directory /usr/local/src/mod_ruby_old and apply the patch
    Code:
    cd mod_ruby-master
    patch -i ../mod_ruby.txt
    


    Now lets make it
    Code:
    ./configure.rb --with-apxs --with-apr-includes=/usr/include/apr-1.0
    make
    make install
    



    Create /etc/apache2/mods-available/ruby.load with the following content
    Code:
    LoadModule ruby_module /usr/lib/apache2/modules/mod_ruby.so
    
    Code:
    a2enmod ruby
    

    Now just enable Ruby in your ISPConfig
     

    Attached Files:

    Last edited: Mar 16, 2016
  2. minttux

    minttux Member

    Thanks it compiled and i could install mod_ruby but after apache restart it doesn't open any page and pages just loading and in apache error log i have:
    Code:
    [Tue Mar 15 22:09:07.310811 2016] [core:notice] [pid 31707] AH00051: child pid 32308 exit signal Segmentation fault (11), possible coredump in /etc/apache2
    [Tue Mar 15 22:09:07.311398 2016] [:notice] [pid 32323] mod_ruby[32323]: startup_module
    [Tue Mar 15 22:09:07.311979 2016] [:notice] [pid 32322] mod_ruby[32322]: startup_module
    [Tue Mar 15 22:09:07.320688 2016] [:notice] [pid 32321] mod_ruby[32321]: startup_module
    [Tue Mar 15 22:09:07.321243 2016] [:notice] [pid 32326] mod_ruby[32326]: startup_module
    [Tue Mar 15 22:09:07.321748 2016] [:notice] [pid 32325] mod_ruby[32325]: startup_module
    [Tue Mar 15 22:09:07.322245 2016] [:notice] [pid 32324] mod_ruby[32324]: startup_module
    [Tue Mar 15 22:09:07.336695 2016] [:notice] [pid 32327] mod_ruby[32327]: startup_module
    [Tue Mar 15 22:09:07.337281 2016] [:notice] [pid 32320] mod_ruby[32320]: startup_module
    [Tue Mar 15 22:09:07.340304 2016] [core:notice] [pid 31707] AH00051: child pid 32309 exit signal Segmentation fault (11), possible coredump in /etc/apache2
    [Tue Mar 15 22:09:07.344312 2016] [core:notice] [pid 31707] AH00051: child pid 32310 exit signal Segmentation fault (11), possible coredump in /etc/apache2
    [Tue Mar 15 22:09:07.344394 2016] [core:notice] [pid 31707] AH00051: child pid 32311 exit signal Segmentation fault (11), possible coredump in /etc/apache2
    
    So i disable mod_ruby and now apache works
     
  3. minttux

    minttux Member

    it could not make and return error:
    Code:
    root@server:/usr/local/src/mod_ruby_old/mod_ruby-master# make
    gcc   -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC -Wall  -pipe -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security   -DLINUX -D_REENTRANT -D_GNU_SOURCE  -pthread  -I. -I/usr/include/ruby-1.9.1 -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/apache2 -I/usr/include/apr-1.0    -omod_ruby.o -c mod_ruby.c
    mod_ruby.c: In function ‘ruby_register_hooks’:
    mod_ruby.c:240:5: warning: passing argument 1 of ‘ap_hook_error_log’ from incompatible pointer type [enabled by default]
         ap_hook_error_log(ruby_error_log_handler, NULL, NULL, APR_HOOK_MIDDLE);
         ^
    In file included from /usr/include/apache2/ap_hooks.h:40:0,
                     from /usr/include/apache2/ap_config.h:25,
                     from /usr/include/apache2/httpd.h:44,
                     from mod_ruby.h:100,
                     from mod_ruby.c:33:
    /usr/include/apache2/ap_hooks.h:75:35: note: expected ‘void (*)(const struct ap_errorlog_info *, const char *)’ but argument is of type ‘void (*)(const char *, int,  int,  apr_status_t,  const struct server_rec *, const struct request_rec *, struct pool *, const char *)’
             APR_DECLARE_EXTERNAL_HOOK(ap,AP,ret,name,args)
                                       ^
    /usr/include/apr-1.0/apr_hooks.h:120:22: note: in definition of macro ‘APR_DECLARE_EXTERNAL_HOOK’
    link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
                          ^
    /usr/include/apache2/http_core.h:891:1: note: in expansion of macro ‘AP_DECLARE_HOOK’
    AP_DECLARE_HOOK(void, error_log, (const ap_errorlog_info *info,
    ^
    mod_ruby.c: At top level:
    mod_ruby.c:501:6: error: conflicting types for ‘ruby_log_error’
    void ruby_log_error(const char *file, int line,
          ^
    In file included from mod_ruby.c:33:0:
    mod_ruby.h:300:6: note: previous declaration of ‘ruby_log_error’ was here
    void ruby_log_error(const char *file, int line, int level,
          ^
    mod_ruby.c: In function ‘run_safely_0’:
    mod_ruby.c:1067:24: warning: unused variable ‘targ’ [-Wunused-variable]
         struct timeout_arg targ;
                            ^
    mod_ruby.c: In function ‘run_safely’:
    mod_ruby.c:1088:11: warning: unused variable ‘thread’ [-Wunused-variable]
         VALUE thread, ret;
               ^
    mod_ruby.c: At top level:
    mod_ruby.c:1045:14: warning: ‘do_timeout’ defined but not used [-Wunused-function]
    static VALUE do_timeout(struct timeout_arg *arg)
                  ^
    make: *** [mod_ruby.o] Error 1
    
    and it's my apache2 and ruby version:
    Code:
    # apachectl -V
    AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-ispconfig.conf:61
    Server version: Apache/2.4.7 (Ubuntu)
    Server built:   Jan 14 2016 17:45:23
    Server's Module Magic Number: 20120211:27
    Server loaded:  APR 1.5.1-dev, APR-UTIL 1.5.3
    Compiled using: APR 1.5.1-dev, APR-UTIL 1.5.3
    Architecture:   64-bit
    Server MPM:     prefork
      threaded:     no
        forked:     yes (variable process count)
    Server compiled with....
    -D APR_HAS_SENDFILE
    -D APR_HAS_MMAP
    -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
    -D APR_USE_SYSVSEM_SERIALIZE
    -D APR_USE_PTHREAD_SERIALIZE
    -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
    -D APR_HAS_OTHER_CHILD
    -D AP_HAVE_RELIABLE_PIPED_LOGS
    -D DYNAMIC_MODULE_LIMIT=256
    -D HTTPD_ROOT="/etc/apache2"
    -D SUEXEC_BIN="/usr/lib/apache2/suexec"
    -D DEFAULT_PIDLOG="/var/run/apache2.pid"
    -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
    -D DEFAULT_ERRORLOG="logs/error_log"
    -D AP_TYPES_CONFIG_FILE="mime.types"
    -D SERVER_CONFIG_FILE="apache2.conf"
    root@server:/usr/local/src/mod_ruby_old/mod_ruby-master# ruby -v
    ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
    
     
  4. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    Hmm I wasn't able to reproduce either the first nor the second issue :/
    Did you see any errors while applying the patch file?
    My ruby.c looks like
    http://s000.tinyupload.com/index.php?file_id=21370299087222088094

    I don't think that's a 32/64bit issue

    if I have some time later, I'll try on 64 bit

    Oh and I didn't need
    "RubyConfig GEM_PATH /usr/lib/ruby/gems/2.0.0/gems/"
     
  5. minttux

    minttux Member

    Are u sure your patch file is correct ? it seems on ) is lost:
    [​IMG]also i replace my mod_ruby.c file with yours and i get error when run make.
    and it's output of patch:
    Code:
    # patch -i 1.txt
    patching file apachelib.c
    Hunk #2 succeeded at 207 with fuzz 2.
    patching file apachelib.h
    patching file connection.c
    patching file mod_ruby.c
    Hunk #1 succeeded at 317 with fuzz 2 (offset 74 lines).
    Hunk #2 FAILED at 498.
    Hunk #3 FAILED at 1514.
    2 out of 3 hunks FAILED -- saving rejects to file mod_ruby.c.rej
    patching file mod_ruby.h
    Hunk #2 FAILED at 297.
    1 out of 2 hunks FAILED -- saving rejects to file mod_ruby.h.rej
    patching file request.c
    Hunk #2 succeeded at 1178 with fuzz 2.
    Hunk #3 FAILED at 1472.
    Hunk #4 FAILED at 1489.
    Hunk #5 FAILED at 1504.
    Hunk #6 FAILED at 1521.
    4 out of 6 hunks FAILED -- saving rejects to file request.c.rej
    patching file server.c
    
     
    Last edited: Mar 15, 2016
  6. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    Yes, I did all the steps I posted on fresh source to verify they're working.
    The line you're seeing there is just a marker for the patch program.
    It belongs to server.c line 70 which indeed has a newline at this point
     
  7. minttux

    minttux Member

    i removed everything and uzip again and now patch with fixed last line and it was output of patch then configure then make and it shows error
    Code:
    # patch -i ../1.txt
    patching file apachelib.c
    Hunk #2 succeeded at 207 with fuzz 2.
    patching file apachelib.h
    patching file connection.c
    patching file mod_ruby.c
    Hunk #1 succeeded at 243 with fuzz 2.
    patching file mod_ruby.h
    Hunk #2 FAILED at 297.
    1 out of 2 hunks FAILED -- saving rejects to file mod_ruby.h.rej
    patching file request.c
    Hunk #2 succeeded at 1178 with fuzz 2.
    Hunk #3 FAILED at 1472.
    Hunk #4 FAILED at 1489.
    Hunk #5 FAILED at 1504.
    Hunk #6 FAILED at 1521.
    4 out of 6 hunks FAILED -- saving rejects to file request.c.rej
    patching file server.c
    
    
    
    root@server:/usr/local/src/mod_ruby_old/mod_ruby-master# make
    make: *** No targets specified and no makefile found.  Stop.
    root@server:/usr/local/src/mod_ruby_old/mod_ruby-master# ./configure.rb --with-apxs --with-apr-includes=/usr/include/apr-1.0
    ./configure.rb:301: Use RbConfig instead of obsolete and deprecated Config.
    checking for a BSD compatible install... /usr/bin/install -c
    checking whether we are using gcc... yes
    checking Ruby version... 1.9.3
    checking for static Apache module support... no
    checking for dynamic Apache module support... yes
    creating Makefile
    creating libruby.module
    creating doc/Makefile
    
    
    
    root@server:/usr/local/src/mod_ruby_old/mod_ruby-master# make
    gcc   -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC -Wall  -pipe -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security   -DLINUX -D_REENTRANT -D_GNU_SOURCE  -pthread  -I. -I/usr/include/ruby-1.9.1 -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/apache2 -I/usr/include/apr-1.0    -omod_ruby.o -c mod_ruby.c
    mod_ruby.c: In function ‘ruby_register_hooks’:
    mod_ruby.c:240:5: warning: passing argument 1 of ‘ap_hook_error_log’ from incompatible pointer type [enabled by default]
         ap_hook_error_log(ruby_error_log_handler, NULL, NULL, APR_HOOK_MIDDLE);
         ^
    In file included from /usr/include/apache2/ap_hooks.h:40:0,
                     from /usr/include/apache2/ap_config.h:25,
                     from /usr/include/apache2/httpd.h:44,
                     from mod_ruby.h:100,
                     from mod_ruby.c:33:
    /usr/include/apache2/ap_hooks.h:75:35: note: expected ‘void (*)(const struct ap_errorlog_info *, const char *)’ but argument is of type ‘void (*)(const char *, int,  int,  apr_status_t,  const struct server_rec *, const struct request_rec *, struct pool *, const char *)’
             APR_DECLARE_EXTERNAL_HOOK(ap,AP,ret,name,args)
                                       ^
    /usr/include/apr-1.0/apr_hooks.h:120:22: note: in definition of macro ‘APR_DECLARE_EXTERNAL_HOOK’
    link##_DECLARE(void) ns##_hook_##name(ns##_HOOK_##name##_t *pf, \
                          ^
    /usr/include/apache2/http_core.h:891:1: note: in expansion of macro ‘AP_DECLARE_HOOK’
    AP_DECLARE_HOOK(void, error_log, (const ap_errorlog_info *info,
    ^
    mod_ruby.c: At top level:
    mod_ruby.c:501:6: error: conflicting types for ‘ruby_log_error’
    void ruby_log_error(const char *file, int line,
          ^
    In file included from mod_ruby.c:33:0:
    mod_ruby.h:300:6: note: previous declaration of ‘ruby_log_error’ was here
    void ruby_log_error(const char *file, int line, int level,
          ^
    mod_ruby.c: In function ‘run_safely_0’:
    mod_ruby.c:1067:24: warning: unused variable ‘targ’ [-Wunused-variable]
         struct timeout_arg targ;
                            ^
    mod_ruby.c: In function ‘run_safely’:
    mod_ruby.c:1088:11: warning: unused variable ‘thread’ [-Wunused-variable]
         VALUE thread, ret;
               ^
    mod_ruby.c: At top level:
    mod_ruby.c:1045:14: warning: ‘do_timeout’ defined but not used [-Wunused-function]
    static VALUE do_timeout(struct timeout_arg *arg)
                  ^
    make: *** [mod_ruby.o] Error 1
    
    What about error for previous mod_ruby ? it's old one the previous complied but apache segment fault for it
     
  8. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    Again, the patch file is alright, no need to fix anything. Regarding your segmention fault - I've not been able to reproduce this issue - you could try installing -dbg files and debug what's wrong or where it fails.
    Have you enabled any 3rd party repositories ? I was using stock debian 8 and ubuntu 14.04 and did not have any issues, well but 32bit
     
  9. minttux

    minttux Member

    But it worked.Thanks
     
  10. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    I'm going to try it on 64bit anyway :) It's bothering me it didn't work for you, so I give it one last attempt to compile it on 64bit.
    However, keep in mind using CGI is slow and it allows any program beeing executed since it's not limited to #!/usr/bin/ruby ...
     
  11. minttux

    minttux Member

    Thanks a lot i never forget it

    You'r right. but its better something work as a ruby feature until there is checkbox that doesn't do anything
     
  12. ztk.me

    ztk.me ISPConfig Developer ISPConfig Developer

    Indeed, it does behave a bit different. I did some debugging but as said, it's none of my daily business rewriting apache modules :D
    We do have an issue somewhere
    However, I was curious and I got a solution ( maybe ) - however, I just played around and I defnitly don't know how it will effect anything but the new mod_ruby does not segfault anymore....

    change src/ruby.cpp startup function to the following code
    Code:
    void startup(const char* script_name)
    {
        if (running)
        {
            return;
        }
    
        int fake_argc = 0;
    //    char* fake_args[fake_argc];
    //    char** fake_argv = fake_args;
        char **fake_argv;
    
        ruby_sysinit(&fake_argc, &fake_argv);
    
        // Initialize Ruby itself
        RUBY_INIT_STACK;
        ruby_init();
    
        ruby_init_loadpath();
        //Init_prelude();
        //ruby_init_gems();
    
        // To load prelude.rb
    //    static char* args[] = { "ruby", "/dev/null" };
    //    ruby_process_options(2,args);
    
        // Load Ruby encodings, otherwise we'll get all kinds of "Unitialized
        // constanct Encoding::UTF-7", etc. everywhere.
    //    rb_enc_find_index("encdb");
    
    //    VALUE gem;
    //    gem = rb_define_module("Gem");
    //    rb_const_set(gem, rb_intern("Enable"), Qtrue);
    //    rb_require("rubygems");
    
    
    
    
        ruby_script((char*)script_name);
    
        running = true;
    
    
    }
    
    This is for the new mod_ruby, not the old one.
    The old mod_ruby does compile well! ( but segfaults aswell on 64bit ) but there's no issue like you described.
     
    Last edited: Mar 16, 2016
  13. minttux

    minttux Member

    Thanks it worked now.
    i put mod-ruby.deb package for everyone needs to install it on ubuntu 64bit
    so just enable it and change template
     

    Attached Files:

    till likes this.

Share This Page