Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Created March 15, 2016 15:20
Show Gist options
  • Save tolleiv/3dbf63221eea5cd0c1ce to your computer and use it in GitHub Desktop.
Save tolleiv/3dbf63221eea5cd0c1ce to your computer and use it in GitHub Desktop.
Tiny local server Rakefile
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