I would like to use this Ruby WEBrick server solution for on-demand showcasing of some random web pages. So I set up some forwarding exception on my adsl modem local web interface(192.168.2.1). Then enabled iptables
with a very basic setup. I use an iptables
command to temporarily open port 3000 for tcp, then launch the Ruby script, and when I interrupt the server(with ctlr-c), it closes and I remove that very same filter rule to tidy things up(even though I know the rule wouldn't persist accross reboots):
# sudo iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
# ./myscript(ruby) - server goes up
<ctrl-c> - server goes down
# sudo iptables -D INPUT -p tcp --dport 3000 -j ACCEPT
How would I do that with a single command/script? I can make an alias to wrap the first command and starting the server, but it's not clear how to take care of the exit and the last command...