Init
-
Project: rubyforge.org/projects/aef/
-
RDoc: rdoc.info/projects/aef/init/
-
RDoc: aef.rubyforge.org/init/
-
Github: github.com/aef/init/
DESCRIPTION:
Clean and simple *nix init scripts with Ruby
FEATURES/PROBLEMS:
Tested and fully working on:
-
Ubuntu Linux 9.10 (Karmic Koala) on x86_64
-
Ruby 1.8.7
-
Ruby 1.9.2
-
Ruby Enterprise Edition 2010.02
-
JRuby 1.5.5
-
Rubinius 1.1.1
-
-
Microsoft Windows XP SP2 on x86
-
Ruby 1.8.7
-
Ruby 1.9.2
-
JRuby 1.5.5
-
-
Debian GNU/Linux 4.0 (Lenny) on x86
-
Ruby 1.8.7
-
Ruby 1.9.2
-
JRuby 1.5.3
-
This projects tries to conform to:
-
SemVer (and SemVerTag), semver.org/
-
Ruby Packaging Standard, chneukirchen.github.com/rps/
-
Gem Packaging: Best Practices, weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
Additional facts:
-
Written purely in Ruby
-
Does not modify any exisiting classes or modules
SYNOPSIS:
Load the library:
require 'aef/init'
Simply subclass Aef::Init and define at least a start and a stop method. At the end, call the parse method on that class.
class DemoSubclass < Aef::Init
def start
system('echo start')
end
def stop
system('echo stop')
end
end
DemoSubclass.parse
To be able to call the commands from ruby you should wrap the parse method call in a block that only calls it if the script is executed on the commandline.
if __FILE__ == $PROGRAM_NAME
DemoSubclass.parse
end
There is no need to implement the command restart in most cases, as there is one defined by default, which simply calls the commands stop and start in a row. A delay can between the two commands can be defined:
class DemoSubclass < Aef::Init
...
stop_start_delay 3
...
end
If no command is specified on the commandline, restart is called by default. This default can be changed:
class DemoSubclass < Aef::Init
...
default_command :start
...
end
If you want to share commands between init scripts, you can also simple put a class between Init and the final implementation:
class CommonCommands > Aef::Init
def common
system('echo common')
end
end
class DemoSubclass > CommonCommands
...
end
See the examples folder and spec/bin/simple_init.rb for working example classes.
REQUIREMENTS:
none
Additional for automated testing
-
rubygems
-
hoe
-
rspec
-
facets
INSTALL:
Normal
gem install init
High security (recommended)
There is a high security installation option available through rubygems. It is highly recommended over the normal installation, although it may be a bit less comfortable. To use the installation method, you will need my public key, which I use for cryptographic signatures on all my gems. You can find the public key and more detailed verification information in the aef-certificates section of my rubyforge project
Add the key to your rubygems’ trusted certificates by the following command:
gem cert --add aef.pem
Now you can install the gem while automatically verifying it’s signature by the following command:
gem install init --ignore-dependencies -P HighSecurity
Please notice that you will need other keys for dependent libraries, so you may have to install dependencies manually.
Automated testing
You can test this package through RSpec on your system. First find the path where the gem was installed to:
gem which init
Go into the root directory of the installed gem and run the following command to start the test runner:
rake spec
If something goes wrong you should be noticed through failing examples.
DEVELOPMENT:
This software is developed in the source code management system git hosted at github.com. You can download the most recent sourcecode through the following command:
git clone git://github.com/aef/init.git
Help on making this software better is always very appreciated. If you want your changes to be included in the official release, please send me pull request on github.com. Alternatevitely you can also send me a patch through the project’s tracker at rubyforge.org. You can generate a patch-file by the following command:
git diff > patch.diff
Please write tests for your changes and notice that I can’t promise to include your changes before reviewing them.
LICENSE:
Copyright Alexander E. Fischer <[email protected]>, 2009-2010
This file is part of Init.
Init is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.