Skip to content

Commit

Permalink
Now able to handle stderr and stdout streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Dernise committed Aug 14, 2013
1 parent 15b091d commit 18d2de1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.rb
Expand Up @@ -4,6 +4,7 @@
require 'colored'
require 'daemons'
require 'eventmachine'
require 'io/wait'
require 'json'
require 'logger'
require 'open3'
Expand Down Expand Up @@ -36,7 +37,7 @@
ServiceManager.init
Console.show 'Managers loaded', 'info'

#SampleScroll = ScrollInstaller.new('Bukkit', {folder: 'minecraft_test', user:'dernise', port:25568})
# SampleScroll = ScrollInstaller.new('Bukkit', {folder: 'minecraft_test', user:'dernise', port:25568})
#SampleScroll.install

ServiceManager.start_service(2)
Expand Down
23 changes: 23 additions & 0 deletions modules/services/system.rb
Expand Up @@ -9,6 +9,7 @@ def daemonize(cmd, options = {})
rd.close
wr.write wait_thr[:pid]
wr.close
handle_output(stdout, stderr, wait_thr)
exit
}
Process.detach(p1) # divorce p1 from parent process (shell)
Expand All @@ -22,6 +23,28 @@ def daemonize(cmd, options = {})
daemon_id
end

def handle_output (stdout,stderr,wait_thr)
threads = []
threads << Thread.new { #handle stdout
while wait_thr.status
if stdout.ready?
puts stdout.gets
end
sleep 1
end
}

threads << Thread.new { #handle stderr
while wait_thr.status
if stderr.ready?
puts stderr.gets
end
sleep 1
end
}
threads.map(&:join)
end

#Launch the program as a specific User.
def set_user(uid)
if ::Process::Sys.geteuid == 0
Expand Down

0 comments on commit 18d2de1

Please sign in to comment.