Last active
December 28, 2015 01:49
-
-
Save andykingking/7423897 to your computer and use it in GitHub Desktop.
Quick script to start certain services for development
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 'sys/proctable' | |
module ProcTableGrep | |
def exist? | |
Sys::ProcTable.ps.each do |p| | |
return true if p.cmdline.include? @pgrep | |
end | |
false | |
end | |
end | |
module VMGrep | |
def exist? | |
result = `/Applications/VMware\\ Fusion.app/Contents/Library/vmrun list` | |
result.include? @pgrep | |
end | |
end | |
class ReqProcess | |
def initialize(name, pgrep, cmd, is_vmware=false) | |
@name = name | |
@pgrep = pgrep | |
@cmd = cmd | |
unless is_vmware | |
extend ProcTableGrep | |
else | |
extend VMGrep | |
end | |
end | |
def daemonize | |
fork {`#{@cmd}`} | |
puts "Started #{@name}." | |
end | |
end | |
processes = [] | |
# Add processes | |
processes.each {|p| p.daemonize unless p.exist?} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment