Created
March 15, 2016 15:20
-
-
Save tolleiv/3dbf63221eea5cd0c1ce to your computer and use it in GitHub Desktop.
Tiny local server Rakefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task default: :start | |
@pid_file='server.pid' | |
desc "Bring up a server" | |
task :start do | |
unless File.exist?(@pid_file) | |
@pid = Process.spawn( | |
'ruby -run -e httpd . -p 8000', | |
in: :close | |
) | |
File.open(@pid_file, 'w') {|f| f.write(@pid.to_s) } | |
sleep 1 | |
end | |
end | |
desc "Stop the demo server" | |
task :stop do | |
if File.exist?(@pid_file) | |
Process.kill("TERM", File.read(@pid_file).to_i) | |
File.delete(@pid_file) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment