Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 90 lines (80 sloc) 1.974 kb
e52f52c @holman
holman authored
1 #!/usr/bin/env ruby
e65a348 @holman hax
holman authored
2 # encoding: UTF-8
e52f52c @holman
holman authored
3
4 $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
6 require 'play'
7
8411e5a @holman auto-migrate, closes #10
holman authored
8 # Auto-migrate before launching the servers.
319a768 @holman drop options and simplify startup
holman authored
9 #
10 # Returns nothing.
8411e5a @holman auto-migrate, closes #10
holman authored
11 def migrate
ecf6c20 @holman Print out migration try
holman authored
12 puts "Migrating your database"
6a84b3c @holman Fix migrations
holman authored
13 version = `ls db/migrate | wc -l`.to_i
8411e5a @holman auto-migrate, closes #10
holman authored
14 ActiveRecord::Base.establish_connection(Play.config['db'])
552739b @holman fix first-run migrations
holman authored
15 ActiveRecord::Migrator.migrate("#{File.dirname(__FILE__)}/../db/migrate/", version)
8411e5a @holman auto-migrate, closes #10
holman authored
16 end
17
319a768 @holman drop options and simplify startup
holman authored
18 # Starts up the web interface.
19 #
20 # Returns nothing.
21 def start_web
22 pid = fork { Play::Library.monitor }
23 Process.detach(pid)
e52f52c @holman
holman authored
24
319a768 @holman drop options and simplify startup
holman authored
25 puts "play is running on http://localhost:5050"
26 system("unicorn -c #{File.dirname(__FILE__)}/../config/unicorn.rb")
27 end
e52f52c @holman
holman authored
28
319a768 @holman drop options and simplify startup
holman authored
29 # Starts up the music server.
30 #
31 # Returns nothing.
32 def start_music
ef0a54c @medwards Abstract client, make client configurable, make afplay the default cl…
medwards authored
33 pid = fork { Play.client.loop }
319a768 @holman drop options and simplify startup
holman authored
34 Process.detach(pid)
35 end
e52f52c @holman
holman authored
36
319a768 @holman drop options and simplify startup
holman authored
37 # Forks and kicks off music indexing.
38 #
39 # Returns nothing.
40 def index_music
8001b91 @tombell Print that indexing is running in the background
tombell authored
41 puts "play is indexing your music in the background"
319a768 @holman drop options and simplify startup
holman authored
42 pid = fork { Play::Library.import_songs }
43 Process.detach(pid)
e52f52c @holman
holman authored
44 end
45
0e47301 @holman Album Art.
holman authored
46 # Fetches all the album art in the world.
47 #
48 # Returns nothing.
49 def fetch_art
50 Play::Album.fetch_art!
51 end
52
319a768 @holman drop options and simplify startup
holman authored
53 case ARGV[0]
54 when 'start'
55 start_music
56 start_web
57 index_music
58 when 'stop'
ef0a54c @medwards Abstract client, make client configurable, make afplay the default cl…
medwards authored
59 Play.client.stop
319a768 @holman drop options and simplify startup
holman authored
60 when 'music'
61 migrate
62 start_music
63 index_music
64 when 'web'
65 migrate
66 start_web
67 when 'pause'
ef0a54c @medwards Abstract client, make client configurable, make afplay the default cl…
medwards authored
68 Play.client.pause
319a768 @holman drop options and simplify startup
holman authored
69 when 'index'
069d17f @holman migrate all the things (closes #31)
holman authored
70 migrate
319a768 @holman drop options and simplify startup
holman authored
71 index_music
0e47301 @holman Album Art.
holman authored
72 when 'fetch-art'
73 fetch_art
7b751a1 @holman force a migrate
holman authored
74 when 'migrate'
75 migrate
319a768 @holman drop options and simplify startup
holman authored
76 else
77 puts "play ►"
78 puts ""
79 puts "USAGE: play [command]"
80 puts "COMMANDS: "
0481ff6 @tombell Add missing fetch-art command to help
tombell authored
81 puts " start - Starts the web and music servers."
82 puts " stop - Stops the music server."
83 puts " music - Starts the music server."
84 puts " web - Starts the web server."
85 puts " pause - Pauses the music server."
86 puts " fetch-art - Fetch album art."
87 puts " migrate - Forces a migration of the database."
88 puts " index - Forces a reindex of the music library."
319a768 @holman drop options and simplify startup
holman authored
89 end
Something went wrong with that request. Please try again.