# Script to restart webrick

**URL:** <https://www.ruby-forum.com/t/script-to-restart-webrick/76987>\
**Category:** Rails\
**Created:** [November 23, 2006, 4:13am UTC](https://www.ruby-forum.com/t/script-to-restart-webrick/76987 "2006-11-23T04:13:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bala\_Paranj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/41988e/32.png) [@bala\_Paranj](https://www.ruby-forum.com/u/bala_Paranj)\
**Post date:** [November 23, 2006, 4:13am UTC](https://www.ruby-forum.com/t/script-to-restart-webrick/76987/1 "2006-11-23T04:13:59Z")

</div>

Enjoy this little script to restart webrick:

#!/bin/sh  
pid=$(ps -o pid,command | grep ‘\<ruby script/server\>’ | awk ‘{print  
$1}’)  
kill -9 $pid  
ruby script/server

Run on prompt by entering: sh scriptname.sh

---

<div class="post-metadata">

**Author:** ![bala\_Paranj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/41988e/32.png) [@bala\_Paranj](https://www.ruby-forum.com/u/bala_Paranj)\
**Post date:** [November 23, 2006, 4:40am UTC](https://www.ruby-forum.com/t/script-to-restart-webrick/76987/2 "2006-11-23T04:40:40Z")

</div>

bala Paranj wrote:

> Enjoy this little script to restart webrick:

I do that like this:

def croakServer(server, response)  
response.status = 200  
response[‘Content-Type’] = “text/html”

```
response.body = '<html><head><title>Shutting Down</title></head>
                    <body>Shutting down 

```

MiniWikiRuby…’

```
server.shutdown()

```

end

def bounceServer(server, response)  
response.status = 200  
response[‘Content-Type’] = “text/html”

```
response.body = '<html><head><title>Bouncing</title></head>
                    <body>Bouncing MiniWikiRuby...</body></html>'

server.shutdown()
launch("ruby miniWiki.rb " + ARGV.join(' '))

```

end

```
if 80 != port then
    server.mount_proc '/croak' do |request, response|
        croakServer(server, response)
    end

    server.mount_proc '/bounce' do |request, response|
        bounceServer(server, response)
    end
end

```

If you mount Webrick on a non-public port, it exposes two “actions”,  
croak  
and bounce. They croak and bounce, respectively.

From a script, you can simply croak your server with

wget [http://localhost:8080/croak](http://localhost:8080/croak)

My (non-Rails) tests bounce a lite server when they start, using  
Net::HTTP  
for the wget role.

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!
