标签:
有时候,我们需要服务器能控制远程服务器做一些事情,同时稳定靠谱,不会突然挂掉什么的。
那么ruby就是极好的工具啦。
# encoding: utf-8
#!/usr/bin/ruby
# encoding: utf-8
# 端口 1990
# 浏览器访问:http://127.0.0.1:1990/hello/password
require ‘sinatra/base‘
require ‘json‘
require ‘net/http‘
class Hello < Sinatra::Base
  set :port, 1990
  set :bind, ‘0.0.0.0‘
  set :environment, :production
  get ‘/hello/:pwd‘ do
    {result:1, message:‘hello‘}.to_json
  end
  class << self
    def init
      puts ‘init‘
    end
  end
  
  init
  run!
end
基于非常有名的sinatra web框架,非常赞的迷你框架,只需要几行代码就实现了一个web程序,这里用来跑远程脚本,稳定可靠。当然也可以使用自带的webbrick,但是代码看起来就没这舒服了。
ruby run.rb 就跑起来了。。
标签:
原文地址:http://my.oschina.net/moli/blog/471359