launch_tracks 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.
Files changed (4) hide show
  1. data/README.rdoc +63 -0
  2. data/bin/launch_tracks +92 -0
  3. data/lib/launch_tracks.rb +16 -0
  4. metadata +86 -0
@@ -0,0 +1,63 @@
1
+ = LaunchTracks
2
+
3
+ LaunchTracks uses launchd and the Tracks Rack server to start your Ruby web
4
+ apps on demand.
5
+
6
+ == Install
7
+
8
+ gem install launch_tracks
9
+
10
+ == Usage
11
+
12
+ cd /path/to/myapp
13
+ launch_tracks setup 4000
14
+
15
+ Your app will automatically start once you visit http://localhost:4000/ and
16
+ shutdown after 10 minutes idle.
17
+
18
+ The output from stdout and stderr will be available at /tmp/myapp-out.txt and /tmp/myapp-err.txt respectively.
19
+
20
+ To restart your app <tt>touch restart.txt</tt> in your app's base directory.
21
+
22
+ === Commands
23
+
24
+ [setup] Creates a launchd plist for your app in ~/Library/LaunchAgents, and
25
+ loads it, making your app available for on-demand startup. Requires a
26
+ port number for your app to run on as an argument.
27
+ Example: <tt>launch_tracks setup 4000</tt>
28
+
29
+ [load] Loads your app's launchd plist from ~/Library/LaunchAgents, making
30
+ your app available for on-demand startup.
31
+
32
+ [unload] Unloads your app's launchd plist from ~/Library/LaunchAgents,
33
+ disabling on-demand startup.
34
+
35
+ [restart] Restart your app. The same can be achieved with
36
+ <tt>touch restart.txt</tt> in your app's base directory.
37
+
38
+ [rm] Unload and remove your app's plist from ~/Library/LaunchAgents,
39
+ permanently disabling it.
40
+
41
+ == Licence
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2012 Matthew Sadler
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy
48
+ of this software and associated documentation files (the "Software"), to deal
49
+ in the Software without restriction, including without limitation the rights
50
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
+ copies of the Software, and to permit persons to whom the Software is
52
+ furnished to do so, subject to the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be included in
55
+ all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
63
+ THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+
4
+ name = FileUtils.pwd.split("/").last
5
+ label = "com.github.matsadler.launch_tracks.#{name}"
6
+ logdir = "/tmp"
7
+ plist_name = "#{label}.plist"
8
+ plist_dir = File.expand_path("~/Library/LaunchAgents")
9
+ plist_path = "#{plist_dir}/#{plist_name}"
10
+
11
+ command, port = ARGV
12
+
13
+ help = "Usage: launch_tracks help|setup PORTNUMBER|load|unload|restart|rm"
14
+
15
+ case command
16
+ when "help", "-h", "--help"
17
+ puts help
18
+ exit
19
+ when "load"
20
+ exec "launchctl load #{plist_path}"
21
+ when "unload"
22
+ exec "launchctl unload #{plist_path}"
23
+ when "restart"
24
+ FileUtils.touch("restart.txt")
25
+ exit
26
+ when "rm"
27
+ `launchctl unload #{plist_path}`
28
+ FileUtils.rm(plist_path)
29
+ exit
30
+ when "setup"
31
+ abort help unless port =~ /^\d+$/
32
+ # continue
33
+ else
34
+ abort help
35
+ end
36
+
37
+ plist = <<-PLIST
38
+ <?xml version="1.0" encoding="UTF-8"?>
39
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
40
+ <plist version="1.0">
41
+ <dict>
42
+
43
+ <key>Label</key>
44
+ <string>#{label}</string>
45
+
46
+ <key>WorkingDirectory</key>
47
+ <string>#{FileUtils.pwd}</string>
48
+
49
+ <key>StandardOutPath</key>
50
+ <string>#{logdir}/#{name}-out.log</string>
51
+
52
+ <key>StandardErrorPath</key>
53
+ <string>#{logdir}/#{name}-err.log</string>
54
+
55
+ <key>EnvironmentVariables</key>
56
+ <dict>
57
+ #{ENV.map do |key,string|
58
+ "<key>#{key}</key>
59
+ <string>#{string}</string>"
60
+ end.join("\n ")}
61
+ </dict>
62
+
63
+ <key>ProgramArguments</key>
64
+ <array>
65
+ #{if File.exist?("Gemfile")
66
+ "<string>bundle</string>
67
+ <string>exec</string>
68
+ "
69
+ end}<string>rackup</string>
70
+ <string>-rlaunch_tracks</string>
71
+ <string>-slaunch_tracks</string>
72
+ </array>
73
+
74
+ <key>Sockets</key>
75
+ <dict>
76
+ <key>http</key>
77
+ <dict>
78
+ <key>SockServiceName</key>
79
+ <string>#{port}</string>
80
+ <key>SockFamily</key>
81
+ <string>IPv4</string>
82
+ </dict>
83
+ </dict>
84
+
85
+ </dict>
86
+ </plist>
87
+ PLIST
88
+
89
+ FileUtils.mkdir_p(plist_dir)
90
+ File.open(plist_path, "w") {|f| f << plist}
91
+
92
+ exec "launchctl load #{plist_path}"
@@ -0,0 +1,16 @@
1
+ require "fileutils"
2
+ require "launch"
3
+ require "tracks"
4
+ require "rack/idle"
5
+
6
+ Rack::Handler.register("launch_tracks", "LaunchTracks")
7
+
8
+ module LaunchTracks
9
+
10
+ def self.run(app, options={})
11
+ app = Rack::Idle.new(app, :watch => "restart.txt")
12
+ sockets = Launch::Job.checkin.sockets["http"]
13
+ Tracks.new(app, options).listen(sockets.first)
14
+ end
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: launch_tracks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Sadler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: launch
16
+ requirement: &70168027907900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70168027907900
25
+ - !ruby/object:Gem::Dependency
26
+ name: tracks
27
+ requirement: &70168027907420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70168027907420
36
+ - !ruby/object:Gem::Dependency
37
+ name: rack-idle
38
+ requirement: &70168027906960 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70168027906960
47
+ description: Automaticlly start Rack applications on demand using launchd.
48
+ email: mat@sourcetagsandcodes.com
49
+ executables:
50
+ - launch_tracks
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ files:
55
+ - lib/launch_tracks.rb
56
+ - README.rdoc
57
+ - bin/launch_tracks
58
+ homepage: http://github.com/matsadler/launch_tracks
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --main
63
+ - README.rdoc
64
+ - --charset
65
+ - utf-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.10
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Start Rack apps on demand with launchd.
86
+ test_files: []