norr-merb-manage 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTORS ADDED
@@ -0,0 +1,5 @@
1
+ merb-manage: a tool for controlling and configuring Merb applications
2
+
3
+ Contributors:
4
+
5
+ * Fabien Franzen (loob2) - http://github.com/fabien
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 El Draper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,40 @@
1
+ merb-manage: a tool for controlling and configuring Merb applications
2
+
3
+ Usage:
4
+
5
+ merb-manage-ctl [start|stop|restart] (-c CONFIG_DIR)
6
+ start: starts any instances of Merb applications configured within the CONFIG_DIR (defaults to /etc/merb-manage)
7
+ stop: stops any instances of Merb applications configured within the CONFIG_DIR
8
+ restart: stops, then starts any instances of Merb applications configured within the CONFIG_DIR
9
+
10
+ merb-manage [start|stop|restart]
11
+ this script can be used as a startup script, for example within /etc/init.d, to call out to merb-manage-ctl to start Merb applications when a server starts
12
+
13
+
14
+ Configuration:
15
+
16
+ YAML configuration files define the Merb application settings for merb-manage. Generally you can store the configuration within the config directory of your Merb application (config/merb-manage.yml), and then symlink this to a file within the configuration directory (/etc/merb-manage/myapp.yml).
17
+
18
+ Configuration might look like the following:
19
+
20
+ path: /var/www/sample_app
21
+ gem: false
22
+ adapter: thin
23
+ environment: production
24
+ port: 5000
25
+ servers: 3
26
+ user: www-data
27
+ group: www-data
28
+ logging: info
29
+
30
+ Here are the supported parameters:
31
+ user: the user that the application should run as - if specified, the Merb application is started with an su USER -c "COMMAND", and the user is passed through to the Merb startup command
32
+ group: the group that the application runs under, passed through to the Merb startup command
33
+ adapter: the web application server adapter, such as mongrel, thin etc - anything that your installation of Merb supports
34
+ environment: the Merb environment to run as, development, test or production
35
+ servers: the amount of servers to start (for clustering/load balancing etc)
36
+ port: the port to start the Merb application on (in the case of multiple servers, the ports will be sequential from the port specified, i.e. servers set to 3, with port set to 5000, would start the application on 5000, 5001 and 5002)
37
+ logging: the logging level to pass through to Merb - debug, info, warn, error and fatal
38
+ gem: set to true to use bundled merb gem in app (bin/merb). set to false or leave out to use global merb
39
+
40
+ Most of these options can be left off if you simply want the Merb defaults - if "servers" isn't specified however, then Merb will be passed the "-d" flag to ensure that the single Merb server will run in daemonized mode.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2008 El Draper, el@eldiablo.co.uk
4
+ #
5
+ # merb-manage-ctl Controller script for starting/stopping/restarting configured Merb applications
6
+ #
7
+ require "yaml"
8
+
9
+ # Default config directory
10
+ configuration_pattern = "/etc/merb-manage/*.yml"
11
+
12
+ # This iterates through each config found in the configuration directory, executing the specified block for each
13
+ def each_config(config, &block)
14
+ begin
15
+ Dir.glob(config) do |yml|
16
+ begin
17
+ result = yield YAML.load(open(File.join(yml)))
18
+ puts "#{yml}:"
19
+ result.split("\n").each { |r| puts r }
20
+ rescue Exception => err
21
+ puts "Exception (#{yml}): #{err.message}"
22
+ end
23
+ end
24
+ rescue Errno::ENOENT
25
+ puts "Unable to find #{config}"
26
+ rescue Errno::ENOTDIR
27
+ puts "Not a directory - #{config}"
28
+ end
29
+ end
30
+
31
+ # This starts the server as per the specified yml config
32
+ def start(yml)
33
+ # Decide which merb to use, bundled gem or global
34
+ if yml["gem"].nil?
35
+ command = "merb -m #{yml['path']} "
36
+ else
37
+ if yml["gem"]
38
+ command = "#{yml['path']}/bin/merb -m #{yml['path']} "
39
+ else
40
+ command = "merb -m #{yml['path']} "
41
+ end
42
+ end
43
+ command += "-u #{yml['user']} " unless yml["user"].nil?
44
+ command += "-G #{yml['group']} " unless yml["group"].nil?
45
+ command += "-a #{yml['adapter']} " unless yml["adapter"].nil?
46
+ command += "-e #{yml['environment']} " unless yml["environment"].nil?
47
+ command += "-c #{yml['servers']} " unless yml["servers"].nil?
48
+ command += "-d " if yml["servers"].nil?
49
+ command += "-p #{yml['port']} " unless yml["port"].nil?
50
+ command += "-l #{yml['logging']} " unless yml["logging"].nil?
51
+ command = "su #{yml['user']} -c \"#{command}\"" unless yml["user"].nil?
52
+ `#{command}`
53
+ end
54
+
55
+ # This stops the server as per the specified yml config
56
+ def stop(yml)
57
+ `merb -m #{yml["path"]} -k all`
58
+ end
59
+
60
+ # See if there is a -c argument
61
+ if ARGV.include?("-c")
62
+ # Attempt to grab the specified config directory
63
+ config = ARGV[ARGV.index("-c") + 1]
64
+ configuration_pattern = config unless config.nil?
65
+ end
66
+
67
+ # Evaluate and execute the action being requested
68
+ case ARGV[0]
69
+ when "start":
70
+ each_config(configuration_pattern) do |yml|
71
+ start(yml)
72
+ end
73
+ when "restart":
74
+ each_config(configuration_pattern) do |yml|
75
+ stop(yml)
76
+ start(yml)
77
+ end
78
+ when "stop":
79
+ each_config(configuration_pattern) do |yml|
80
+ stop(yml)
81
+ end
82
+ else
83
+ # Print out the usage as the arguments didn't match a known action
84
+ puts "Usage: merb-manage-ctl {start|stop|restart} (-c CONFIG_GLOB)"
85
+ end
@@ -0,0 +1,9 @@
1
+ path: /var/www/sample_app
2
+ gem: false
3
+ adapter: thin
4
+ environment: production
5
+ port: 5000
6
+ servers: 3
7
+ user: www-data
8
+ group: www-data
9
+ logging: info
@@ -0,0 +1,41 @@
1
+ #!/bin/bash
2
+ #
3
+ # Copyright (c) 2008 El Draper, el@eldiablo.co.uk
4
+ #
5
+ # merb-manage Startup script for Merb applications, utilising merb-manage-ctl
6
+ #
7
+ # Can be used as a startup script to ensure Merb apps fire back up after a reboot (such as within /etc/init.d)
8
+ #
9
+ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin
10
+ MERB_MANAGE_CONF_DIR=/etc/merb-manage
11
+
12
+ # Default return value
13
+ RETVAL=0
14
+
15
+ # Exit if we can't find the merb-manage-ctl script
16
+ which merb-manage-ctl >/dev/null || exit 0
17
+
18
+ # Validate config directory
19
+ [ -d "$MERB_MANAGE_CONF_DIR" ] || exit 0
20
+
21
+ # Evaluate command
22
+ case "$1" in
23
+ start)
24
+ merb-manage-ctl start -c $MERB_MANAGE_CONF_DIR
25
+ RETVAL=$?
26
+ ;;
27
+ stop)
28
+ merb-manage-ctl stop -c $MERB_MANAGE_CONF_DIR
29
+ RETVAL=$?
30
+ ;;
31
+ restart)
32
+ merb-manage-ctl restart -c $MERB_MANAGE_CONF_DIR
33
+ RETVAL=$?
34
+ ;;
35
+ *)
36
+ echo "Usage: merb-manage {start|stop|restart}"
37
+ exit 1
38
+ ;;
39
+ esac
40
+
41
+ exit $RETVAL
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norr-merb-manage
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.6"
5
+ platform: ruby
6
+ authors:
7
+ - El Draper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ version:
24
+ description:
25
+ email: el@eldiablo.co.uk
26
+ executables:
27
+ - merb-manage-ctl
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - CONTRIBUTORS
34
+ - LICENSE
35
+ - README
36
+ - bin/merb-manage-ctl
37
+ - config/merb.yml.sample
38
+ - resources/merb-manage
39
+ has_rdoc: false
40
+ homepage: http://github.com/eldiablo/merb-manage
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Provides easy configuration and management of Merb applications, including multiple servers and different adapters
65
+ test_files: []
66
+