#!/usr/bin/ruby ## restart given service with eg /etc/init.d/$thing restart ## syntactic sugar, practice, Artistic License (C) 2008 ## Debian and most use /etc/init.d/ @initscripts = '/etc/init.d/' ## Usage def usage p 'restart.rb: Take one argument, a service name from /etc/init.d . ' exit end ## if number of args is not 1, show usage if ARGV.length != 1 usage end ## check configuration if ! File.directory?(@initscripts) p 'No such directory: ' + @initscripts usage end ## get arg @service = ARGV.pop ## if arg service is not in /etc/init.d , point that out and usage. # if ![ -x '/etc/init.d/#{@service}'] if ! File.exist?(@initscripts + @service) p 'reboot.rb: ' + @initscripts + @service + ' not found.' usage end ## And finally, cycle something system(@initscripts + @service + ' restart')