/
play
executable file
·61 lines (44 loc) · 1.35 KB
/
play
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'play'
require 'optparse'
# Auto-migrate before launching the servers.
def migrate
ActiveRecord::Base.establish_connection(Play.config['db'])
ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../db/migrate/", ActiveRecord::Migrator.current_version)
end
parser = OptionParser.new do |opts|
opts.banner = "Usage: play [options] COMMAND"
opts.separator ""
opts.separator "Options:"
opts.on("-d", "--detach", "Start the music server") do
ENV['RACK_ENV'] = 'production'
migrate
# Run a "quick" import to check for anything new.
pid = fork { Play::Library.import_songs }
Process.detach(pid)
pid = fork { Play::Client.loop }
Process.detach(pid)
end
opts.on("-s", "--stop", "Stop the music server") do
Play::Client.stop
end
opts.on("-w", "--web", "Run the web instance") do
migrate
pid = fork { Play::Library.monitor }
Process.detach(pid)
system("unicorn -c #{File.dirname(__FILE__)}/../config/unicorn.rb")
end
opts.on("-p", "--path", "Pause the music server") do |path|
Play::Client.pause
end
opts.on("-i", "--import", "Import new songs") do |import|
Play::Library.import_songs
exit
end
opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
end
parser.parse!