fallen 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/.gitignore +2 -0
  2. data/.yardopts +3 -0
  3. data/README.md +2 -2
  4. data/fallen.gemspec +5 -2
  5. data/lib/fallen.rb +43 -1
  6. metadata +8 -5
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  *.gem
2
+ .yardoc
3
+ doc/
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup=markdown
2
+ lib/**/*.rb -
3
+ README.md UNLICENSE
data/README.md CHANGED
@@ -11,7 +11,7 @@ module Azazel
11
11
 
12
12
  def self.run
13
13
  while running?
14
- puts "My name is Legion"
14
+ puts "Time is on my side... Yes it is..."
15
15
  sleep 666
16
16
  end
17
17
  end
@@ -20,7 +20,7 @@ end
20
20
  Azazel.start!
21
21
  ```
22
22
 
23
- This will print _My name is Legion_ every 666 seconds on `STDOUT`. You can stop the daemon by pressing `CTRL+c`.
23
+ This will print _Time is on my side... Yes it is.._ every 666 seconds on `STDOUT`. You can stop the daemon by pressing `CTRL+c`.
24
24
 
25
25
  ## Control your daemon
26
26
  `Fallen` accepts the following methods:
data/fallen.gemspec CHANGED
@@ -2,12 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "fallen"
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
  s.summary = "A simpler daemon library"
7
7
  s.description = "A simpler way to create Ruby fallen angels, better known as daemons"
8
8
  s.authors = ["Leandro López"]
9
9
  s.email = ["inkel.ar@gmail.com"]
10
- s.homepage = "https://github.com/inkel/fallen"
10
+ s.homepage = "http://inkel.github.com/fallen"
11
+ s.license = "UNLICENSE"
12
+
13
+ s.required_ruby_version = '>= 1.9.2'
11
14
 
12
15
  s.files = `git ls-files`.split("\n")
13
16
  end
data/lib/fallen.rb CHANGED
@@ -5,37 +5,68 @@ module Fallen
5
5
  @stdout = nil
6
6
  @stderr = nil
7
7
 
8
+ # Detachs this fallen angel from current process and runs it in
9
+ # background
10
+ #
11
+ # @note Unless `STDIN`, `STDOUT` or `STDERR` are redirected to a
12
+ # file, these will be redirected to `/dev/null`
8
13
  def daemonize!
9
- Process.daemon true
14
+ Process.daemon true, (@stdin || @stdout || @stderr)
10
15
  end
11
16
 
17
+ # Changes the working directory
18
+ #
19
+ # All paths will be relative to the working directory unless they're
20
+ # specified as absolute paths.
21
+ #
22
+ # @param [String] path of the new workng directory
12
23
  def chdir! path
13
24
  Dir.chdir File.absolute_path(path)
14
25
  end
15
26
 
27
+ # Path where the PID file will be created
16
28
  def pid_file path
17
29
  @pid_file = File.absolute_path(path)
18
30
  end
19
31
 
32
+ # Reopens `STDIN` for reading from `path`
33
+ #
34
+ # This path is relative to the working directory unless an absolute
35
+ # path is given.
20
36
  def stdin path
21
37
  @stdin = File.absolute_path(path)
22
38
  STDIN.reopen @stdin
23
39
  end
24
40
 
41
+ # Reopens `STDOUT` for writing to `path`
42
+ #
43
+ # This path is relative to the working directory unless an absolute
44
+ # path is given.
25
45
  def stdout path
26
46
  @stdout = File.absolute_path(path)
27
47
  STDOUT.reopen @stdout, "a"
28
48
  end
29
49
 
50
+ # Reopens `STDERR` for writing to `path`
51
+ #
52
+ # This path is relative to the working directory unless an absolute
53
+ # path is given.
30
54
  def stderr path
31
55
  @stderr = File.absolute_path(path)
32
56
  STDERR.reopen @stderr, "a"
33
57
  end
34
58
 
59
+ # Returns `true` if the fallen angel is running
35
60
  def running?
36
61
  @running
37
62
  end
38
63
 
64
+ # Brings the fallen angel to life
65
+ #
66
+ # If a PID file was provided it will try to store the current
67
+ # PID. If this files exists it will try to check if the stored PID
68
+ # is already running, in which case `Fallen` will exit with an error
69
+ # code.
39
70
  def start!
40
71
  if @pid_file && File.exists?(@pid_file)
41
72
  pid = File.read(@pid_file).strip
@@ -51,6 +82,11 @@ module Fallen
51
82
  end
52
83
  end
53
84
 
85
+ # Runs the fallen angel
86
+ #
87
+ # This will set up `INT` & `TERM` signal handlers to stop execution
88
+ # properly. When this signal handlers are called it will also call
89
+ # the `stop` callback method.
54
90
  def run!
55
91
  save_pid_file
56
92
  @running = true
@@ -59,6 +95,10 @@ module Fallen
59
95
  run
60
96
  end
61
97
 
98
+ # Stops fallen angel execution
99
+ #
100
+ # This method only works when a PID file is given, otherwise it will
101
+ # exit with an error.
62
102
  def stop!
63
103
  if @pid_file && File.exists?(@pid_file)
64
104
  pid = File.read(@pid_file).strip
@@ -74,10 +114,12 @@ module Fallen
74
114
  end
75
115
  end
76
116
 
117
+ # Callback method to be run when fallen angel stops
77
118
  def stop; end
78
119
 
79
120
  private
80
121
 
122
+ # Save the falen angel PID to the PID file specified in `pid_file`
81
123
  def save_pid_file
82
124
  File.open(@pid_file, "w") do |fp|
83
125
  fp.write(Process.pid)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fallen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simpler way to create Ruby fallen angels, better known as daemons
15
15
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .yardopts
22
23
  - README.md
23
24
  - UNLICENSE
24
25
  - examples/azazel.rb
@@ -26,8 +27,9 @@ files:
26
27
  - fallen.gemspec
27
28
  - lib/fallen.rb
28
29
  - lib/fallen/cli.rb
29
- homepage: https://github.com/inkel/fallen
30
- licenses: []
30
+ homepage: http://inkel.github.com/fallen
31
+ licenses:
32
+ - UNLICENSE
31
33
  post_install_message:
32
34
  rdoc_options: []
33
35
  require_paths:
@@ -37,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
39
  requirements:
38
40
  - - ! '>='
39
41
  - !ruby/object:Gem::Version
40
- version: '0'
42
+ version: 1.9.2
41
43
  required_rubygems_version: !ruby/object:Gem::Requirement
42
44
  none: false
43
45
  requirements:
@@ -51,3 +53,4 @@ signing_key:
51
53
  specification_version: 3
52
54
  summary: A simpler daemon library
53
55
  test_files: []
56
+ has_rdoc: