Class: Cinchize::Cinchize
- Inherits:
-
Object
- Object
- Cinchize::Cinchize
- Defined in:
- lib/cinchize.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #app_name ⇒ Object
- #clean_app_name ⇒ Object
- #dir ⇒ Object
-
#initialize(options, network, plugins, plugin_options) ⇒ Cinchize
constructor
A new instance of Cinchize.
- #restart ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options, network, plugins, plugin_options) ⇒ Cinchize
Returns a new instance of Cinchize.
129 130 131 132 133 134 |
# File 'lib/cinchize.rb', line 129 def initialize , network, plugins, @network = network @plugins = plugins @plugin_options = @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
127 128 129 |
# File 'lib/cinchize.rb', line 127 def @options end |
Instance Method Details
#app_name ⇒ Object
136 137 138 |
# File 'lib/cinchize.rb', line 136 def app_name [:app_name] end |
#clean_app_name ⇒ Object
144 145 146 |
# File 'lib/cinchize.rb', line 144 def clean_app_name app_name.split('_', 2).last end |
#dir ⇒ Object
140 141 142 |
# File 'lib/cinchize.rb', line 140 def dir [:dir] end |
#restart ⇒ Object
148 149 150 151 |
# File 'lib/cinchize.rb', line 148 def restart stop start end |
#running? ⇒ Boolean
207 208 209 210 211 212 213 |
# File 'lib/cinchize.rb', line 207 def running? pidfile = Daemons::PidFile.new dir, app_name return false if pidfile.pid.nil? return Process.kill(0, pidfile.pid) != 0 rescue Errno::ESRCH => e return false end |
#start ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/cinchize.rb', line 153 def start if running? raise ArgumentError.new "#{clean_app_name} is already running" end puts "* starting #{clean_app_name}" daemon = Daemons::ApplicationGroup.new(app_name, { :ontop => [:ontop], :dir => dir, :dir_mode => [:dir_mode] }) app = daemon.new_application :mode => :none, :log_output => [:log_output] app.start network = @network plugins = @plugins = @plugin_options loop do bot = Cinch::Bot.new do configure do |c| network.each_pair { |key, value| c.send("#{key}=".to_sym, value) } c.plugins.plugins = plugins c.plugins. = end end bot.start end end |
#status ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/cinchize.rb', line 199 def status if running? puts "* #{clean_app_name} is running" else puts "* #{clean_app_name} is not running" end end |
#stop ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cinchize.rb', line 186 def stop unless running? puts "* #{clean_app_name} is not running" return end pidfile = Daemons::PidFile.new dir, app_name puts "* stopping #{clean_app_name}" Process.kill(9, pidfile.pid) File.delete(pidfile.filename) end |