lita 2.1.2 → 2.2.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.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/lita/cli.rb +38 -1
- data/lib/lita/daemon.rb +62 -0
- data/lib/lita/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b61601772ee2c0a0822f137d838dd8f2b2aed2b
|
4
|
+
data.tar.gz: a035716200ec7451d45e4b9cc6bf633200718a30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0088d680d6ded0dbeabfc979401010675d6e5d2b296dfdd66e06cadcfcf760d2db22ba480f9830a7d8eb05d3b81f1773bbe7ec8c6d20e4bb0820699eff90c195
|
7
|
+
data.tar.gz: 7225377452adbde322b4a9a1a62d2abb30721dee7b719b62e9d41c62ede19116b0979942374bfb195ea8eb2ebdec8efcbbe6ab1ba360927c17b42f065526775f
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Yes.
|
|
42
42
|
|
43
43
|
## Installation
|
44
44
|
|
45
|
-
First, install the gem with `gem install lita`. This gives you access to the `lita`
|
45
|
+
First, install the gem with `gem install lita`. This gives you access to the `lita` command. Run `lita help` to list available tasks.
|
46
46
|
|
47
47
|
Generate a new Lita instance by running `lita new NAME`. This will create a new directory called NAME (defaults to "lita") with a Gemfile and Lita configuration file.
|
48
48
|
|
@@ -295,7 +295,7 @@ module Lita
|
|
295
295
|
|
296
296
|
data = MultiJson.load(http_response.body)
|
297
297
|
rep = data["representative"]["name"]
|
298
|
-
redis.set(zip,
|
298
|
+
redis.set(zip, rep)
|
299
299
|
rep
|
300
300
|
end
|
301
301
|
end
|
@@ -386,6 +386,10 @@ If you use `lita: true` instead of `lita_handler: true` in the metadata for your
|
|
386
386
|
* Lita's logger is stubbed to prevent log messages from cluttering up your test output.
|
387
387
|
* Lita's configuration is cleared out before each example, so that the first call to `Lita.config` will start from the default configuration.
|
388
388
|
|
389
|
+
## Running as a daemon
|
390
|
+
|
391
|
+
Lita has built-in support for daemonization on Unix systems. When run as a daemon, Lita will redirect standard output and standard error to a log file, and write the process ID to a PID file. To start Lita as a daemon, run `lita -d`. There are additional command line flags for specifying the path of the log and PID files, which override the defaults. If an existing Lita process is running when `lita -d` is invoked, Lita will abort and leave the original process running, unless the `-k` flag is specified, in which case it will kill the existing process. Run `lita help` for information about all the possible command line flags.
|
392
|
+
|
389
393
|
## Deploying to Heroku
|
390
394
|
|
391
395
|
There are a few things worth mentioning when deploying an instance of Lita to Heroku:
|
data/lib/lita/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
|
3
|
+
require "lita/daemon"
|
4
|
+
|
3
5
|
module Lita
|
4
6
|
# The command line interface for Lita.
|
5
7
|
class CLI < Thor
|
@@ -14,12 +16,47 @@ module Lita
|
|
14
16
|
class_option :config,
|
15
17
|
aliases: "-c",
|
16
18
|
banner: "PATH",
|
17
|
-
default: "lita_config.rb",
|
19
|
+
default: File.expand_path("lita_config.rb", Dir.pwd),
|
18
20
|
desc: "Path to the configuration file to use"
|
19
21
|
|
22
|
+
class_option :daemonize,
|
23
|
+
aliases: "-d",
|
24
|
+
default: false,
|
25
|
+
desc: "Run Lita as a daemon",
|
26
|
+
type: :boolean
|
27
|
+
|
28
|
+
class_option :log_file,
|
29
|
+
aliases: "-l",
|
30
|
+
banner: "PATH",
|
31
|
+
default: Process.euid == 0 ?
|
32
|
+
"/var/log/lita.log" : File.expand_path("lita.log", ENV["HOME"]),
|
33
|
+
desc: "Path where the log file should be written when daemonized"
|
34
|
+
|
35
|
+
class_option :pid_file,
|
36
|
+
aliases: "-p",
|
37
|
+
banner: "PATH",
|
38
|
+
default: Process.euid == 0 ?
|
39
|
+
"/var/run/lita.pid" : File.expand_path("lita.pid", ENV["HOME"]),
|
40
|
+
desc: "Path where the PID file should be written when daemonized"
|
41
|
+
|
42
|
+
class_option :kill,
|
43
|
+
aliases: "-k",
|
44
|
+
default: false,
|
45
|
+
desc: "Kill existing Lita processes when starting the daemon",
|
46
|
+
type: :boolean
|
47
|
+
|
20
48
|
desc "start", "Starts Lita"
|
21
49
|
def start
|
22
50
|
Bundler.require
|
51
|
+
|
52
|
+
if options[:daemonize]
|
53
|
+
Daemon.new(
|
54
|
+
options[:pid_file],
|
55
|
+
options[:log_file],
|
56
|
+
options[:kill]
|
57
|
+
).daemonize
|
58
|
+
end
|
59
|
+
|
23
60
|
Lita.run(options[:config])
|
24
61
|
end
|
25
62
|
|
data/lib/lita/daemon.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
# Converts Lita to a daemon process.
|
5
|
+
class Daemon
|
6
|
+
# @param pid_path [String] The path to the PID file.
|
7
|
+
# @param log_path [String] The path to the log file.
|
8
|
+
# @param kill_existing [Boolean] Whether or not to kill existing processes.
|
9
|
+
def initialize(pid_path, log_path, kill_existing)
|
10
|
+
@pid_path = pid_path
|
11
|
+
@log_path = log_path
|
12
|
+
@kill_existing = kill_existing
|
13
|
+
end
|
14
|
+
|
15
|
+
# Converts Lita to a daemon process.
|
16
|
+
# @return [void]
|
17
|
+
def daemonize
|
18
|
+
handle_existing_process
|
19
|
+
Process.daemon(true)
|
20
|
+
File.open(@pid_path, "w") { |f| f.write(Process.pid) }
|
21
|
+
set_up_logs
|
22
|
+
at_exit { FileUtils.rm(@pid_path) if File.exist?(@pid_path) }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Abort if Lita is already running.
|
28
|
+
def ensure_not_running
|
29
|
+
if File.exist?(@pid_path)
|
30
|
+
abort <<-FATAL.chomp
|
31
|
+
PID file exists at #{@pid_path}. Lita may already be running. \
|
32
|
+
Kill the existing process or remove the PID file and then start Lita.
|
33
|
+
FATAL
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Call the appropriate method depending on kill mode.
|
38
|
+
def handle_existing_process
|
39
|
+
if @kill_existing
|
40
|
+
kill_existing_process
|
41
|
+
else
|
42
|
+
ensure_not_running
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Try to kill an existing process.
|
47
|
+
def kill_existing_process
|
48
|
+
pid = File.read(@pid_path).strip.to_i
|
49
|
+
Process.kill("TERM", pid)
|
50
|
+
rescue Errno::ESRCH, RangeError, Errno::EPERM
|
51
|
+
abort "Failed to kill existing Lita process #{pid}."
|
52
|
+
end
|
53
|
+
|
54
|
+
# Redirect the standard streams to a log file.
|
55
|
+
def set_up_logs
|
56
|
+
log_file = File.new(@log_path, "a")
|
57
|
+
$stdout.reopen(log_file)
|
58
|
+
$stderr.reopen(log_file)
|
59
|
+
$stderr.sync = $stdout.sync = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/lita/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Cuadra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/lita/authorization.rb
|
200
200
|
- lib/lita/cli.rb
|
201
201
|
- lib/lita/config.rb
|
202
|
+
- lib/lita/daemon.rb
|
202
203
|
- lib/lita/handler.rb
|
203
204
|
- lib/lita/handlers/authorization.rb
|
204
205
|
- lib/lita/handlers/help.rb
|