daemon-ogre 1.4.9 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +1 -8
- data/README.md +7 -8
- data/Rakefile +1 -52
- data/VERSION +1 -1
- data/daemon-ogre.gemspec +21 -55
- data/example/sample_daemon_app.rb +19 -0
- data/files.rb +24 -0
- data/lib/daemon-ogre/app.rb +40 -0
- data/lib/daemon-ogre/daemon.rb +65 -0
- data/lib/daemon-ogre/mpatch.rb +93 -0
- data/lib/daemon-ogre/server.rb +199 -0
- data/lib/daemon-ogre/startup.rb +85 -0
- data/lib/daemon-ogre/support.rb +246 -0
- data/lib/daemon-ogre.rb +6 -711
- data/test/test_daemon-ogre.rb +0 -7
- metadata +20 -80
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/daemon-ogre.iml +0 -18
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -24
- data/.idea/modules.xml +0 -9
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -434
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTliYTU5NmU3YjJjYTI0YzAwYzdjODhiYWZhMzdlMzk5ZmQ5ZGFkOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGY0M2QzZWZmNjczMTEwOTE5MmRkOWIzMDRmMzFjYWJjYTIzZThjNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmE5OGZjMGQxOTIwYzA1MDZiYWU0ZjExNzdmYzJlOWE0NTEyMjUzOTAxOTEy
|
10
|
+
OWMwZGZlYjdkN2NhMTBlMzYxYzhhNTIwYzllZjViMDhjMjgwMGZiMWFjNGJh
|
11
|
+
Nzg0NmMyMTQ3MzM3NjYwMzk5YzgxOWQ2NTJmNDg4NGIzZGU3OWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODVkOTNjOTIxNGMzNjEzYjlmNDhjOGE2ZmUyYzAwODhiZDIwZGE3ZjI1MGE5
|
14
|
+
MmZmMTVmZGQ0ZTkzNWFmYmIwNjdkYzIxMDE3YzZjNTFmNzRlZTQxNmIyN2U5
|
15
|
+
OWQ0ZjM4OTM1YmIzZDcxNTZmYTEzOThhN2JlYTgxNGJhYjkyNTg=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,19 +4,18 @@ daemon-ogre
|
|
4
4
|
Description
|
5
5
|
-----------
|
6
6
|
|
7
|
+
WARNING!
|
8
|
+
The gem will be not updated in the future but redirected to my other project:
|
9
|
+
Procemon
|
10
|
+
https://github.com/adamluzsi/procemon
|
11
|
+
All the functions are implemented and upgraded in all meaning there what you liked in daemon-ogre
|
12
|
+
|
13
|
+
|
7
14
|
This gem is made for one purpose.
|
8
15
|
|
9
16
|
Ruby meant to be for easy use, not hardcore coding!
|
10
17
|
And in terms for this, ogre will aid you in the brute way, so you can relax...
|
11
18
|
|
12
|
-
Are you need load a whole bunch of folders to your rack application ?
|
13
|
-
Do it! You want one nice hash for config constant
|
14
|
-
from ymls all over your dirs? sure you can! you want have
|
15
|
-
start/stop/status/restart/daemon/etc argument commands from
|
16
|
-
terminal to control your application without any fuss?
|
17
|
-
There you go! Are you need an easy way,
|
18
|
-
to do the classic way of daemonise your awsome app?
|
19
|
-
There will be no problem at all, let the Ogre do the job!
|
20
19
|
|
21
20
|
so all you need is enjoy your code!
|
22
21
|
Follow me on Github and send request,
|
data/Rakefile
CHANGED
@@ -1,52 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
gem.name = "daemon-ogre"
|
17
|
-
gem.homepage = "http://github.com/adamluzsi/daemon-ogre"
|
18
|
-
gem.license = "MIT"
|
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! 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
|
-
gem.email = "adamluzsi@gmail.com"
|
22
|
-
gem.authors = ["Adam.Luzsi"]
|
23
|
-
# dependencies defined in Gemfile
|
24
|
-
end
|
25
|
-
Jeweler::RubygemsDotOrgTasks.new
|
26
|
-
|
27
|
-
require 'rake/testtask'
|
28
|
-
Rake::TestTask.new(:test) do |test|
|
29
|
-
test.libs << 'lib' << 'test'
|
30
|
-
test.pattern = 'test/**/test_*.rb'
|
31
|
-
test.verbose = true
|
32
|
-
end
|
33
|
-
|
34
|
-
#require 'rcov/rcovtask'
|
35
|
-
#Rcov::RcovTask.new do |test|
|
36
|
-
# test.libs << 'test'
|
37
|
-
# test.pattern = 'test/**/test_*.rb'
|
38
|
-
# test.verbose = true
|
39
|
-
# test.rcov_opts << '--exclude "gems/*"'
|
40
|
-
#end
|
41
|
-
|
42
|
-
task :default => :test
|
43
|
-
|
44
|
-
require 'rdoc/task'
|
45
|
-
Rake::RDocTask.new do |rdoc|
|
46
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
-
|
48
|
-
rdoc.rdoc_dir = 'rdoc'
|
49
|
-
rdoc.title = "daemon-ogre #{version}"
|
50
|
-
rdoc.rdoc_files.include('README*')
|
51
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
-
end
|
1
|
+
require File.join "bundler","gem_tasks"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/daemon-ogre.gemspec
CHANGED
@@ -1,66 +1,32 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
|
7
|
-
s.name = "daemon-ogre"
|
8
|
-
s.version = "1.3.1"
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
|
7
|
+
spec.name = "daemon-ogre"
|
8
|
+
|
9
|
+
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
10
|
+
|
11
|
+
spec.authors = ["Adam.Luzsi"]
|
12
|
+
spec.email = "adamluzsi@gmail.com"
|
13
|
+
|
14
|
+
spec.description = "Simple to use app ARGV based daemonizer"
|
15
|
+
spec.summary = %q{DSL for helping make file loads and configuration objects }
|
16
|
+
|
17
|
+
spec.extra_rdoc_files = [
|
16
18
|
"LICENSE.txt",
|
17
19
|
"README.md",
|
18
20
|
"README.rdoc"
|
19
21
|
]
|
20
|
-
s.files = [
|
21
|
-
".idea/.name",
|
22
|
-
".idea/.rakeTasks",
|
23
|
-
".idea/daemon-ogre.iml",
|
24
|
-
".idea/encodings.xml",
|
25
|
-
".idea/misc.xml",
|
26
|
-
".idea/modules.xml",
|
27
|
-
".idea/scopes/scope_settings.xml",
|
28
|
-
".idea/vcs.xml",
|
29
|
-
".idea/workspace.xml",
|
30
|
-
"Gemfile",
|
31
|
-
"Gemfile.lock",
|
32
|
-
"LICENSE.txt",
|
33
|
-
"README.md",
|
34
|
-
"README.rdoc",
|
35
|
-
"Rakefile",
|
36
|
-
"VERSION",
|
37
|
-
"daemon-ogre.gemspec",
|
38
|
-
"lib/daemon-ogre.rb",
|
39
|
-
"test/helper.rb",
|
40
|
-
"test/test_daemon-ogre.rb"
|
41
|
-
]
|
42
|
-
s.homepage = "http://github.com/adamluzsi/daemon-ogre"
|
43
|
-
s.licenses = ["MIT"]
|
44
|
-
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = "1.8.25"
|
46
|
-
s.summary = "Let the Ogre Do the hard work"
|
47
22
|
|
48
|
-
|
49
|
-
|
23
|
+
spec.files = SpecFiles
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.homepage = "http://github.com/adamluzsi/daemon-ogre"
|
29
|
+
spec.licenses = ["MIT"]
|
50
30
|
|
51
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<debugger>, [">= 0"])
|
54
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
57
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
58
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
-
end
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<rdoc>, [">= 0"])
|
62
|
-
s.add_dependency(%q<debugger>, [">= 0"])
|
63
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
-
end
|
65
31
|
end
|
66
32
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative File.join '..','lib','daemon-ogre.rb'
|
2
|
+
|
3
|
+
# start as
|
4
|
+
# ruby sample_daemon_app.rb start daemon
|
5
|
+
#
|
6
|
+
# to check it's running
|
7
|
+
# ps aux | grep MySuperAppName
|
8
|
+
|
9
|
+
DaemonOgre.start :name => "MySuperAppName",
|
10
|
+
:log_path => File.join('.','var','log','log_file_name'),
|
11
|
+
:pid_path => File.join('.','var','pid','pid_file_name'),
|
12
|
+
:terminate => true
|
13
|
+
|
14
|
+
10.times do
|
15
|
+
|
16
|
+
puts Time.now
|
17
|
+
sleep 1
|
18
|
+
|
19
|
+
end
|
data/files.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Get Files from dir
|
2
|
+
begin
|
3
|
+
|
4
|
+
files_to_be_loaded = %w[version.rb]
|
5
|
+
|
6
|
+
SpecFiles= Array.new
|
7
|
+
|
8
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
+
one_file_name = File.expand_path one_file_name
|
10
|
+
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
+
|
12
|
+
if !one_file_name.include?("pkg")
|
13
|
+
if !File.directory? file_name
|
14
|
+
SpecFiles.push file_name
|
15
|
+
STDOUT.puts file_name if $DEBUG
|
16
|
+
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
+
load one_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#DaemonOgreBody
|
2
|
+
begin
|
3
|
+
module DaemonOgre
|
4
|
+
|
5
|
+
#config
|
6
|
+
begin
|
7
|
+
class App
|
8
|
+
class << self
|
9
|
+
attr_accessor :log_path,
|
10
|
+
:pid_path,
|
11
|
+
:daemon_stderr,
|
12
|
+
:exceptions,
|
13
|
+
:exlogger,
|
14
|
+
:app_name,
|
15
|
+
:port,
|
16
|
+
:terminate
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#default
|
22
|
+
begin
|
23
|
+
App.log_path = "./var/log/logfile.log"
|
24
|
+
App.pid_path = "./var/pid/pidfile.pid"
|
25
|
+
App.terminate = false
|
26
|
+
App.port = 80
|
27
|
+
App.app_name = $0
|
28
|
+
|
29
|
+
begin
|
30
|
+
['daemon_stderr','exceptions','exlogger'].each do |one_log|
|
31
|
+
|
32
|
+
App.__send__(one_log+"=",clone_mpath(App.log_path,one_log+".log"))
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#DaemonOgreBody
|
2
|
+
begin
|
3
|
+
module DaemonOgre
|
4
|
+
|
5
|
+
#DaemonEngine
|
6
|
+
begin
|
7
|
+
class Daemon
|
8
|
+
# Checks to see if the current process is the child process and if not
|
9
|
+
# will update the pid file with the child pid.
|
10
|
+
def self.start pid, pidfile, outfile, errfile
|
11
|
+
unless pid.nil?
|
12
|
+
raise "Fork failed" if pid == -1
|
13
|
+
write pid, pidfile #for kill we need a pidfile
|
14
|
+
exit
|
15
|
+
else
|
16
|
+
redirect outfile, errfile
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Attempts to write the pid of the forked process to the pid file.
|
21
|
+
def self.write pid, pidfile
|
22
|
+
DaemonOgre.create_on_filesystem pidfile
|
23
|
+
File.open pidfile, "a+" do |new_line|
|
24
|
+
new_line.write "#{pid}\n"
|
25
|
+
end
|
26
|
+
rescue ::Exception => e
|
27
|
+
$stderr.puts "While writing the PID to file, unexpected #{e.class}: #{e}"
|
28
|
+
Process.kill "HUP", pid
|
29
|
+
end
|
30
|
+
|
31
|
+
# Try and read the existing pid from the pid file and signal the
|
32
|
+
# process. Returns true for a non blocking status.
|
33
|
+
def self.kill(pidfile)
|
34
|
+
opid = open("./#{pidfile}").read.strip.to_i
|
35
|
+
Process.kill 'HUP', opid.to_i
|
36
|
+
true
|
37
|
+
rescue Errno::ENOENT
|
38
|
+
$stdout.puts "#{pidfile} did not exist: Errno::ENOENT" if $DEBUG
|
39
|
+
true
|
40
|
+
rescue Errno::ESRCH
|
41
|
+
$stdout.puts "The process #{opid} did not exist: Errno::ESRCH" if $DEBUG
|
42
|
+
true
|
43
|
+
rescue Errno::EPERM
|
44
|
+
$stderr.puts "Lack of privileges to manage the process #{opid}: Errno::EPERM" if $DEBUG
|
45
|
+
false
|
46
|
+
rescue ::Exception => e
|
47
|
+
$stderr.puts "While signaling the PID, unexpected #{e.class}: #{e}" if $DEBUG
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
# Send stdout and stderr to log files for the child process
|
52
|
+
def self.redirect outfile, errfile
|
53
|
+
$stdin.reopen '/dev/null'
|
54
|
+
out = File.new outfile, "a"
|
55
|
+
err = File.new errfile, "a"
|
56
|
+
$stdout.reopen out
|
57
|
+
$stderr.reopen err
|
58
|
+
$stdout.sync = $stderr.sync = true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#monkey patch
|
2
|
+
begin
|
3
|
+
def process_running?(input)
|
4
|
+
DaemonOgre.process_running?(input)
|
5
|
+
end
|
6
|
+
def require_directory(directory,*args)
|
7
|
+
DaemonOgre.load_directory(directory,{:monkey_patch => 1},*args)
|
8
|
+
end
|
9
|
+
def require_ymls(directory)
|
10
|
+
DaemonOgre.load_ymls(
|
11
|
+
directory,
|
12
|
+
{:monkey_patch => 1}
|
13
|
+
)
|
14
|
+
end
|
15
|
+
def get_port(port,max_port=65535 ,host="0.0.0.0")
|
16
|
+
DaemonOgre.get_port(port,max_port,host)
|
17
|
+
end
|
18
|
+
def exlogger(error_msg,*args)
|
19
|
+
arg=Hash[*args]
|
20
|
+
arg[:prefix] = String.new if arg[:prefix].nil?
|
21
|
+
arg[:path] = DaemonOgre::App.exlogger if arg[:path].nil?
|
22
|
+
DaemonOgre.create_on_filesystem arg[:path],
|
23
|
+
'a+'
|
24
|
+
DaemonOgre.error_logger(error_msg,arg[:prefix],arg[:path])
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class Exception
|
29
|
+
def logger
|
30
|
+
DaemonOgre.create_on_filesystem DaemonOgre::App.exceptions,
|
31
|
+
'a+'
|
32
|
+
DaemonOgre.error_logger(self.backtrace,self,DaemonOgre::App.exceptions)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
class File
|
36
|
+
def self.create!(file,optionable_data=nil,optionable_file_mod="w")
|
37
|
+
DaemonOgre.create_on_filesystem file,
|
38
|
+
optionable_file_mod,
|
39
|
+
optionable_data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
class Class
|
43
|
+
def class_methods
|
44
|
+
self.methods - Object.methods
|
45
|
+
end
|
46
|
+
def self.class_methods
|
47
|
+
self.methods - Object.methods
|
48
|
+
end
|
49
|
+
end
|
50
|
+
class Rnd
|
51
|
+
class << self
|
52
|
+
def string(length,amount=1)
|
53
|
+
mrg = String.new
|
54
|
+
first_string = true
|
55
|
+
amount.times do
|
56
|
+
a_string = Random.rand(length)
|
57
|
+
a_string == 0 ? a_string += 1 : a_string
|
58
|
+
mrg_prt = (0...a_string).map{ ('a'..'z').to_a[rand(26)] }.join
|
59
|
+
first_string ? mrg += mrg_prt : mrg+= " #{mrg_prt}"
|
60
|
+
first_string = false
|
61
|
+
end
|
62
|
+
return mrg
|
63
|
+
end
|
64
|
+
def integer(length)
|
65
|
+
Random.rand(length)
|
66
|
+
end
|
67
|
+
def boolean
|
68
|
+
rand(2) == 1
|
69
|
+
end
|
70
|
+
def date from = Time.at(1114924812), to = Time.now
|
71
|
+
rand(from..to)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
class Array
|
76
|
+
def index_of(target_element)
|
77
|
+
array = self
|
78
|
+
hash = Hash[array.map.with_index.to_a]
|
79
|
+
return hash[target_element]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
class Hash
|
83
|
+
#pass single or array of keys, which will be removed, returning the remaining hash
|
84
|
+
def remove!(*keys)
|
85
|
+
keys.each{|key| self.delete(key) }
|
86
|
+
self
|
87
|
+
end
|
88
|
+
#non-destructive version
|
89
|
+
def remove(*keys)
|
90
|
+
self.dup.remove!(*keys)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#DaemonOgreBody
|
2
|
+
begin
|
3
|
+
module DaemonOgre
|
4
|
+
|
5
|
+
#server_model
|
6
|
+
begin
|
7
|
+
class Server
|
8
|
+
@@startup = false
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def daemon
|
12
|
+
puts "#{$0} daemon is watching you..."
|
13
|
+
DaemonOgre.create_on_filesystem DaemonOgre::App.pid_path,
|
14
|
+
'a+'
|
15
|
+
DaemonOgre.create_on_filesystem DaemonOgre::App.log_path,
|
16
|
+
'a+'
|
17
|
+
DaemonOgre.create_on_filesystem DaemonOgre::App.daemon_stderr,
|
18
|
+
'a+'
|
19
|
+
|
20
|
+
|
21
|
+
DaemonOgre::Daemon.start fork,
|
22
|
+
DaemonOgre::App.pid_path,
|
23
|
+
DaemonOgre::App.log_path,
|
24
|
+
DaemonOgre::App.daemon_stderr
|
25
|
+
end
|
26
|
+
|
27
|
+
def debug
|
28
|
+
$DEBUG = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def help
|
32
|
+
puts "\nyou can use one of these commands: "+\
|
33
|
+
"\nstart daemon -d stop restart log -l pid -p port -tcp status reset help"+\
|
34
|
+
"\n==============================================================================DESC======>>"
|
35
|
+
puts "start\t\t\t\t=> this will start the #{$0}"+\
|
36
|
+
"\ndaemon\t\t\t\t=> this will make is daemon process"+\
|
37
|
+
"\nstop\t\t\t\t=> this will kill the last process with pidfile"+\
|
38
|
+
"\nrestart\t\tor reset\t=> hard restart"+\
|
39
|
+
"\nlog\t\tor -l\t\t=> logfile place"+\
|
40
|
+
"\npid\t\tor -p\t\t=> pid file place (if you want set the filename as well, put .pid or .txt in the end)"+\
|
41
|
+
"\nport\t\tor -tcp\t\t=> user definiated port"+\
|
42
|
+
"\nstatus\t\t\t\t=> last process alive?"+\
|
43
|
+
"\ndebug\t\tor -d\t\t=> show debug log (you can make your own by using 'puts 'xy' if $DEBUG' "+\
|
44
|
+
"\nhelp\t\t\t\tgive you this msg :)\n"
|
45
|
+
DaemonOgre::App.terminate=true
|
46
|
+
end
|
47
|
+
|
48
|
+
def start
|
49
|
+
if File.exist?(File.expand_path(App.pid_path))
|
50
|
+
text = File.open(File.expand_path(App.pid_path)).read
|
51
|
+
terminate_on_command = Array.new
|
52
|
+
text.each_line do |line|
|
53
|
+
terminate_on_command.push DaemonOgre.process_running?(line)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if !terminate_on_command.nil?
|
58
|
+
if !terminate_on_command.include?(true)
|
59
|
+
@@startup = true
|
60
|
+
else
|
61
|
+
puts "sorry but process is already running in this specification"
|
62
|
+
Process.exit
|
63
|
+
end
|
64
|
+
else
|
65
|
+
@@startup = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def stop
|
70
|
+
puts "#{$0} is going to be FacePalmed..."
|
71
|
+
Daemon.kill DaemonOgre::App.pid_path
|
72
|
+
kill_with_pid
|
73
|
+
File.open(DaemonOgre::App.pid_path, "w").write("")
|
74
|
+
DaemonOgre::App.terminate=true
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def restart
|
79
|
+
|
80
|
+
Daemon.kill DaemonOgre::App.pid_path
|
81
|
+
kill_with_pid
|
82
|
+
File.open(DaemonOgre::App.pid_path, "w").write("")
|
83
|
+
start
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def kill_with_pid
|
88
|
+
begin
|
89
|
+
if File.exists?(DaemonOgre::App.pid_path)
|
90
|
+
puts "PidFile found, processing..." if $DEBUG
|
91
|
+
File.open(DaemonOgre::App.pid_path).each_line do |row|
|
92
|
+
begin
|
93
|
+
Process.kill 'TERM', row.to_i
|
94
|
+
puts "terminated process at: #{row}" if $DEBUG
|
95
|
+
rescue Exception => ex
|
96
|
+
puts "At process: #{row}, #{ex}" if $DEBUG
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
system "ps -ef | grep #{$0}"
|
101
|
+
#system "netstat --listen"
|
102
|
+
#puts "\nLepton is around 10300-10399"
|
103
|
+
end
|
104
|
+
rescue Exception => ex
|
105
|
+
puts "Exception has occured: #{ex}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def continue?
|
110
|
+
Process.exit if !@@startup
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_log(param)
|
114
|
+
ARGV.each do |one_parameter|
|
115
|
+
if one_parameter == param
|
116
|
+
DaemonOgre::App.log_path= ARGV[ARGV.index(one_parameter)+1]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def set_pid(param)
|
122
|
+
ARGV.each do |one_parameter|
|
123
|
+
if one_parameter == param
|
124
|
+
if ARGV[ARGV.index(one_parameter)+1].to_s.include?(".pid") ||\
|
125
|
+
ARGV[ARGV.index(one_parameter)+1].to_s.include?(".txt")
|
126
|
+
DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1]
|
127
|
+
else
|
128
|
+
DaemonOgre::App.pid_path= ARGV[ARGV.index(one_parameter)+1].to_s+"lepton.pid"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def set_port(param)
|
135
|
+
ARGV.each do |one_parameter|
|
136
|
+
if one_parameter == param
|
137
|
+
DaemonOgre::App.port= ARGV[ARGV.index(one_parameter)+1]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def pid
|
143
|
+
begin
|
144
|
+
if !DaemonOgre::App.pid_path.nil?
|
145
|
+
DaemonOgre::App.pid_path+="lepton.pid" if !DaemonOgre::App.pid_path.include?(".pid")
|
146
|
+
pre_path = File.dirname "#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}"
|
147
|
+
pre_path_array = pre_path.split('/') - [ pre_path[0].to_s ]
|
148
|
+
if !Dir.exists?(pre_path)
|
149
|
+
at_now = String.new
|
150
|
+
pre_path_array.each do |one_dir_to_be_made|
|
151
|
+
#at_now show the place where we are now
|
152
|
+
at_now == "" ? at_now += one_dir_to_be_made : at_now += "/"+one_dir_to_be_made
|
153
|
+
if !Dir.exists?("#{File.dirname(__FILE__)}/#{at_now}")
|
154
|
+
Dir.mkdir("#{File.dirname(__FILE__)}/#{at_now}")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
File.new("#{File.dirname(__FILE__)}/#{DaemonOgre::App.pid_path}", "a+").write Process.pid.to_s+"\n"
|
159
|
+
end
|
160
|
+
rescue Exception => ex
|
161
|
+
ex.logger
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def pid_check
|
166
|
+
if File.exist?(File.expand_path(App.pid_path))
|
167
|
+
puts "checking pidfile:"
|
168
|
+
text = File.open(File.expand_path(App.pid_path)).read
|
169
|
+
text.each_line do |line|
|
170
|
+
puts "#{line.chomp}:\t#{DaemonOgre.process_running?(line)}"
|
171
|
+
end
|
172
|
+
else
|
173
|
+
puts "missing pid file (with default path) "+\
|
174
|
+
"\nif you specificated one manualy pls type"+\
|
175
|
+
" the path first in with '-p xy/xzt.pid'"
|
176
|
+
end
|
177
|
+
DaemonOgre::App.terminate=true
|
178
|
+
end
|
179
|
+
|
180
|
+
def clear
|
181
|
+
|
182
|
+
logs = ['loh_path','daemon_stderr','exceptions','exlogger']
|
183
|
+
|
184
|
+
logs.each do |logname|
|
185
|
+
begin
|
186
|
+
File.delete DaemonOgre::App.__send__(logname)
|
187
|
+
rescue Exception => ex
|
188
|
+
puts ex if $DEBUG
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|