win32 service - daemon

Discussion in 'Ruby' started by Bigmac Turdsplash, Sep 15, 2009.

  1. i think i understand how the process works,

    require "rubygems"
    require "win32/service"
    require 'win32/daemon'
    include Win32

    # Create a new service
    Service.delete('netcat')
    Service.create('netcat', nil,
    :service_type => Service::WIN32_OWN_PROCESS,
    :description => 'just descriptgion',
    :start_type => Service::AUTO_START,
    :error_control => Service::ERROR_NORMAL,
    :binary_path_name => 'c:\test\rscript.exe',
    :load_order_group => 'Network',
    :dependencies => ['W32Time','Schedule'],

    :display_name => 'just displayg'
    )

    this writes to the registry, it also executes the the file as a service
    which confuses me because i dont see Service.start anywhere and the
    process only last for like 10...

    the reason it only last for a few seconds, The service did not respond
    to the start or control request in a timely fashion... sounds simple
    right? so, i need to add code to the rscript.exe

    require "rubygems"
    require 'win32/daemon'
    include Win32

    class Daemon
    def service_main
    while running?
    sleep 3
    File.open("c:\\test.log", "a"){ |f| f.puts "service is running"
    }
    # my program will do stuff here ? ? ? Right ???
    end
    end
    def service_stop
    exit!
    end
    end
    Daemon.mainloop

    this script wont compile with rubyscript2exe

    I need my executable to communicate with the service manager... this
    daemon script wont compile so now im stumped... idk what else to try...
    --
    Posted via http://www.ruby-forum.com/.
     
    Bigmac Turdsplash, Sep 15, 2009
    #1
    1. Advertising

  2. Bigmac Turdsplash, Sep 15, 2009
    #2
    1. Advertising

  3. Bigmac Turdsplash

    Ilias bankai Guest

    Trie to add the following to your daemon (service) script

    require 'RUBYSCRIPT2EXE' and exit if RUBYSCRIPT2EXE.is_compiling? (see
    below)

    require "rubygems"
    require 'RUBYSCRIPT2EXE'
    require 'win32/daemon'
    include Win32

    exit if RUBYSCRIPT2EXE.is_compiling?

    the 'exit if RUBYSCRIPT2EXE.is_compiling?' will stop the script from
    running and compile the code in the a exe file with the required gems.

    Good luck

    --
    Posted via http://www.ruby-forum.com/.
     
    Ilias bankai, Sep 16, 2009
    #3
  4. > the 'exit if RUBYSCRIPT2EXE.is_compiling?' will stop the script from
    > running and compile the code in the a exe file with the required gems.
    >
    > Good luck


    I just tried this, i get a long error when i try to compile...

    C:\decoy>ruby rubyscript2exe.rb netcat.rbruby netcat.rb
    Tracing netcat.rbruby ...
    netcat.rbruby doesn't exist.

    C:\decoy>ruby rubyscript2exe.rb netcat.rb
    Tracing netcat ...
    Gathering files...
    C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/requir
    e2lib.rb:60:in `gatherlibs': undefined method `list' for
    Gem::Specification:Clas
    s (NoMethodError)
    from
    C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscri
    pt2exe/require2lib.rb:30
    from netcat.rb:7
    C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/requir
    e2lib.rb:60:in `gatherlibs': undefined method `list' for
    Gem::Specification:Clas
    s (NoMethodError)
    from
    C:/Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscri
    pt2exe/require2lib.rb:30
    from netcat.rb:7
    Couldn't execute this command (rc=256):
    C:\Program Files\Metasploit\Framework3\bin\ruby -I
    'C:/Users/BiGMaC/AppData/Loc
    al/Temp/tar2rubyscript.d.1808.1/rubyscript2exe' -I
    'C:/Users/BiGMaC/AppData/Loca
    l/Temp/tar2rubyscript.d.1808.1' -I 'C:/Program
    Files/Metasploit/Framework3/lib/r
    uby/site_ruby/1.8' -I 'C:/Program
    Files/Metasploit/Framework3/lib/ruby/site_ruby
    /1.8/i386-msvcrt' -I 'C:/Program
    Files/Metasploit/Framework3/lib/ruby/site_ruby'
    -I 'C:/Program Files/Metasploit/Framework3/lib/ruby/1.8' -I 'C:/Program
    Files/M
    etasploit/Framework3/lib/ruby/1.8/i386-mswin32' -I '.' -I 'C:/decoy' -I
    'C:/User
    s/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe' -I
    'C:/Users
    /BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/lib'
    -I 'C:/Us
    ers/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe' -I
    'C:/Use
    rs/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/lib'
    -r 'C:/
    Users/BiGMaC/AppData/Local/Temp/tar2rubyscript.d.1808.1/rubyscript2exe/require2l
    ib.rb' 'netcat.rb'
    Stopped.

    C:\decoy>
    --
    Posted via http://www.ruby-forum.com/.
     
    Bigmac Turdsplash, Sep 16, 2009
    #4
  5. Bigmac Turdsplash

    Ilias bankai Guest

    if you are using gem version 1.3, Rubyscript2exe doesn't work anymore
    with this version. Try to downgrade if that's the case otherwise try
    using OCRA it does the same as Rubyscript2exe.

    Cheers
    --
    Posted via http://www.ruby-forum.com/.
     
    Ilias bankai, Sep 16, 2009
    #5
  6. Ilias bankai wrote:
    > if you are using gem version 1.3, Rubyscript2exe doesn't work anymore
    > with this version. Try to downgrade if that's the case otherwise try
    > using OCRA it does the same as Rubyscript2exe.
    >
    > Cheers


    ok, i found my problem... ruby2exe and ocra work just fine... I dont
    know how to properly install gems and library's... im not sure were the
    correct download is for this daemon lib is...

    C:\Users\BiGMaC>irb
    irb(main):001:0> require 'win32/daemon'
    LoadError: no such file to load -- win32/daemon
    from (irb):1:in `require'
    from (irb):1
    --
    Posted via http://www.ruby-forum.com/.
     
    Bigmac Turdsplash, Sep 17, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Paul Calderone
    Replies:
    0
    Views:
    480
    Jean-Paul Calderone
    Mar 20, 2009
  2. Floris Bruynooghe
    Replies:
    1
    Views:
    473
    Floris Bruynooghe
    Mar 24, 2009
  3. Andre Warnier

    open2(), win2k, perl5.6.1, Win32::Daemon

    Andre Warnier, Sep 10, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    119
    Andre Warnier
    Sep 10, 2003
  4. Replies:
    1
    Views:
    153
    robic0
    Apr 30, 2006
  5. Daemon Win32::Daemon;

    , Sep 7, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    276
Loading...

Share This Page