daemon-ogre 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/README.md +68 -13
  2. data/README.rdoc +122 -55
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/daemon-ogre.gemspec +2 -2
  6. data/lib/daemon-ogre.rb +340 -329
  7. metadata +3 -1
data/README.md CHANGED
@@ -24,6 +24,32 @@ but we love config our beloved App!
24
24
  # with "start" arguments like :
25
25
  # ruby my_awsome_app.rb start
26
26
 
27
+ In use?
28
+ -------
29
+
30
+
31
+ you can simply use your terminal with arguments like
32
+ * start - for start the process if you choosed :terminate => true in code like above
33
+ start command will check does the application already running or not, so you dont have to worry about
34
+
35
+ * stop - will terminate the running application
36
+ * restart - will stop the process if that is already running than start again
37
+ * debug - this will show the fancy loadings if you want look busy by coding big stuffs :) (or debug your code)
38
+ * debugger - this will call the ruby debugger gem to aid you in trouble
39
+ you should use these commands:
40
+
41
+ set autolist on #show the code, and the position like and editor, in every step.
42
+ s #step in any kind of method, beware to use carefully because you end up in really deep somewhere in Alice world
43
+ n #step to next code/codeblock etc, without enter it (usefull when you find the right place)
44
+ l #list your current position
45
+ #simply hit enter to repeate the last one
46
+
47
+ * daemon or -d -this will fork a child process by the given parameters
48
+ * log or -l -you can set the log file position n by terminal for one time run
49
+ * pid or -p -you can set the pid file position n name by terminal for one time run
50
+ * status or -s -this will tell you ,does your process is running not
51
+ * help -this will invoke some help to the terminal if you out of luck and forget everything from this page
52
+
27
53
 
28
54
  othere stuffs to use:
29
55
  ---------------------
@@ -69,33 +95,59 @@ and if you hate find all the bugs... you can use error_logger at your command li
69
95
  your awsome code!
70
96
 
71
97
  rescue xyexception => ex
72
- logger ex, #error_msg
73
- prefix, #this is optionable! but i usualy use: "#{__FILE__}/#{__LINE__}"
74
- log_file #this is optionable!
98
+ exlogger ex, #error_msg
99
+ prefix, #this is optionable! but i usualy use: "#{__FILE__}/#{__LINE__}"
100
+ log_file #this is optionable!
75
101
  end
102
+
103
+ #or with less fuss
104
+
105
+
106
+ begin
107
+
108
+ rescue Exception => ex
109
+ ex.logger
110
+ end
111
+
112
+
113
+
76
114
 
77
115
 
78
116
  if you need methods from any kind of class without the object methods, you should try this!
117
+
118
+
79
119
  Xyclassname.class_methods
80
120
 
81
121
 
82
122
  you want make some test script with rnd numbers, strings, dates, bools etc? use the Rnd class at your command
83
- Rnd
84
- -string
85
- -number
86
- -boolean
87
- -date
123
+
124
+
125
+ Rnd
126
+ -string
127
+ -number
128
+ -boolean
129
+ -date
130
+
88
131
 
89
132
  examples:
133
+
134
+
90
135
  Rnd.number(100)
91
136
  Rnd.string(15,2) #for rnd bla bla names
137
+
92
138
 
93
139
 
94
140
  You need get the index of an Array element? you can use:
141
+
142
+
143
+
95
144
  array_variable.index_of("something)
96
145
 
97
146
 
98
147
  Do you wanted to know , does that process running on that pid or not?
148
+
149
+
150
+
99
151
  process_running?(nmbr)
100
152
 
101
153
 
@@ -103,14 +155,16 @@ Do you wanted to know , does that process running on that pid or not?
103
155
 
104
156
  in Short:
105
157
  ---------
158
+
106
159
  require 'daemon-ogre'
107
- DaemonOgre.start #arguments if you want :)
160
+ DaemonOgre.start
108
161
  your_Super_app_code!
109
162
 
110
163
 
111
164
 
112
165
 
113
- == Contributing to daemon-ogre
166
+ Contributing to daemon-ogre
167
+ ---------------------------
114
168
 
115
169
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
116
170
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -120,11 +174,12 @@ in Short:
120
174
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
121
175
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
122
176
 
123
- == Copyright
177
+ Copyright
178
+ ---------
124
179
 
180
+ Right to copy and use at your service fellow coder
125
181
  Copyright (c) 2013 adam.luzsi. See LICENSE.txt for
126
182
  further details.
127
183
 
128
184
 
129
-
130
- daemon-ogre
185
+ daemon-ogre
data/README.rdoc CHANGED
@@ -1,108 +1,171 @@
1
- = daemon-ogre
1
+ daemon-ogre
2
+ ===========
2
3
 
4
+ Installation
5
+ ------------
3
6
 
4
- gem install 'daemon-ogre'
7
+ ### [RubyGems](http://rubygems.org/)
8
+
9
+ $ gem install 'daemon-ogre'
5
10
 
6
11
 
7
12
  require 'daemon-ogre'
8
13
  DaemonOgre.start
9
14
 
10
15
 
11
- but we love config our beloved App!
12
- -======================================================================================================================-
13
- DaemonOgre.start :name => "MySuperAppName!", #this will be the name of the application
14
- :log_path => "./var/log/log_file_name", #this will be the logfile place and name
15
- :pid_path => "./var/pid/pid_file_name", #this will be the pidfile place and name
16
- :terminate => true #this command not let start your code if it's not started
17
- # with "start" arguments like :
18
- # ruby my_awsome_app.rb start
16
+ but we love config our beloved App!
17
+ -----------------------------------
18
+
19
+
20
+ DaemonOgre.start :name => "MySuperAppName!", #this will be the name of the application
21
+ :log_path => "./var/log/log_file_name", #this will be the logfile place and name
22
+ :pid_path => "./var/pid/pid_file_name", #this will be the pidfile place and name
23
+ :terminate => true #this command not let start your code if it's not started
24
+ # with "start" arguments like :
25
+ # ruby my_awsome_app.rb start
26
+
27
+ In use?
28
+ -------
29
+
30
+
31
+ you can simply use your terminal with arguments like
32
+ * start - for start the process if you choosed :terminate => true in code like above
33
+ start command will check does the application already running or not, so you dont have to worry about
34
+
35
+ * stop - will terminate the running application
36
+ * restart - will stop the process if that is already running than start again
37
+ * debug - this will show the fancy loadings if you want look busy by coding big stuffs :) (or debug your code)
38
+ * debugger - this will call the ruby debugger gem to aid you in trouble
39
+ you should use these commands:
40
+
41
+ set autolist on #show the code, and the position like and editor, in every step.
42
+ s #step in any kind of method, beware to use carefully because you end up in really deep somewhere in Alice world
43
+ n #step to next code/codeblock etc, without enter it (usefull when you find the right place)
44
+ l #list your current position
45
+ #simply hit enter to repeate the last one
46
+
47
+ * daemon or -d -this will fork a child process by the given parameters
48
+ * log or -l -you can set the log file position n by terminal for one time run
49
+ * pid or -p -you can set the pid file position n name by terminal for one time run
50
+ * status or -s -this will tell you ,does your process is running not
51
+ * help -this will invoke some help to the terminal if you out of luck and forget everything from this page
19
52
 
20
53
 
21
- -======================================================================================================================-
22
- othere stuffs to use:
23
- everybody love: require_relative...
24
- so why should not try require_directory instead all the fuss
25
- you can tell to it if you want some file to be excluded or just delayed loaded,
26
- because you want them loaded in the last place
27
- Example:
54
+ othere stuffs to use:
55
+ ---------------------
56
+ everybody love: require_relative...
57
+ so why should not try require_directory instead all the fuss
58
+ you can tell to it if you want some file to be excluded or just delayed loaded,
59
+ because you want them loaded in the last place
60
+ Example:
28
61
 
29
- require_directory "some_dir_name_from_here_where_are_multi_dir_levels"
30
62
 
31
- or
63
+ require_directory "some_dir_name_from_here_where_are_multi_dir_levels"
32
64
 
33
- require_directory "some_dir_name_from_here_where_are_multi_dir_levels",
34
- :delayed => ["files","to","be","delayed","in","load"],
35
- :exclude => ["files","to","be","exclude","in","load"]
65
+ or
36
66
 
67
+ require_directory "some_dir_name_from_here_where_are_multi_dir_levels",
68
+ :delayed => ["files","to","be","delayed","in","load"],
69
+ :exclude => ["files","to","be","exclude","in","load"]
70
+
71
+
72
+
73
+ Helpers
74
+ -------
37
75
 
38
- -======================================================================================================================-
39
76
  and ofc what else what we love if not our beloved yml-s
40
77
  we should use a nice Config constant for this(or at least i love to do)
41
78
 
42
- CONFIG = require_ymls "some_dir_name_from_here_where_are_the_yml_files_in_multi_dir_level"
43
- the file names will be the hash-key and under that , there will be the yml file datas loaded in
79
+ CONFIG = require_ymls "some_dir_name_from_here_where_are_the_yml_files_in_multi_dir_level"
80
+ the file names will be the hash-key and under that , there will be the yml file datas loaded in
44
81
 
45
- if you need get a free port in a range or from, you can use this:
46
- get_port(from_nmb,to_nmb,host)
82
+ if you need get a free port in a range or from, you can use this:
83
+ get_port(from_nmb,to_nmb,host)
47
84
 
48
- or by simply
85
+ or by simply
49
86
 
50
- get_port(number)
87
+ get_port(number)
51
88
 
52
89
 
53
- and if you hate find all the bugs... you can use error_logger at your command like this:
90
+ and if you hate find all the bugs... you can use error_logger at your command like this:
54
91
 
55
92
 
56
- begin
93
+ begin
57
94
 
58
- your awsome code!
95
+ your awsome code!
59
96
 
60
- rescue xyexception => ex
61
- logger ex, #error_msg
62
- prefix, #this is optionable! but i usualy use: "#{__FILE__}/#{__LINE__}"
63
- log_file #this is optionable!
64
- end
97
+ rescue xyexception => ex
98
+ exlogger ex, #error_msg
99
+ prefix, #this is optionable! but i usualy use: "#{__FILE__}/#{__LINE__}"
100
+ log_file #this is optionable!
101
+ end
102
+
103
+ #or with less fuss
104
+
105
+
106
+ begin
107
+
108
+ rescue Exception => ex
109
+ ex.logger
110
+ end
111
+
112
+
113
+
65
114
 
66
115
 
67
116
  if you need methods from any kind of class without the object methods, you should try this!
68
- Xyclassname.class_methods
117
+
118
+
119
+ Xyclassname.class_methods
69
120
 
70
121
 
71
122
  you want make some test script with rnd numbers, strings, dates, bools etc? use the Rnd class at your command
72
- Rnd
73
- -string
74
- -number
75
- -boolean
76
- -date
77
123
 
78
- example: Rnd.number(100)
79
- or Rnd.string(15,2) #for rnd bla bla names
124
+
125
+ Rnd
126
+ -string
127
+ -number
128
+ -boolean
129
+ -date
130
+
131
+
132
+ examples:
133
+
134
+
135
+ Rnd.number(100)
136
+ Rnd.string(15,2) #for rnd bla bla names
137
+
80
138
 
81
139
 
82
140
  You need get the index of an Array element? you can use:
83
- array_variable.index_of("something)
141
+
142
+
143
+
144
+ array_variable.index_of("something)
145
+
84
146
 
85
147
  Do you wanted to know , does that process running on that pid or not?
86
- process_running?(nmbr)
87
148
 
88
149
 
89
150
 
90
- -=========================================================-
151
+ process_running?(nmbr)
152
+
91
153
 
92
154
 
93
155
 
94
156
  in Short:
95
- require 'daemon-ogre'
96
- DaemonOgre.start
157
+ ---------
158
+
159
+ require 'daemon-ogre'
160
+ DaemonOgre.start
161
+ your_Super_app_code!
97
162
 
98
- for boot your files and ymls, helpers above :)
99
- your_Super_app_code!
100
163
 
101
164
 
102
165
 
166
+ Contributing to daemon-ogre
167
+ ---------------------------
103
168
 
104
- == Contributing to daemon-ogre
105
-
106
169
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
107
170
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
108
171
  * Fork the project.
@@ -111,8 +174,12 @@ your_Super_app_code!
111
174
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
112
175
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
113
176
 
114
- == Copyright
177
+ Copyright
178
+ ---------
115
179
 
180
+ Right to copy and use at your service fellow coder
116
181
  Copyright (c) 2013 adam.luzsi. See LICENSE.txt for
117
182
  further details.
118
183
 
184
+
185
+ daemon-ogre
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.homepage = "http://github.com/adamluzsi/daemon-ogre"
18
18
  gem.license = "MIT"
19
19
  gem.summary = %Q{Let the Ogre Do the hard work}
20
- gem.description = %Q{This gem is made for one purpose. Ruby meant to be for easy use, not hardcore coding! And in terms for this, ogre will aid you in the brute way, so you can relax... Are you need load a whole bunch of folders to your rack application ? do it! You want one nice hash for config constant from ymls all over your dirs? sure you can! you want have start/stop/status/restart/daemon/etc argument commands from terminal to control your application without any fuss? There you go! Are you need an easy way to do the classic way of daemonise your awsome app? there will be no problem at all, let the Ogre do the job :) so all you need is enjoy your code!}
20
+ gem.description = %Q{This gem is made for one purpose. Ruby meant to be for easy use, not hardcore coding! And in terms for this, ogre will aid you in the brute way, so you can relax... Are you need load a whole bunch of folders to your rack application ? do it! You want one nice hash for config constant from ymls all over your dirs? sure you can! you want have start/stop/status/restart/daemon/etc argument commands from terminal to control your application without any fuss? There you go! Are you need an easy way to do the classic way of daemonise your awsome app? there will be no problem at all, let the Ogre do the job :) so all you need is enjoy your code! Follow me on Github and send request if you have idea what can be usefull in creating your app :) https://github.com/adamluzsi/daemon-ogre.git}
21
21
  gem.email = "adamluzsi@gmail.com"
22
22
  gem.authors = ["Adam.Luzsi"]
23
23
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.5
data/daemon-ogre.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "daemon-ogre"
8
- s.version = "1.2.3"
8
+ s.version = "1.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam.Luzsi"]
12
12
  s.date = "2013-05-30"
13
- s.description = "This gem is made for one purpose. Ruby meant to be for easy use, not hardcore coding! And in terms for this, ogre will aid you in the brute way, so you can relax... Are you need load a whole bunch of folders to your rack application ? do it! You want one nice hash for config constant from ymls all over your dirs? sure you can! you want have start/stop/status/restart/daemon/etc argument commands from terminal to control your application without any fuss? There you go! Are you need an easy way to do the classic way of daemonise your awsome app? there will be no problem at all, let the Ogre do the job :) so all you need is enjoy your code!"
13
+ s.description = "This gem is made for one purpose. Ruby meant to be for easy use, not hardcore coding! And in terms for this, ogre will aid you in the brute way, so you can relax... Are you need load a whole bunch of folders to your rack application ? do it! You want one nice hash for config constant from ymls all over your dirs? sure you can! you want have start/stop/status/restart/daemon/etc argument commands from terminal to control your application without any fuss? There you go! Are you need an easy way to do the classic way of daemonise your awsome app? there will be no problem at all, let the Ogre do the job :) so all you need is enjoy your code! Follow me on Github and send request if you have idea what can be usefull in creating your app :) https://github.com/adamluzsi/daemon-ogre.git"
14
14
  s.email = "adamluzsi@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
data/lib/daemon-ogre.rb CHANGED
@@ -2,430 +2,430 @@
2
2
  begin
3
3
  module DaemonOgre
4
4
 
5
- #config
6
- begin
7
- class App
8
- class << self
9
- attr_accessor :log_path,
10
- :pid_path,
11
- :app_name,
12
- :port,
13
- :terminate,
14
- :debug
5
+ #config
6
+ begin
7
+ class App
8
+ class << self
9
+ attr_accessor :log_path,
10
+ :pid_path,
11
+ :app_name,
12
+ :port,
13
+ :terminate,
14
+ :debug
15
+ end
15
16
  end
16
17
  end
17
- end
18
18
 
19
- #default
20
- App.log_path = "./var/log/logfile.log"
21
- App.pid_path = "./var/pid/pidfile.pid"
22
- App.terminate = false
23
- App.port = 80
24
- App.app_name = $0
25
- App.debug = false
19
+ #default
20
+ App.log_path = "./var/log/logfile.log"
21
+ App.pid_path = "./var/pid/pidfile.pid"
22
+ App.terminate = false
23
+ App.port = 80
24
+ App.app_name = $0
25
+ App.debug = false
26
26
 
27
- #OgreClassMethods
28
- begin
29
- class << self
30
- #Based on the rb location
31
- def load_directory(directory,*args)
32
- arg = Hash[*args]
27
+ #OgreClassMethods
28
+ begin
29
+ class << self
30
+ #Based on the rb location
31
+ def load_directory(directory,*args)
32
+ arg = Hash[*args]
33
33
 
34
- if !arg[:delayed].nil?
35
- raise ArgumentError, "Delayed items must be in an "+\
36
- "Array! Example:\n:delayed => ['abc']" if arg[:delayed].class == Array
37
- end
34
+ if !arg[:delayed].nil?
35
+ raise ArgumentError, "Delayed items must be in an "+\
36
+ "Array! Example:\n:delayed => ['abc']" if arg[:delayed].class == Array
37
+ end
38
38
 
39
- if !arg[:exclude].nil?
40
- raise ArgumentError, "Exclude items must be in an "+\
41
- "Array! Example:\n:exclude => ['abc']" if arg[:exclude].class == Array
42
- end
39
+ if !arg[:exclude].nil?
40
+ raise ArgumentError, "Exclude items must be in an "+\
41
+ "Array! Example:\n:exclude => ['abc']" if arg[:exclude].class == Array
42
+ end
43
43
 
44
44
 
45
- #=================================================================================================================
45
+ #=================================================================================================================
46
46
 
47
- puts "LOADING_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if App.debug
47
+ puts "LOADING_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if App.debug
48
48
 
49
- delayed_loads = Array.new
50
- Dir["#{directory}/**/*.rb"].each do |file|
49
+ delayed_loads = Array.new
50
+ Dir["#{directory}/**/*.rb"].each do |file|
51
51
 
52
- arg[:delayed]= [nil] if arg[:delayed].nil?
53
- arg[:exclude]= [nil] if arg[:exclude].nil?
52
+ arg[:delayed]= [nil] if arg[:delayed].nil?
53
+ arg[:exclude]= [nil] if arg[:exclude].nil?
54
54
 
55
- arg[:exclude].each do |except|
56
- if file.split('/').last.split('.').first == except.to_s.split('.').first
57
- puts file.to_s + " cant be loaded because it's an exception"
58
- else
59
- arg[:delayed].each do |delay|
60
- if file.split('/').last.split('.').first == delay.to_s.split('.').first
61
- delayed_loads.push(file)
62
- else
63
- load(file)
64
- puts file.to_s
55
+ arg[:exclude].each do |except|
56
+ if file.split('/').last.split('.').first == except.to_s.split('.').first
57
+ puts file.to_s + " cant be loaded because it's an exception"
58
+ else
59
+ arg[:delayed].each do |delay|
60
+ if file.split('/').last.split('.').first == delay.to_s.split('.').first
61
+ delayed_loads.push(file)
62
+ else
63
+ load(file)
64
+ puts file.to_s
65
+ end
65
66
  end
66
67
  end
67
68
  end
68
69
  end
70
+ delayed_loads.each do |delayed_load_element|
71
+ load(delayed_load_element)
72
+ puts delayed_load_element.to_s if App.debug
73
+ end
74
+ puts "DONE_LOAD_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if App.debug
75
+
69
76
  end
70
- delayed_loads.each do |delayed_load_element|
71
- load(delayed_load_element)
72
- puts delayed_load_element.to_s if App.debug
73
- end
74
- puts "DONE_LOAD_FILES_FROM_"+directory.to_s.split('/').last.split('.').first.capitalize if App.debug
75
77
 
76
- end
78
+ def get_port(port,max_port=65535 ,host="0.0.0.0")
77
79
 
78
- def get_port(port,max_port=65535 ,host="0.0.0.0")
80
+ require 'socket'
81
+ port = port.to_i
79
82
 
80
- require 'socket'
81
- port = port.to_i
83
+ begin
84
+ server = TCPServer.new('0.0.0.0', port)
85
+ server.close
86
+ return port
87
+ rescue Errno::EADDRINUSE
88
+ port = port.to_i + 1 if port < max_port+1
89
+ retry
90
+ end
82
91
 
83
- begin
84
- server = TCPServer.new('0.0.0.0', port)
85
- server.close
86
- return port
87
- rescue Errno::EADDRINUSE
88
- port = port.to_i + 1 if port < max_port+1
89
- retry
90
92
  end
91
93
 
92
- end
94
+ def error_logger(error_msg,prefix="",log_file=App.log_path)
93
95
 
94
- def error_logger(error_msg,prefix="",log_file=App.log_path)
96
+ create_on_filesystem(log_file)
95
97
 
96
- create_on_filesystem(log_file)
98
+ if File.exists?(File.expand_path(log_file))
99
+ error_log = File.open( File.expand_path(log_file), "a+")
100
+ error_log << "\n#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
101
+ error_log.close
102
+ else
103
+ File.new(File.expand_path(log_file), "w").write(
104
+ "#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
105
+ )
106
+ end
97
107
 
98
- if File.exists?("./#{log_file}")
99
- error_log = File.open( ".#{log_file}", "a+")
100
- error_log << "\n#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
101
- error_log.close
102
- else
103
- File.new("./#{log_file}", "w").write(
104
- "#{Time.now} | #{prefix}#{":" if prefix != ""} #{error_msg}"
105
- )
108
+ return {:error => error_msg}
106
109
  end
107
110
 
108
- return {:error => error_msg}
109
- end
110
-
111
- def load_ymls(directory)
111
+ def load_ymls(directory)
112
112
 
113
- require 'yaml'
114
- #require "hashie"
113
+ require 'yaml'
114
+ #require "hashie"
115
115
 
116
- yaml_files = Dir["#{directory}/**/*.yml"].each { |f| puts f.to_s if App.debug }
117
- puts "\nyaml file found: "+yaml_files.inspect.to_s if App.debug
118
- @result_hash = {}
119
- yaml_files.each_with_index do |full_path_file_name|
116
+ yaml_files = Dir["#{directory}/**/*.yml"].each { |f| puts f.to_s if App.debug }
117
+ puts "\nyaml file found: "+yaml_files.inspect.to_s if App.debug
118
+ @result_hash = {}
119
+ yaml_files.each_with_index do |full_path_file_name|
120
120
 
121
121
 
122
- file_name = full_path_file_name.split('/').last.split('.').first
122
+ file_name = full_path_file_name.split('/').last.split('.').first
123
123
 
124
- hash_key = file_name
125
- @result_hash[hash_key] = YAML.load(File.read("#{full_path_file_name}"))
124
+ hash_key = file_name
125
+ @result_hash[hash_key] = YAML.load(File.read("#{full_path_file_name}"))
126
126
 
127
- #@result_hash = @result_hash.merge!(tmp_hash)
127
+ #@result_hash = @result_hash.merge!(tmp_hash)
128
128
 
129
129
 
130
- puts "==========================================================" if App.debug
131
- puts "Loading "+file_name.to_s.capitalize+"\n" if App.debug
132
- puts YAML.load(File.read("#{full_path_file_name}")) if App.debug
133
- puts "__________________________________________________________" if App.debug
130
+ puts "==========================================================" if App.debug
131
+ puts "Loading "+file_name.to_s.capitalize+"\n" if App.debug
132
+ puts YAML.load(File.read("#{full_path_file_name}")) if App.debug
133
+ puts "__________________________________________________________" if App.debug
134
134
 
135
- end
135
+ end
136
136
 
137
- puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" if App.debug
138
- puts "The Main Hash: \n"+@result_hash.inspect.to_s if App.debug
139
- puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" if App.debug
137
+ puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" if App.debug
138
+ puts "The Main Hash: \n"+@result_hash.inspect.to_s if App.debug
139
+ puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" if App.debug
140
140
 
141
- return @result_hash
142
- end
141
+ return @result_hash
142
+ end
143
143
 
144
- def create_on_filesystem(input,optionable_data=nil,optionable_file_mod="w")
145
- begin
144
+ def create_on_filesystem(input,optionable_data=nil,optionable_file_mod="w")
145
+ begin
146
146
 
147
- #file_name generate
148
- if !input.to_s.split('/').last.nil? || input.to_s.split('/').last != ''
149
- file_name = input.to_s.split('/').last
150
- else
151
- file_name = nil?
152
- end
147
+ #file_name generate
148
+ if !input.to_s.split('/').last.nil? || input.to_s.split('/').last != ''
149
+ file_name = input.to_s.split('/').last
150
+ else
151
+ file_name = nil?
152
+ end
153
153
 
154
- #path_way
155
- begin
156
- raise ArgumentError, "missing input: #{input}" if input.nil?
157
- path = File.expand_path(input).to_s.split('/')
158
- path = path - [File.expand_path(input).to_s.split('/').last]
159
- path.shift
160
- end
154
+ #path_way
155
+ begin
156
+ raise ArgumentError, "missing input: #{input}" if input.nil?
157
+ path = File.expand_path(input).to_s.split('/')
158
+ path = path - [File.expand_path(input).to_s.split('/').last]
159
+ path.shift
160
+ end
161
161
 
162
- #job
163
- begin
164
- if !Dir.exists?("/"+path.join("/"))
162
+ #job
163
+ begin
164
+ if !Dir.exists?("/"+path.join("/"))
165
165
 
166
- at_now = "/"
167
- path.each do |dir_to_be_checked|
166
+ at_now = "/"
167
+ path.each do |dir_to_be_checked|
168
168
 
169
- at_now += "#{dir_to_be_checked}/"
170
- Dir.mkdir(at_now) if !Dir.exists?(at_now)
169
+ at_now += "#{dir_to_be_checked}/"
170
+ Dir.mkdir(at_now) if !Dir.exists?(at_now)
171
171
 
172
+ end
172
173
  end
173
174
  end
174
- end
175
175
 
176
- #file_create
177
- File.new("/#{path.join("/")}/#{file_name}", optionable_file_mod ).write optionable_data
176
+ #file_create
177
+ File.new("/#{path.join("/")}/#{file_name}", optionable_file_mod ).write optionable_data
178
178
 
179
- rescue Exception => ex
180
- puts ex
179
+ rescue Exception => ex
180
+ puts ex
181
+ end
181
182
  end
182
- end
183
183
 
184
- def process_running?(input)
185
- begin
186
- Process.getpgid input.chomp.to_i
187
- return true
188
- rescue Exception
189
- return false
184
+ def process_running?(input)
185
+ begin
186
+ Process.getpgid input.chomp.to_i
187
+ return true
188
+ rescue Exception
189
+ return false
190
+ end
190
191
  end
191
- end
192
192
 
193
+ end
193
194
  end
194
- end
195
195
 
196
- #DaemonEngine
197
- begin
198
- class Daemon
199
- # Checks to see if the current process is the child process and if not
200
- # will update the pid file with the child pid.
201
- def self.start pid, pidfile, outfile, errfile
202
- unless pid.nil?
203
- raise "Fork failed" if pid == -1
204
- write pid, pidfile #if kill pidfile
205
- exit
206
- else
207
- redirect outfile, errfile
196
+ #DaemonEngine
197
+ begin
198
+ class Daemon
199
+ # Checks to see if the current process is the child process and if not
200
+ # will update the pid file with the child pid.
201
+ def self.start pid, pidfile, outfile, errfile
202
+ unless pid.nil?
203
+ raise "Fork failed" if pid == -1
204
+ write pid, pidfile #if kill pidfile
205
+ exit
206
+ else
207
+ redirect outfile, errfile
208
+ end
208
209
  end
209
- end
210
210
 
211
- # Attempts to write the pid of the forked process to the pid file.
212
- def self.write pid, pidfile
213
- DaemonOgre.create_on_filesystem pidfile
214
- File.open pidfile, "a+" do |new_line|
215
- new_line.write "#{pid}\n"
211
+ # Attempts to write the pid of the forked process to the pid file.
212
+ def self.write pid, pidfile
213
+ DaemonOgre.create_on_filesystem pidfile
214
+ File.open pidfile, "a+" do |new_line|
215
+ new_line.write "#{pid}\n"
216
+ end
217
+ rescue ::Exception => e
218
+ $stderr.puts "While writing the PID to file, unexpected #{e.class}: #{e}"
219
+ Process.kill "HUP", pid
216
220
  end
217
- rescue ::Exception => e
218
- $stderr.puts "While writing the PID to file, unexpected #{e.class}: #{e}"
219
- Process.kill "HUP", pid
220
- end
221
221
 
222
- # Try and read the existing pid from the pid file and signal the
223
- # process. Returns true for a non blocking status.
224
- def self.kill(pidfile)
225
- opid = open("./#{pidfile}").read.strip.to_i
226
- Process.kill 'HUP', opid.to_i
227
- true
228
- rescue Errno::ENOENT
229
- $stdout.puts "#{pidfile} did not exist: Errno::ENOENT" if App.debug
230
- true
231
- rescue Errno::ESRCH
232
- $stdout.puts "The process #{opid} did not exist: Errno::ESRCH" if App.debug
233
- true
234
- rescue Errno::EPERM
235
- $stderr.puts "Lack of privileges to manage the process #{opid}: Errno::EPERM" if App.debug
236
- false
237
- rescue ::Exception => e
238
- $stderr.puts "While signaling the PID, unexpected #{e.class}: #{e}" if App.debug
239
- false
240
- end
222
+ # Try and read the existing pid from the pid file and signal the
223
+ # process. Returns true for a non blocking status.
224
+ def self.kill(pidfile)
225
+ opid = open("./#{pidfile}").read.strip.to_i
226
+ Process.kill 'HUP', opid.to_i
227
+ true
228
+ rescue Errno::ENOENT
229
+ $stdout.puts "#{pidfile} did not exist: Errno::ENOENT" if App.debug
230
+ true
231
+ rescue Errno::ESRCH
232
+ $stdout.puts "The process #{opid} did not exist: Errno::ESRCH" if App.debug
233
+ true
234
+ rescue Errno::EPERM
235
+ $stderr.puts "Lack of privileges to manage the process #{opid}: Errno::EPERM" if App.debug
236
+ false
237
+ rescue ::Exception => e
238
+ $stderr.puts "While signaling the PID, unexpected #{e.class}: #{e}" if App.debug
239
+ false
240
+ end
241
241
 
242
- # Send stdout and stderr to log files for the child process
243
- def self.redirect outfile, errfile
244
- $stdin.reopen '/dev/null'
245
- out = File.new outfile, "a"
246
- err = File.new errfile, "a"
247
- $stdout.reopen out
248
- $stderr.reopen err
249
- $stdout.sync = $stderr.sync = true
242
+ # Send stdout and stderr to log files for the child process
243
+ def self.redirect outfile, errfile
244
+ $stdin.reopen '/dev/null'
245
+ out = File.new outfile, "a"
246
+ err = File.new errfile, "a"
247
+ $stdout.reopen out
248
+ $stderr.reopen err
249
+ $stdout.sync = $stderr.sync = true
250
+ end
250
251
  end
251
- end
252
-
253
- end
254
252
 
255
- #server_model
256
- begin
257
- class Server
258
- @@startup = false
259
- class << self
260
-
261
- def daemon
262
- puts "#{$0} daemon watching you..."
263
- DaemonOgre.create_on_filesystem DaemonOgre::App.pid_path
264
- DaemonOgre.create_on_filesystem DaemonOgre::App.log_path
265
- DaemonOgre.create_on_filesystem './var/daemon.stderr.log'
266
- Daemon.start fork,
267
- DaemonOgre::App.pid_path,
268
- DaemonOgre::App.log_path,
269
- ('./var/daemon.stderr.log')
270
- end
253
+ end
271
254
 
272
- def debug
273
- App.debug=true
274
- end
255
+ #server_model
256
+ begin
257
+ class Server
258
+ @@startup = false
259
+ class << self
260
+
261
+ def daemon
262
+ puts "#{$0} daemon watching you..."
263
+ DaemonOgre.create_on_filesystem DaemonOgre::App.pid_path
264
+ DaemonOgre.create_on_filesystem DaemonOgre::App.log_path
265
+ DaemonOgre.create_on_filesystem './var/daemon.stderr.log'
266
+ Daemon.start fork,
267
+ DaemonOgre::App.pid_path,
268
+ DaemonOgre::App.log_path,
269
+ ('./var/daemon.stderr.log')
270
+ end
275
271
 
276
- def help
277
- puts "\nyou can use one of these commands: "+\
278
- "\nstart daemon -d stop restart log -l pid -p port -tcp status reset help"+\
279
- "\n==============================================================================DESC======>>"
280
- puts "start\t\t\t\t=> this will start the #{$0}"+\
281
- "\ndaemon\t\tor -d\t\t=> this will make is daemon process"+\
282
- "\nstop\t\t\t\t=> this will kill the last process with pidfile"+\
283
- "\nrestart\t\tor reset\t=> hard restart"+\
284
- "\nlog\t\tor -l\t\t=> logfile place"+\
285
- "\npid\t\tor -p\t\t=> pid file place (if you want set the filename as well, put .pid or .txt in the end)"+\
286
- "\nport\t\tor -tcp\t\t=> user definiated port"+\
287
- "\nstatus\t\t\t\t=> last process alive?"+\
288
- "\nhelp\t\t\t\tgive you this msg :)\n"
289
- DaemonOgre::App.terminate=true
290
- end
272
+ def debug
273
+ App.debug=true
274
+ end
291
275
 
292
- def start
293
- if File.exist?(File.expand_path(App.pid_path))
294
- text = File.open(File.expand_path(App.pid_path)).read
295
- terminate_on_command = Array.new
296
- text.each_line do |line|
297
- terminate_on_command.push DaemonOgre.process_running?(line)
276
+ def help
277
+ puts "\nyou can use one of these commands: "+\
278
+ "\nstart daemon -d stop restart log -l pid -p port -tcp status reset help"+\
279
+ "\n==============================================================================DESC======>>"
280
+ puts "start\t\t\t\t=> this will start the #{$0}"+\
281
+ "\ndaemon\t\tor -d\t\t=> this will make is daemon process"+\
282
+ "\nstop\t\t\t\t=> this will kill the last process with pidfile"+\
283
+ "\nrestart\t\tor reset\t=> hard restart"+\
284
+ "\nlog\t\tor -l\t\t=> logfile place"+\
285
+ "\npid\t\tor -p\t\t=> pid file place (if you want set the filename as well, put .pid or .txt in the end)"+\
286
+ "\nport\t\tor -tcp\t\t=> user definiated port"+\
287
+ "\nstatus\t\t\t\t=> last process alive?"+\
288
+ "\nhelp\t\t\t\tgive you this msg :)\n"
289
+ DaemonOgre::App.terminate=true
298
290
  end
299
- end
300
291
 
301
- if !terminate_on_command.nil?
302
- if !terminate_on_command.include?(true)
303
- @@startup = true
304
- else
305
- puts "sorry but process is already running in this specification"
306
- Process.exit
292
+ def start
293
+ if File.exist?(File.expand_path(App.pid_path))
294
+ text = File.open(File.expand_path(App.pid_path)).read
295
+ terminate_on_command = Array.new
296
+ text.each_line do |line|
297
+ terminate_on_command.push DaemonOgre.process_running?(line)
298
+ end
299
+ end
300
+
301
+ if !terminate_on_command.nil?
302
+ if !terminate_on_command.include?(true)
303
+ @@startup = true
304
+ else
305
+ puts "sorry but process is already running in this specification"
306
+ Process.exit
307
+ end
308
+ else
309
+ @@startup = true
310
+ end
307
311
  end
308
- else
309
- @@startup = true
310
- end
311
- end
312
312
 
313
- def stop
314
- puts "#{$0} is going to be FacePalmed..."
315
- Daemon.kill DaemonOgre::App.pid_path
316
- kill_with_pid
317
- File.open(DaemonOgre::App.pid_path, "w").write("")
318
- DaemonOgre::App.terminate=true
313
+ def stop
314
+ puts "#{$0} is going to be FacePalmed..."
315
+ Daemon.kill DaemonOgre::App.pid_path
316
+ kill_with_pid
317
+ File.open(DaemonOgre::App.pid_path, "w").write("")
318
+ DaemonOgre::App.terminate=true
319
319
 
320
- end
320
+ end
321
321
 
322
- def restart
322
+ def restart
323
323
 
324
- Daemon.kill DaemonOgre::App.pid_path
325
- kill_with_pid
326
- File.open(DaemonOgre::App.pid_path, "w").write("")
327
- start
324
+ Daemon.kill DaemonOgre::App.pid_path
325
+ kill_with_pid
326
+ File.open(DaemonOgre::App.pid_path, "w").write("")
327
+ start
328
328
 
329
- end
329
+ end
330
330
 
331
- def kill_with_pid
332
- begin
333
- if File.exists?(DaemonOgre::App.pid_path)
334
- puts "PidFile found, processing..." if App.debug
335
- File.open(DaemonOgre::App.pid_path).each_line do |row|
336
- begin
337
- Process.kill 'TERM', row.to_i
338
- puts "terminated process at: #{row}" if App.debug
339
- rescue Exception => ex
340
- puts "At process: #{row}, #{ex}" if App.debug
331
+ def kill_with_pid
332
+ begin
333
+ if File.exists?(DaemonOgre::App.pid_path)
334
+ puts "PidFile found, processing..." if App.debug
335
+ File.open(DaemonOgre::App.pid_path).each_line do |row|
336
+ begin
337
+ Process.kill 'TERM', row.to_i
338
+ puts "terminated process at: #{row}" if App.debug
339
+ rescue Exception => ex
340
+ puts "At process: #{row}, #{ex}" if App.debug
341
+ end
342
+ end
343
+ else
344
+ system "ps -ef | grep #{$0}"
345
+ #system "netstat --listen"
346
+ #puts "\nLepton is around 10300-10399"
341
347
  end
348
+ rescue Exception => ex
349
+ puts "Exception has occured: #{ex}"
342
350
  end
343
- else
344
- system "ps -ef | grep #{$0}"
345
- #system "netstat --listen"
346
- #puts "\nLepton is around 10300-10399"
347
351
  end
348
- rescue Exception => ex
349
- puts "Exception has occured: #{ex}"
350
- end
351
- end
352
352
 
353
- def continue?
354
- Process.exit if !@@startup
355
- end
353
+ def continue?
354
+ Process.exit if !@@startup
355
+ end
356
356
 
357
- def set_log(param)
358
- ARGV.each do |one_parameter|
359
- if one_parameter == param
360
- DaemonOgre::App.log_path= ARGV[ARGV.index(one_parameter)+1]
357
+ def set_log(param)
358
+ ARGV.each do |one_parameter|
359
+ if one_parameter == param
360
+ DaemonOgre::App.log_path= ARGV[ARGV.index(one_parameter)+1]
361
+ end
362
+ end
361
363
  end
362
- end
363
- end
364
364
 
365
- def set_pid(param)
366
- ARGV.each do |one_parameter|
367
- if one_parameter == param
368
- if ARGV[ARGV.index(one_parameter)+1].to_s.include?(".pid") ||\
369
- ARGV[ARGV.index(one_parameter)+1].to_s.include?(".txt")
370
- DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1]
371
- else
372
- DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1].to_s+"lepton.pid"
365
+ def set_pid(param)
366
+ ARGV.each do |one_parameter|
367
+ if one_parameter == param
368
+ if ARGV[ARGV.index(one_parameter)+1].to_s.include?(".pid") ||\
369
+ ARGV[ARGV.index(one_parameter)+1].to_s.include?(".txt")
370
+ DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1]
371
+ else
372
+ DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1].to_s+"lepton.pid"
373
+ end
374
+ end
373
375
  end
374
376
  end
375
- end
376
- end
377
377
 
378
- def set_port(param)
379
- ARGV.each do |one_parameter|
380
- if one_parameter == param
381
- DaemonOgre::App.port= ARGV[ARGV.index(one_parameter)+1]
378
+ def set_port(param)
379
+ ARGV.each do |one_parameter|
380
+ if one_parameter == param
381
+ DaemonOgre::App.port= ARGV[ARGV.index(one_parameter)+1]
382
+ end
383
+ end
382
384
  end
383
- end
384
- end
385
385
 
386
- def pid
387
- begin
388
- if !DaemonOgre::App.pid_path.nil?
389
- DaemonOgre::App.pid_path+="lepton.pid" if !DaemonOgre::App.pid_path.include?(".pid")
390
- pre_path = File.dirname "#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}"
391
- pre_path_array = pre_path.split('/') - [ pre_path[0].to_s ]
392
- if !Dir.exists?(pre_path)
393
- at_now = String.new
394
- pre_path_array.each do |one_dir_to_be_made|
395
- #at_now show the place where we are now
396
- at_now == "" ? at_now += one_dir_to_be_made : at_now += "/"+one_dir_to_be_made
397
- if !Dir.exists?("#{File.dirname(__FILE__)}/#{at_now}")
398
- Dir.mkdir("#{File.dirname(__FILE__)}/#{at_now}")
386
+ def pid
387
+ begin
388
+ if !DaemonOgre::App.pid_path.nil?
389
+ DaemonOgre::App.pid_path+="lepton.pid" if !DaemonOgre::App.pid_path.include?(".pid")
390
+ pre_path = File.dirname "#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}"
391
+ pre_path_array = pre_path.split('/') - [ pre_path[0].to_s ]
392
+ if !Dir.exists?(pre_path)
393
+ at_now = String.new
394
+ pre_path_array.each do |one_dir_to_be_made|
395
+ #at_now show the place where we are now
396
+ at_now == "" ? at_now += one_dir_to_be_made : at_now += "/"+one_dir_to_be_made
397
+ if !Dir.exists?("#{File.dirname(__FILE__)}/#{at_now}")
398
+ Dir.mkdir("#{File.dirname(__FILE__)}/#{at_now}")
399
+ end
400
+ end
399
401
  end
402
+ File.new("#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}", "a+").write Process.pid.to_s+"\n"
400
403
  end
404
+ rescue Exception => ex
405
+ error_logger(ex)
401
406
  end
402
- File.new("#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}", "a+").write Process.pid.to_s+"\n"
403
407
  end
404
- rescue Exception => ex
405
- error_logger(ex)
406
- end
407
- end
408
408
 
409
- def pid_check
410
- if File.exist?(File.expand_path(App.pid_path))
411
- puts "checking pidfile:"
412
- text = File.open(File.expand_path(App.pid_path)).read
413
- text.each_line do |line|
414
- puts "#{line.chomp}:\t#{DaemonOgre.process_running?(line)}"
409
+ def pid_check
410
+ if File.exist?(File.expand_path(App.pid_path))
411
+ puts "checking pidfile:"
412
+ text = File.open(File.expand_path(App.pid_path)).read
413
+ text.each_line do |line|
414
+ puts "#{line.chomp}:\t#{DaemonOgre.process_running?(line)}"
415
+ end
416
+ else
417
+ puts "missing pid file (with default path) "+\
418
+ "\nif you specificated one manualy pls type"+\
419
+ " the path first in with '-p xy/xzt.pid'"
420
+ end
421
+ DaemonOgre::App.terminate=true
415
422
  end
416
- else
417
- puts "missing pid file (with default path) "+\
418
- "\nif you specificated one manualy pls type"+\
419
- " the path first in with '-p xy/xzt.pid'"
423
+
420
424
  end
421
- DaemonOgre::App.terminate=true
422
425
  end
423
-
424
426
  end
425
- end
426
- end
427
427
 
428
- end
428
+ end
429
429
  end
430
430
 
431
431
  #monkey patch
@@ -442,9 +442,20 @@ begin
442
442
  def get_port(port,max_port=65535 ,host="0.0.0.0")
443
443
  DaemonOgre.get_port(port,max_port,host)
444
444
  end
445
- def logger(error_msg,prefix="",log_file=DaemonOgre::App.log_path)
445
+ def exlogger(error_msg,prefix="",log_file=DaemonOgre::App.log_path)
446
446
  DaemonOgre.error_logger(error_msg,prefix,log_file)
447
447
  end
448
+ class Exception
449
+ def logger
450
+ path = File.expand_path(DaemonOgre::App.log_path)
451
+ path = path.split('/')
452
+ path.pop
453
+ path.push("exceptions.log")
454
+ path = path.join("/")
455
+ DaemonOgre.create_on_filesystem(path)
456
+ DaemonOgre.error_logger(self.backtrace,self,path)
457
+ end
458
+ end
448
459
  class File
449
460
  def self.create!(input,optionable_data=nil,optionable_file_mod="w")
450
461
  DaemonOgre.create_on_filesystem(input,optionable_data,optionable_file_mod)
@@ -577,4 +588,4 @@ begin
577
588
  " continue? 'ruby xy.rb start'\narg[:name]\tapplication names as daemon process"
578
589
  end
579
590
  end
580
- end
591
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemon-ogre
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -67,6 +67,8 @@ description: This gem is made for one purpose. Ruby meant to be for easy use, no
67
67
  from terminal to control your application without any fuss? There you go! Are you
68
68
  need an easy way to do the classic way of daemonise your awsome app? there will
69
69
  be no problem at all, let the Ogre do the job :) so all you need is enjoy your code!
70
+ Follow me on Github and send request if you have idea what can be usefull in creating
71
+ your app :) https://github.com/adamluzsi/daemon-ogre.git
70
72
  email: adamluzsi@gmail.com
71
73
  executables: []
72
74
  extensions: []