Created
December 27, 2011 07:39
-
-
Save tastycode/1522961 to your computer and use it in GitHub Desktop.
system commands gists
This file contains hidden or 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
| module FFMpeg | |
| class Convert | |
| attr_accessor :version, :total_time, :frame, :total_frames, :capturing, | |
| :input_fps | |
| def initialize(input, output, options={}) | |
| @input = input | |
| @output = output | |
| @options = options | |
| failure_msg = "FATAL: cannot find ffmpeg command" | |
| failure_msg << " (#{ self.class.base_command })" | |
| self.class.system_command(failure_msg) do | |
| cmd = "#{ self.class.base_command } --version 2> /dev/null" | |
| system cmd | |
| end | |
| end | |
| def self.base_command | |
| ENV['FFMPEG'] || 'ffmpeg' | |
| end | |
| #... | |
| end |
This file contains hidden or 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 'escape' | |
| require 'set' | |
| require 'tempfile' | |
| require 'sunspot/solr/java' | |
| require 'sunspot/solr/installer' | |
| module Sunspot | |
| module Solr | |
| class Server #:nodoc: | |
| # ... | |
| # | |
| # Start the sunspot-solr server. Bootstrap solr_home first, | |
| # if neccessary. | |
| # | |
| # ==== Returns | |
| # | |
| # Boolean:: success | |
| # | |
| def start | |
| bootstrap | |
| if File.exist?(pid_path) | |
| existing_pid = IO.read(pid_path).to_i | |
| begin | |
| Process.kill(0, existing_pid) | |
| raise(AlreadyRunningError, "Server is already running with PID #{existing_pid}") | |
| rescue Errno::ESRCH | |
| STDERR.puts("Removing stale PID file at #{pid_path}") | |
| FileUtils.rm(pid_path) | |
| end | |
| end | |
| fork do | |
| pid = fork do | |
| Process.setsid | |
| STDIN.reopen('/dev/null') | |
| STDOUT.reopen('/dev/null', 'a') | |
| STDERR.reopen(STDOUT) | |
| run | |
| end | |
| FileUtils.mkdir_p(pid_dir) | |
| File.open(pid_path, 'w') do |file| | |
| file << pid | |
| end | |
| end | |
| end | |
| # | |
| # Run the sunspot-solr server in the foreground. Boostrap | |
| # solr_home first, if neccessary. | |
| # | |
| # ==== Returns | |
| # | |
| # Boolean:: success | |
| # | |
| def run | |
| bootstrap | |
| command = ['java'] | |
| command << "-Xms#{min_memory}" if min_memory | |
| command << "-Xmx#{max_memory}" if max_memory | |
| command << "-Djetty.port=#{port}" if port | |
| command << "-Djetty.host=#{bind_address}" if bind_address | |
| command << "-Dsolr.data.dir=#{solr_data_dir}" if solr_data_dir | |
| command << "-Dsolr.solr.home=#{solr_home}" if solr_home | |
| command << "-Djava.util.logging.config.file=#{logging_config_path}" if logging_config_path | |
| command << '-jar' << File.basename(solr_jar) | |
| FileUtils.cd(File.dirname(solr_jar)) do | |
| exec(Escape.shell_command(command)) | |
| end | |
| end | |
| # ... | |
| end | |
| end |
This file contains hidden or 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
| ruby-1.9.2-p290 :002 > Executor::command("expr 5 / 0") | |
| Executor::CommandFailure: Command "expr 5 / 0" failed with expr: division by zero |
This file contains hidden or 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
| ruby-1.9.2-p290 :011 > Executor::command("sleep 10 && echo 5") do |result| | |
| ruby-1.9.2-p290 :012 > puts "got result #{result}" | |
| ruby-1.9.2-p290 :013?> end | |
| => #<Thread:0x007fde40827a28 run> | |
| ruby-1.9.2-p290 :014 > sleep 10 | |
| got result 5 | |
| => 10 | |
| ruby-1.9.2-p290 :015 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment