Last active
December 31, 2015 07:09
-
-
Save mignev/7952334 to your computer and use it in GitHub Desktop.
Fast rails runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
# thanks to @mitio | |
UNIXSocket.open('/tmp/fast.pid') do |fastrails| | |
fastrails.write ARGV.join(' ') | |
puts fastrails.read | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fast-rails | |
code ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This file is located at /usr/bin/ | |
exec scl-exec-ruby ruby /root/socket/client.rb "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# scl <action> <collection1>...<collectionN> <command> doesn't handle multiple params for command. | |
# If it did we would use: exec scl enable ruby193 "$@" | |
# This file is located at /usr/bin/ | |
COMMAND="$(printf "%q " "$@")" | |
exec scl enable ruby193 "$COMMAND" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require 'stringio' | |
require "/var/www/approot/railsapp/config/environment" | |
server_pid = "/tmp/fast.pid" | |
File.delete(server_pid) if File.exist?(server_pid) | |
server = UNIXServer.new(server_pid) | |
puts "Fast Rails runner is started!" | |
loop do | |
client = server.accept | |
client_arguments = client.recv(1024) | |
splited_client_aruments = client_arguments.split(' ') | |
command = splited_client_aruments.slice!(0) | |
arguments = splited_client_aruments | |
fork do | |
arguments.each do |argument| | |
ARGV << argument | |
end | |
begin | |
$stdout = StringIO.new | |
# thanks to @mitio | |
load(command) | |
client.puts($stdout.string) | |
rescue SystemExit | |
client.puts($stdout.string) | |
rescue Exception | |
client.puts( $!, $@ ) | |
end | |
end | |
trap "CLD" do | |
pid = Process.wait | |
puts "Child pid #{pid}: terminated" | |
end | |
client.close | |
end |
Хардкоднатия път е защото ми трябва да си реша проблема само с 1 проект :), не съм го планирал за повевече от един прокет :)
Намира се във /var/www
приложението е измислено да работи там поради някаква причина ?!? Трябва да питам RedHat защот така са го решили :))
Относно trap
-a ... не мисля, че мога да ти дам разумент отговор ... мисля, че имаше някаква причина .... но не съм сигурен в момента!
Относно drb
мерси :) ще го погледна, изглежда наистина интересно.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Хардкоднатия път към приложението е греда. Още повече, какво прави development проекта във
/var/www
? Това ми мяза на някакви PHP навици, и то лоши.trap
-а защо е в вloop
-а? Не върши ли работа ако го сложиш извън?Иначе, яко. Ако ти се вдига level, може да разгледаш
drb
за да не се занимаваш със сокети като грешен дявол.