init 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +0,0 @@
1
- COPYING.txt
2
- History.txt
3
- Manifest.txt
4
- README.rdoc
5
- Rakefile
6
- examples/mongrel.rb
7
- examples/murmur.rb
8
- lib/aef/init.rb
9
- lib/aef/init/init.rb
10
- spec/bin/mock_daemon.rb
11
- spec/bin/simple_init.rb
12
- spec/init_spec.rb
13
- spec/spec_helper.rb
@@ -1,186 +0,0 @@
1
- = Init
2
-
3
- * Project: https://rubyforge.org/projects/aef/
4
- * RDoc: http://rdoc.info/projects/aef/init/
5
- * RDoc: http://aef.rubyforge.org/init/
6
- * Github: http://github.com/aef/init/
7
-
8
- == DESCRIPTION:
9
-
10
- Clean and simple *nix init scripts with Ruby
11
-
12
- == FEATURES/PROBLEMS:
13
-
14
- Tested and fully working on:
15
- * Ubuntu Linux 9.10 (Karmic Koala) on x86_64
16
- * Ruby 1.8.7
17
- * Ruby 1.9.2
18
- * Ruby Enterprise Edition 2010.02
19
- * JRuby 1.5.5
20
- * Rubinius 1.1.1
21
- * Microsoft Windows XP SP2 on x86
22
- * Ruby 1.8.7
23
- * Ruby 1.9.2
24
- * JRuby 1.5.5
25
- * Debian GNU/Linux 4.0 (Lenny) on x86
26
- * Ruby 1.8.7
27
- * Ruby 1.9.2
28
- * JRuby 1.5.3
29
-
30
- This projects tries to conform to:
31
- * SemVer (and SemVerTag), http://semver.org/
32
- * Ruby Packaging Standard, http://chneukirchen.github.com/rps/
33
- * Gem Packaging: Best Practices, http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices
34
-
35
- Additional facts:
36
- * Written purely in Ruby
37
- * Does not modify any exisiting classes or modules
38
-
39
- == SYNOPSIS:
40
-
41
- Load the library:
42
-
43
- require 'aef/init'
44
-
45
- Simply subclass Aef::Init and define at least a start and a stop method. At the
46
- end, call the parse method on that class.
47
-
48
- class DemoSubclass < Aef::Init
49
- def start
50
- system('echo start')
51
- end
52
-
53
- def stop
54
- system('echo stop')
55
- end
56
- end
57
-
58
- DemoSubclass.parse
59
-
60
- To be able to call the commands from ruby you should wrap the parse method call
61
- in a block that only calls it if the script is executed on the commandline.
62
-
63
- if __FILE__ == $PROGRAM_NAME
64
- DemoSubclass.parse
65
- end
66
-
67
- There is no need to implement the command restart in most cases, as there is one
68
- defined by default, which simply calls the commands stop and start in a row.
69
- A delay can between the two commands can be defined:
70
-
71
- class DemoSubclass < Aef::Init
72
- ...
73
- stop_start_delay 3
74
- ...
75
- end
76
-
77
- If no command is specified on the commandline, restart is called by default.
78
- This default can be changed:
79
-
80
- class DemoSubclass < Aef::Init
81
- ...
82
- default_command :start
83
- ...
84
- end
85
-
86
- If you want to share commands between init scripts, you can also simple put a
87
- class between Init and the final implementation:
88
-
89
- class CommonCommands > Aef::Init
90
- def common
91
- system('echo common')
92
- end
93
- end
94
-
95
- class DemoSubclass > CommonCommands
96
- ...
97
- end
98
-
99
- See the examples folder and spec/bin/simple_init.rb for working example classes.
100
-
101
- == REQUIREMENTS:
102
-
103
- none
104
-
105
- === Additional for automated testing
106
- * rubygems
107
- * hoe
108
- * rspec
109
- * facets
110
-
111
- == INSTALL:
112
-
113
- === Normal
114
-
115
- gem install init
116
-
117
- === High security (recommended)
118
-
119
- There is a high security installation option available through rubygems. It is
120
- highly recommended over the normal installation, although it may be a bit less
121
- comfortable. To use the installation method, you will need my public key, which
122
- I use for cryptographic signatures on all my gems. You can find the public key
123
- and more detailed verification information in the aef-certificates section of my
124
- rubyforge project[https://rubyforge.org/frs/?group_id=7890&release_id=31749]
125
-
126
- Add the key to your rubygems' trusted certificates by the following command:
127
-
128
- gem cert --add aef.pem
129
-
130
- Now you can install the gem while automatically verifying it's signature by the
131
- following command:
132
-
133
- gem install init --ignore-dependencies -P HighSecurity
134
-
135
- Please notice that you will need other keys for dependent libraries, so you may
136
- have to install dependencies manually.
137
-
138
- === Automated testing
139
-
140
- You can test this package through RSpec on your system. First find the path
141
- where the gem was installed to:
142
-
143
- gem which init
144
-
145
- Go into the root directory of the installed gem and run the following command
146
- to start the test runner:
147
-
148
- rake spec
149
-
150
- If something goes wrong you should be noticed through failing examples.
151
-
152
- == DEVELOPMENT:
153
-
154
- This software is developed in the source code management system git hosted
155
- at github.com. You can download the most recent sourcecode through the following
156
- command:
157
-
158
- git clone git://github.com/aef/init.git
159
-
160
- Help on making this software better is always very appreciated. If you want your
161
- 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[https://rubyforge.org/tracker/?group_id=7890] at
162
- rubyforge.org. You can generate a patch-file by the following command:
163
-
164
- git diff > patch.diff
165
-
166
- Please write tests for your changes and notice that I can't promise
167
- to include your changes before reviewing them.
168
-
169
- == LICENSE:
170
-
171
- Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2010
172
-
173
- This file is part of Init.
174
-
175
- Init is free software: you can redistribute it and/or modify
176
- it under the terms of the GNU General Public License as published by
177
- the Free Software Foundation, either version 3 of the License, or
178
- (at your option) any later version.
179
-
180
- This program is distributed in the hope that it will be useful,
181
- but WITHOUT ANY WARRANTY; without even the implied warranty of
182
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
183
- GNU General Public License for more details.
184
-
185
- You should have received a copy of the GNU General Public License
186
- along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -1,84 +0,0 @@
1
- # Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2010
2
- #
3
- # This file is part of Init.
4
- #
5
- # Init is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- # Clean and simple *nix init scripts with Ruby
19
- class Aef::Init
20
- VERSION = '1.2.1'.freeze
21
-
22
- # Call this to begin commandline parsing
23
- #
24
- # If an invalid command is specified on the commandline, a usage example is
25
- # displayed. If no command is specified, the default command is started
26
- def self.parse
27
- command = ARGV.shift || :default
28
-
29
- valid_commands = []
30
-
31
- self.ancestors.each do |klass|
32
- valid_commands += klass.public_instance_methods(false)
33
- break if klass == Aef::Init
34
- end
35
-
36
- valid_commands.uniq!
37
-
38
- @@default_command ||= 'restart'
39
- @@stop_start_delay ||= 0
40
-
41
- # This is neccessary because since ruby 1.9, the instance_methods method
42
- # returns an array of symbols instead of an array of strings which it did
43
- # in 1.8
44
- ruby_version_components = RUBY_VERSION.split('.').map(&:to_i)
45
- command = command.to_sym if ruby_version_components[0] >= 1 and ruby_version_components[1] >= 9
46
-
47
- if command == :default
48
- new.send(@@default_command)
49
- elsif valid_commands.include?(command)
50
- new.send(command)
51
- else
52
- puts "Usage: #$PROGRAM_NAME {#{valid_commands.sort.join('|')}}"; exit false
53
- end
54
- end
55
-
56
- # Set a delay in seconds between the call of the stop and the start method in
57
- # the predefined restart method
58
- def self.stop_start_delay(seconds)
59
- @@stop_start_delay = seconds
60
- end
61
-
62
- # Set a default command to be called if no command is specified on the
63
- # commandline.
64
- def self.default_command(command)
65
- @@default_command = command
66
- end
67
-
68
- # The start method needs to be implemented in a subclass
69
- def start
70
- warn 'start method needs to be implemented'; exit false
71
- end
72
-
73
- # The stop method needs to be implemented in a subclass
74
- def stop
75
- warn 'stop method needs to be implemented'; exit false
76
- end
77
-
78
- # By default restart simply calls stop and then start
79
- def restart
80
- stop
81
- sleep @@stop_start_delay
82
- start
83
- end
84
- end