Class: Sambal::TestServer
- Inherits:
-
Object
- Object
- Sambal::TestServer
- Defined in:
- lib/sambal/test_server.rb
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#private_dir ⇒ Object
readonly
Returns the value of attribute private_dir.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#run_as ⇒ Object
readonly
Returns the value of attribute run_as.
-
#share_name ⇒ Object
readonly
Returns the value of attribute share_name.
-
#share_path ⇒ Object
readonly
Returns the value of attribute share_path.
-
#state_dir ⇒ Object
readonly
Returns the value of attribute state_dir.
-
#tmp_path ⇒ Object
readonly
Returns the value of attribute tmp_path.
Instance Method Summary collapse
- #find_pids ⇒ Object
-
#initialize(share_name = 'sambal_test', run_as = ENV['USER']) ⇒ TestServer
constructor
A new instance of TestServer.
- #start ⇒ Object
- #stop ⇒ Object
- #stop! ⇒ Object
- #write_config ⇒ Object
Constructor Details
#initialize(share_name = 'sambal_test', run_as = ENV['USER']) ⇒ TestServer
Returns a new instance of TestServer.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sambal/test_server.rb', line 38 def initialize(share_name='sambal_test', run_as=ENV['USER']) @erb_path = "#{File.(File.dirname(__FILE__))}/smb.conf.erb" @host = "127.0.0.1" ## will always just be localhost @root_path = File.(File.dirname(File.dirname(File.dirname(__FILE__)))) @tmp_path = "#{root_path}/spec_tmp" @share_path = "#{tmp_path}/share" @share_name = share_name @config_path = "#{tmp_path}/smb.conf" @lock_path = "#{tmp_path}" @pid_dir = "#{tmp_path}" @cache_dir = "#{tmp_path}" @state_dir = "#{tmp_path}" @log_path = "#{tmp_path}" @private_dir = "#{tmp_path}" @ncalrpc_dir = "#{tmp_path}" @port = Random.new(Time.now.to_i).rand(2345..5678).to_i @run_as = run_as FileUtils.mkdir_p @share_path write_config end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
31 32 33 |
# File 'lib/sambal/test_server.rb', line 31 def cache_dir @cache_dir end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
33 34 35 |
# File 'lib/sambal/test_server.rb', line 33 def config_path @config_path end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
36 37 38 |
# File 'lib/sambal/test_server.rb', line 36 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
26 27 28 |
# File 'lib/sambal/test_server.rb', line 26 def port @port end |
#private_dir ⇒ Object (readonly)
Returns the value of attribute private_dir.
30 31 32 |
# File 'lib/sambal/test_server.rb', line 30 def private_dir @private_dir end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
28 29 30 |
# File 'lib/sambal/test_server.rb', line 28 def root_path @root_path end |
#run_as ⇒ Object (readonly)
Returns the value of attribute run_as.
35 36 37 |
# File 'lib/sambal/test_server.rb', line 35 def run_as @run_as end |
#share_name ⇒ Object (readonly)
Returns the value of attribute share_name.
34 35 36 |
# File 'lib/sambal/test_server.rb', line 34 def share_name @share_name end |
#share_path ⇒ Object (readonly)
Returns the value of attribute share_path.
27 28 29 |
# File 'lib/sambal/test_server.rb', line 27 def share_path @share_path end |
#state_dir ⇒ Object (readonly)
Returns the value of attribute state_dir.
32 33 34 |
# File 'lib/sambal/test_server.rb', line 32 def state_dir @state_dir end |
#tmp_path ⇒ Object (readonly)
Returns the value of attribute tmp_path.
29 30 31 |
# File 'lib/sambal/test_server.rb', line 29 def tmp_path @tmp_path end |
Instance Method Details
#find_pids ⇒ Object
59 60 61 62 |
# File 'lib/sambal/test_server.rb', line 59 def find_pids pids = `ps ax | grep smbd | grep #{@port} | grep -v grep | awk '{print \$1}'`.chomp pids.split("\n").map {|p| (p.nil? || p=='') ? nil : p.to_i } end |
#start ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sambal/test_server.rb', line 70 def start if RUBY_PLATFORM=="java" @smb_server_pid = Thread.new do `smbd -S -F -s #{@config_path} -p #{@port} --lockdir=#{@lock_path} --piddir=#{@pid_dir} --private-dir=#{@private_dir} --cachedir=#{@cache_dir} --statedir=#{@state_dir} > #{@log_path}/smb.log` end else @smb_server_pid = fork do `smbd -S -F -s #{@config_path} -p #{@port} --lockdir=#{@lock_path} --piddir=#{@pid_dir} --private-dir=#{@private_dir} --cachedir=#{@cache_dir} --statedir=#{@state_dir} > #{@log_path}/smb.log` end end sleep 2 ## takes a short time to start up end |
#stop ⇒ Object
83 84 85 86 87 |
# File 'lib/sambal/test_server.rb', line 83 def stop ## stopping is done in an ugly way by grepping pids = find_pids pids.each { |ppid| `kill -9 #{ppid} 2> /dev/null` } end |
#stop! ⇒ Object
89 90 91 92 |
# File 'lib/sambal/test_server.rb', line 89 def stop! stop FileUtils.rm_rf @tmp_path unless ENV.key?('KEEP_SMB_TMP') end |
#write_config ⇒ Object
64 65 66 67 68 |
# File 'lib/sambal/test_server.rb', line 64 def write_config File.open(@config_path, 'w') do |f| f << Document.new(IO.binread(@erb_path)).interpolate(samba_share: @share_path, local_user: @run_as, share_name: @share_name, log_path: @log_path, ncalrpc_dir: @ncalrpc_dir) end end |