2012-01-09

如何在 Windows 底下添加系統服務(system service)

以下程式碼呼叫方法:

註冊服務
ruby name.rb reg

註銷服務
ruby name.rb del

服務執行之程式碼位於 service_main 區塊內

require 'rubygems'
require 'win32/service'
require 'win32/daemon'
include Win32

SERVICE_NAME = "RubyService"
SERVICE_DISPLAY_NAME = "A Ruby Service by vegafish"

if ( ARGV[ 0 ] == "reg" )
    Service.create({
        :service_name     => SERVICE_NAME,
        :service_type     => Service::WIN32_OWN_PROCESS,
        :description      => 'A custom service I wrote just for fun',
        :start_type       => Service::AUTO_START,
        :error_control    => Service::ERROR_NORMAL,
        :binary_path_name => 'c:\\ruby187\bin\ruby.exe ' + File.expand_path($0),
        :load_order_group => 'Network',
        :dependencies     => ['W32Time','Schedule'],
        :display_name     => SERVICE_DISPLAY_NAME
   })

    puts( "Service " + SERVICE_DISPLAY_NAME + " Registered." )
    Service.start( SERVICE_NAME )
    exit( 0 )
elsif ( ARGV[ 0 ] == "del" )
    if Service.status( SERVICE_NAME ).current_state == "running"
        Service.stop( SERVICE_NAME )
    end
    Service.delete( SERVICE_NAME )
    puts( "Service " + SERVICE_DISPLAY_NAME + " Removed." )
    exit( 0 )
end

class Daemon
    def service_init
        sleep( 5 )
    end
    
    def service_main
        filecount = 0
        watchfile = "c:\\vegafish.txt"
        while( running?() )
            sleep( 3 )
            if ( File.exists?( watchfile ) )
                filecount++
                File.rename( watchfile, watchfile + filecount.to_s )
            end
        end
    end
end

Daemon.mainloop()

2012-01-08

The Bug of Google Picasa Public URL

If you upload pictures via mobile Google+, your Picasa public URL will be changed* automatically.

This bug is not fixed at 2012-01-08.

* Changed from Gmail account to Google+ account number, e.g. http://picasaweb.google.com/vegafish -> http://picasaweb.google.com/117166741167778447153