merb-manage 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/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_directory = "/etc/merb-manage"
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.entries(config).select { |e| e[e.length - 3, 3] == "yml" }.each do |yml|
16
+ begin
17
+ result = yield YAML.load(open(File.join(config, 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 directory - #{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
+ command = "merb -m #{yml['path']} "
34
+ command += "-u #{yml['user']} " unless yml["user"].nil?
35
+ command += "-G #{yml['group']} " unless yml["group"].nil?
36
+ command += "-a #{yml['adapter']} " unless yml["adapter"].nil?
37
+ command += "-e #{yml['environment']} " unless yml["environment"].nil?
38
+ command += "-c #{yml['servers']} " unless yml["servers"].nil?
39
+ command += "-d " if yml["servers"].nil?
40
+ command += "-p #{yml['port']} " unless yml["port"].nil?
41
+ command += "-l #{yml['logging']} " unless yml["logging"].nil?
42
+ command = "su #{yml['user']} -c \"#{command}\"" unless yml["user"].nil?
43
+ `#{command}`
44
+ end
45
+
46
+ # This stops the server as per the specified yml config
47
+ def stop(yml)
48
+ `merb -m #{yml["path"]} -k all`
49
+ end
50
+
51
+ # See if there is a -c argument
52
+ if ARGV.include?("-c")
53
+ # Attempt to grab the specified config directory
54
+ config = ARGV[ARGV.index("-c") + 1]
55
+ configuration_directory = config unless config.nil?
56
+ end
57
+
58
+ # Evaluate and execute the action being requested
59
+ case ARGV[0]
60
+ when "start":
61
+ each_config(configuration_directory) do |yml|
62
+ start(yml)
63
+ end
64
+ when "restart":
65
+ each_config(configuration_directory) do |yml|
66
+ stop(yml)
67
+ start(yml)
68
+ end
69
+ when "stop":
70
+ each_config(configuration_directory) do |yml|
71
+ stop(yml)
72
+ end
73
+ else
74
+ # Print out the usage as the arguments didn't match a known action
75
+ puts "Usage: merb-manage-ctl {start|stop|restart} (-c CONFIG_DIR)"
76
+ end
@@ -0,0 +1,8 @@
1
+ path: /var/www/sample_app
2
+ adapter: thin
3
+ environment: production
4
+ port: 5000
5
+ servers: 3
6
+ user: www-data
7
+ group: www-data
8
+ 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,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-manage
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.4"
5
+ platform: ruby
6
+ authors:
7
+ - El Draper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-20 00:00:00 +01: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
+ - bin/merb-manage-ctl
34
+ - config/merb.yml.sample
35
+ - resources/merb-manage
36
+ has_rdoc: false
37
+ homepage: http://github.com/eldiablo/merb-manage
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.0.1
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Provides easy configuration and management of Merb applications, including multiple servers and different adapters
62
+ test_files: []
63
+