guard-redis 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 632ab4b4b54c4e8b9d3860ce6b6f7c1b52f77283
4
- data.tar.gz: da85a2b91081fcc2263a1fa5d4de3eee05df05aa
3
+ metadata.gz: fae5b604bb544bddec0334ad7491722faeb5f594
4
+ data.tar.gz: 0eac208b2d898a82e129fa9cad1323021b76036c
5
5
  SHA512:
6
- metadata.gz: e429cf1236bd4e8859e966174234e3a901f1f734322d338fa0fadb8f45fe1db0dc4b2eeb6c7e8fd920203b3619252866256823f2bf31dea55b808774ed9e4e1c
7
- data.tar.gz: d2ad050d41116680d37b1129872858fea48a9145a220385faa52a21ae748bee155f8321193a00a09e6521f673a2996ae4e865c2f9532469abe828b5ff1b313a0
6
+ metadata.gz: 77e10fae981ebba8c99b81a477224d166ab5bb4b06f2bbc5e779489ce5bed111df3b7007b37a04e6337200470e4cfabd0ba2d18dba59b2bc7f15dc406fbffd3d
7
+ data.tar.gz: 51ead19490a1e9fe643c79b2c4eed906e35df60221591e7ef316d504018f4fb15655e35d5ddc7b035d5c574a45fae4356df348af25bae41d3ca118a75e3017c2
data/README.md CHANGED
@@ -38,7 +38,7 @@ It takes several options related to its configuration.
38
38
 
39
39
  ### List of available options
40
40
  ~~~~ruby
41
- :executable => "/path/to/redis/server/executable" # Set the custom path to the Redis server executable
41
+ :executable => "/path/to/redis-server/executable" # Set the custom path to the Redis server executable
42
42
  :port => 9999 # Set a custom port number the Redis server is running on
43
43
  :pidfile => "/var/pid/redis.pid" # Set a custom path the where the pidfile is written
44
44
  :reload_on_change => false # Reload Redis if any of the specified files change. Note that you
@@ -53,5 +53,14 @@ It takes several options related to its configuration.
53
53
  # these options to ensure it does so cleanly before reloading with :reload_on_change.
54
54
  ~~~~
55
55
 
56
+ ### Pidfile location must be writable
57
+ Starting with version 2.0.0, the pidfile location you specify or the *default*
58
+ location (`/tmp/redis.pid`) if you don't specify **must be writable** or
59
+ guard-redis will fail to start.
60
+
61
+ **If you specify a pidfile location via the configuration and the directory path
62
+ doesn't exist, guard-redis will attempt to create it**. If it cannot write to that
63
+ directory, you will see an error and redis will fail to start.
64
+
56
65
  ## Contributors
57
66
  Thanks so much to [all who have contributed](https://github.com/whazzmaster/guard-redis/graphs/contributors)!
@@ -3,21 +3,30 @@ require 'guard/compat/plugin'
3
3
  module Guard
4
4
  class Redis < Plugin
5
5
  def start
6
- UI.info "Starting Redis on port #{port}..."
7
- @pid = nil
8
- IO.popen("#{executable} -", 'w+') do |server|
9
- @pid = server.pid
10
- server.write(config)
11
- server.close_write
6
+ @started = false
7
+ begin
8
+ ensure_pidfile_directory
9
+ UI.info "Starting Redis on port #{port}..."
10
+ IO.popen("#{executable} -", 'w+') do |server|
11
+ server.write(config)
12
+ server.close_write
13
+ end
14
+ UI.info "Redis is running with PID #{pid}"
15
+ @started = last_operation_succeeded?
16
+ rescue ::Exception => err
17
+ UI.error "Redis not started due to errors: #{err}"
12
18
  end
13
- UI.info "Redis is running with PID #{pid}"
14
- last_operation_succeeded?
19
+ @started
15
20
  end
16
21
 
17
22
  def stop
18
- shutdown_redis
19
- @pid = nil
20
- true
23
+ if redis_started?
24
+ shutdown_redis
25
+ true
26
+ else
27
+ UI.info "Redis never started. No need to shutdown."
28
+ true
29
+ end
21
30
  end
22
31
 
23
32
  def reload
@@ -35,6 +44,10 @@ module Guard
35
44
  reload if reload_on_change?
36
45
  end
37
46
 
47
+ def redis_started?
48
+ @started
49
+ end
50
+
38
51
  def shutdown_redis
39
52
  return UI.info "No instance of Redis to stop." unless pid
40
53
  return UI.info "Redis (#{pid}) was already stopped." unless process_running?
@@ -56,8 +69,20 @@ module Guard
56
69
  }
57
70
  end
58
71
 
72
+ def ensure_pidfile_directory
73
+ pidfile_dir = File.dirname(pidfile_path)
74
+ unless Dir.exist? pidfile_dir
75
+ UI.info "Creating pidfie directory #{pidfile_dir}"
76
+ FileUtils.mkdir_p pidfile_dir
77
+ end
78
+
79
+ unless File.writable? pidfile_dir
80
+ raise "no write access to pidfile directory #{pidfile_dir}"
81
+ end
82
+ end
83
+
59
84
  def config
60
- result = <<"END"
85
+ result = <<END
61
86
  daemonize yes
62
87
  pidfile #{pidfile_path}
63
88
  port #{port}
@@ -67,7 +92,18 @@ END
67
92
  end
68
93
 
69
94
  def pid
70
- (File.exist?(pidfile_path) && File.read(pidfile_path).to_i) || @pid
95
+ count = 0
96
+ loop do
97
+ if count > 5
98
+ raise "pidfile was never written to #{pidfile_path}"
99
+ end
100
+
101
+ break if File.exists? pidfile_path
102
+ UI.info "Waiting for pidfile to appear at #{pidfile_path}..."
103
+ count += 1
104
+ sleep 1
105
+ end
106
+ File.read(pidfile_path).to_i
71
107
  end
72
108
 
73
109
  def executable
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module RedisVersion
3
- VERSION = '1.0.1'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachery Moneypenny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: redis
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.2'
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.2'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: 1.3.6
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.4
128
+ rubygems_version: 2.4.5
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Guard gem for Redis