guard-restarter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-restarter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Caleb Spare
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Guard::Restarter
2
+
3
+ This is a small guard plugin to run a command (typically a server) and restart it when files change. It
4
+ restarts the process by killing it (with SIGINT, followed by SIGKILL if it doesn't die after a bit). It takes
5
+ care of ensuring the process (and any children) are gone before bringing it up again.
6
+
7
+ ## Installation
8
+
9
+ $ gem install guard-restarter
10
+
11
+ or add it to your gemfile:
12
+
13
+ ``` ruby
14
+ gem "guard-restarter"
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Pretty straightforward:
20
+
21
+ ``` ruby
22
+ guard :restarter, :command => "./run_server" do
23
+ watch(/\.*\.[ch]$/)
24
+ end
25
+ ```
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/guard/restarter", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "guard-restarter"
6
+ gem.version = Guard::Restarter::VERSION
7
+ gem.authors = ["Caleb Spare"]
8
+ gem.email = ["cespare@gmail.com"]
9
+ gem.description =<<EOS
10
+ guard-restarter is a guard plugin to run a command (often a server) and restart it when files change.
11
+ EOS
12
+ gem.summary = %q{A guard-plugin to restart a server.}
13
+ gem.homepage = "https://github.com/cespare/guard-restarter"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "guard"
21
+ end
@@ -0,0 +1,67 @@
1
+ require "guard"
2
+ require "guard/guard"
3
+ require "guard/watcher"
4
+
5
+ module Guard
6
+ class Restarter < ::Guard::Guard
7
+ VERSION = "0.0.1"
8
+
9
+ def initialize(watchers = [], options = {})
10
+ super
11
+ @pid = nil
12
+ @command = options[:command]
13
+ raise "Must provide option :command" unless @command
14
+ end
15
+
16
+ def start()
17
+ start_info
18
+ start_server
19
+ end
20
+
21
+ def run_on_changes(paths)
22
+ run_info
23
+ stop_server
24
+ start_server
25
+ end
26
+
27
+ def stop() stop_server end
28
+
29
+ private
30
+
31
+ def start_server
32
+ @pid = spawn @command, :chdir => Dir.pwd, :pgroup => true
33
+ Process.detach(@pid)
34
+ end
35
+
36
+ def stop_server
37
+ unless @pid && @pid > 0 && server_is_running
38
+ UI.info "Error: server not started."
39
+ return
40
+ end
41
+ UI.info "Stopping server..."
42
+ Process.kill "INT", -@pid
43
+ 20.times do
44
+ return unless server_is_running
45
+ sleep 0.05
46
+ end
47
+ UI.info "Killing server forcibly."
48
+ Process.kill "KILL", -@pid
49
+ end
50
+
51
+ def server_is_running()
52
+ !!Process.kill(0, @pid) rescue false
53
+ end
54
+
55
+ def start_info
56
+ UI.info "Running command '#{@command}'..."
57
+ end
58
+
59
+ def run_info
60
+ if @pid
61
+ UI.info "Process started, pid #{@pid}"
62
+ else
63
+ UI.info "Error starting process."
64
+ end
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-restarter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Caleb Spare
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! 'guard-restarter is a guard plugin to run a command (often a server)
31
+ and restart it when files change.
32
+
33
+ '
34
+ email:
35
+ - cespare@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - .gitignore
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - guard-restarter.gemspec
45
+ - lib/guard/restarter.rb
46
+ homepage: https://github.com/cespare/guard-restarter
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A guard-plugin to restart a server.
70
+ test_files: []
71
+ has_rdoc: