cinchize 0.0.3 → 0.1.0

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.
data/README.rdoc CHANGED
@@ -10,17 +10,19 @@ An early version of program which purpose is to daemonize Cinch ircbots from "si
10
10
 
11
11
  Basic
12
12
 
13
- cinchize network
13
+ cinchize --start network
14
14
 
15
15
  The config file can either be in the current working directory or in /etc, should be called cinchize.json, i.e. /etc/cinchize.json, use -s to look for the file in /etc
16
16
 
17
- cinchize -s network
17
+ cinchize -s --start network
18
18
 
19
19
  To daemonzize, use -d
20
20
 
21
- cinchize -d network
21
+ cinchize -d --start network
22
22
 
23
- Network is the name you call the a server config in the servers part of the config file, i.e. "freenode", "my_cute_bot", "quakenet" or similar.
23
+ Network is the name you call the a server config in the servers part of the config file, i.e. "freenode", "my_cute_bot", "quakenet" or similar.
24
+
25
+ --start, --restart, --stop and --status assumes that the config file is located in the current working directory unless -s is used.
24
26
 
25
27
  == Config-file
26
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
data/cinchize.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cinchize}
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Bergöö"]
12
- s.date = %q{2010-10-31}
12
+ s.date = %q{2010-11-08}
13
13
  s.default_executable = %q{cinchize}
14
14
  s.description = %q{Create dynamic Cinch IRC-bots and daemonize them, without the need of writing any code}
15
15
  s.email = %q{victor.bergoo@gmail.com}
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "bin/cinchize",
28
28
  "cinchize.gemspec",
29
+ "examples/cinchize.init",
29
30
  "lib/cinchize.rb"
30
31
  ]
31
32
  s.homepage = %q{http://github.com/netfeed/cinchize}
@@ -0,0 +1,41 @@
1
+ #!/bin/bash
2
+ # Copyright (c) 2010 Victor Bergöö
3
+ # This program is made available under the terms of the MIT License.
4
+
5
+ # assumes that the config file is located at /etc/cinchize.json
6
+
7
+ RETVAL=0;
8
+ NETWORK="freenode"
9
+
10
+ start() {
11
+ cinchize -ds --start $NETWORK
12
+ }
13
+
14
+ status() {
15
+ cinchize -s --status $NETWORK
16
+ }
17
+
18
+ stop() {
19
+ cinchize -s --stop $NETWORK
20
+ }
21
+
22
+ restart() {
23
+ cinchize -ds --restart $NETWORK
24
+ }
25
+
26
+ case "$1" in
27
+ start)
28
+ start
29
+ ;;
30
+ status)
31
+ status
32
+ ;;
33
+ stop)
34
+ stop
35
+ ;;
36
+ restart)
37
+ restart
38
+ ;;
39
+ esac
40
+
41
+ exit $RETVAL
data/lib/cinchize.rb CHANGED
@@ -16,6 +16,7 @@ module Cinchize
16
16
  :system => false,
17
17
  :local_config => File.join(Dir.pwd, 'cinchize.json'),
18
18
  :system_config => '/etc/cinchize.json',
19
+ :action => nil,
19
20
  }
20
21
 
21
22
  def self.run
@@ -33,10 +34,49 @@ module Cinchize
33
34
  options[:system] = true
34
35
  }
35
36
 
37
+ o.on("--start", "Start the bot") {
38
+ options[:action] = :start
39
+ }
40
+
41
+ o.on("--status", "Status of the bot") {
42
+ options[:action] = :status
43
+ }
44
+
45
+ o.on("--stop", "Stop the bot") {
46
+ options[:action] = :stop
47
+ }
48
+
49
+ o.on("--restart", "Restart the bot") {
50
+ options[:action] = :restart
51
+ }
52
+
36
53
  o.parse!
37
54
  end
38
55
 
39
56
  d_options, network, plugins, plugin_options = config(options, ARGV.first)
57
+
58
+ case options[:action]
59
+ when :start then
60
+ start(d_options, network, plugins, plugin_options)
61
+ when :status then
62
+ status(d_options[:dir], d_options[:app_name])
63
+ when :stop then
64
+ stop(d_options[:dir], d_options[:app_name])
65
+ when :restart then
66
+ stop(d_options[:dir], d_options[:app_name])
67
+ start(d_options, network, plugins, plugin_options)
68
+ else
69
+ puts "Error: no valid action supplied"
70
+ exit 1
71
+ end
72
+ rescue ArgumentError => e
73
+ puts "Error: #{e}"
74
+ exit 1
75
+ end
76
+
77
+ def self.start d_options, network, plugins, plugin_options
78
+ puts "* starting #{d_options[:app_name].split('_').last}"
79
+
40
80
  daemon = Daemons::ApplicationGroup.new(d_options[:app_name], {
41
81
  :ontop => d_options[:ontop],
42
82
  :dir => d_options[:dir],
@@ -57,14 +97,37 @@ module Cinchize
57
97
 
58
98
  bot.start
59
99
  end
60
- rescue ArgumentError => e
61
- puts "Error: #{e}"
62
- exit 1
63
100
  end
64
101
 
65
- def self.config options, network
66
- cmd_options = []
102
+ def self.stop dir, app_name
103
+ pidfile = Daemons::PidFile.new dir, app_name
104
+ unless pidfile.pid
105
+ puts "* #{app_name.split('_').last} is not running"
106
+ return
107
+ end
108
+
109
+ puts "* stopping #{app_name.split('_').last}"
67
110
 
111
+ Process.kill(9, pidfile.pid)
112
+ File.delete(pidfile.filename)
113
+ end
114
+
115
+ def self.status dir, app_name
116
+ pidfile = Daemons::PidFile.new dir, app_name
117
+
118
+ unless pidfile.pid
119
+ puts "* #{app_name.split('_').last} is not running"
120
+ return
121
+ end
122
+
123
+ if Process.kill(0, pidfile.pid) != 0
124
+ puts "* #{app_name.split('_').last} is running"
125
+ else
126
+ puts "* #{app_name.split('_').last} is not running"
127
+ end
128
+ end
129
+
130
+ def self.config options, network
68
131
  config_file = options[:system] ? options[:system_config]: options[:local_config]
69
132
 
70
133
  raise ArgumentError.new "the config file #{config_file} doesn't exist" unless File.exists? config_file
@@ -123,7 +186,7 @@ module Daemons
123
186
  class Application
124
187
  def start_none
125
188
  unless options[:ontop]
126
- Daemonize.daemonize(output_logfile, @group.app_name)
189
+ Daemonize.daemonize(output_logfile, @group.app_name) # our change goes here
127
190
  else
128
191
  Daemonize.simulate
129
192
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Victor Berg\xC3\xB6\xC3\xB6"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-31 00:00:00 +02:00
17
+ date: 2010-11-08 00:00:00 +01:00
18
18
  default_executable: cinchize
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,7 @@ files:
73
73
  - VERSION
74
74
  - bin/cinchize
75
75
  - cinchize.gemspec
76
+ - examples/cinchize.init
76
77
  - lib/cinchize.rb
77
78
  has_rdoc: true
78
79
  homepage: http://github.com/netfeed/cinchize