gadfly 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ae2ac555cd1e6df227c14d4fa7bbaaf1eee46eb
4
+ data.tar.gz: c02b534e549a6c2641593d42e0600ba82a917832
5
+ SHA512:
6
+ metadata.gz: caf43e8b0343f8a130eb5fa10bb741c804399054642288dcbe224e7aaa8c9d637e1ef5f4d61b0a6793bedaf066ede7d1a5b8639c30149442d58d1c88ff801123
7
+ data.tar.gz: 716f9a00bff059e10314b6e8914efd6283c174b8b240c72a75309e0531225ac6a3e73e22189bcdb83127a6b757ea2d667060ce8843f8e53eeee53fdb01e7676f
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ gem "minitest", "4.7.1"
3
+ gem 'pry'
4
+ gem 'turn'
5
+ gem 'rake'
6
+ gem 'selenium-webdriver'
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gadfly (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.4.3)
10
+ childprocess (0.3.9)
11
+ ffi (~> 1.0, >= 1.0.11)
12
+ coderay (1.0.9)
13
+ ffi (1.7.0)
14
+ method_source (0.8.1)
15
+ minitest (4.7.1)
16
+ multi_json (1.7.2)
17
+ pry (0.9.12)
18
+ coderay (~> 1.0.5)
19
+ method_source (~> 0.8)
20
+ slop (~> 3.4)
21
+ rake (10.0.4)
22
+ rubyzip (0.9.9)
23
+ selenium-webdriver (2.32.1)
24
+ childprocess (>= 0.2.5)
25
+ multi_json (~> 1.0)
26
+ rubyzip
27
+ websocket (~> 1.0.4)
28
+ slop (3.4.4)
29
+ turn (0.9.6)
30
+ ansi
31
+ websocket (1.0.7)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ gadfly!
38
+ minitest (= 4.7.1)
39
+ pry
40
+ rake
41
+ selenium-webdriver
42
+ turn
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new('test') do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/tests/**/*.rb']
6
+ end
7
+
8
+ task :build do
9
+ system 'gem build gadfly.gemspec'
10
+ `rm -rf build`
11
+ `mkdir build`
12
+ `mv *.gem build`
13
+ end
data/Vagrantfile ADDED
@@ -0,0 +1,100 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "precise32_ruby"
11
+ config.ssh.forward_agent = true
12
+
13
+ # The url from where the 'config.vm.box' box will be fetched if it
14
+ # doesn't already exist on the user's system.
15
+ # config.vm.box_url = "http://domain.com/path/to/above.box"
16
+
17
+ # Boot with a GUI so you can see the screen. (Default is headless)
18
+ # config.vm.boot_mode = :gui
19
+
20
+ # Assign this VM to a host-only network IP, allowing you to access it
21
+ # via the IP. Host-only networks can talk to the host machine as well as
22
+ # any other machines on the same network, but cannot be accessed (through this
23
+ # network interface) by any external networks.
24
+ # config.vm.network :hostonly, "192.168.33.10"
25
+
26
+ # Assign this VM to a bridged network, allowing you to connect directly to a
27
+ # network using the host's network device. This makes the VM appear as another
28
+ # physical device on your network.
29
+ # config.vm.network :bridged
30
+
31
+ # Forward a port from the guest to the host, which allows for outside
32
+ # computers to access the VM, whereas host only networking does not.
33
+ # config.vm.forward_port 80, 8080
34
+
35
+ # Share an additional folder to the guest VM. The first argument is
36
+ # an identifier, the second is the path on the guest to mount the
37
+ # folder, and the third is the path on the host to the actual folder.
38
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
39
+
40
+ # Enable provisioning with Puppet stand alone. Puppet manifests
41
+ # are contained in a directory path relative to this Vagrantfile.
42
+ # You will need to create the manifests directory and a manifest in
43
+ # the file precise32.pp in the manifests_path directory.
44
+ #
45
+ # An example Puppet manifest to provision the message of the day:
46
+ #
47
+ # # group { "puppet":
48
+ # # ensure => "present",
49
+ # # }
50
+ # #
51
+ # # File { owner => 0, group => 0, mode => 0644 }
52
+ # #
53
+ # # file { '/etc/motd':
54
+ # # content => "Welcome to your Vagrant-built virtual machine!
55
+ # # Managed by Puppet.\n"
56
+ # # }
57
+ #
58
+ # config.vm.provision :puppet do |puppet|
59
+ # puppet.manifests_path = "manifests"
60
+ # puppet.manifest_file = "precise32.pp"
61
+ # end
62
+
63
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
64
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
65
+ # some recipes and/or roles.
66
+ #
67
+ # config.vm.provision :chef_solo do |chef|
68
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
69
+ # chef.roles_path = "../my-recipes/roles"
70
+ # chef.data_bags_path = "../my-recipes/data_bags"
71
+ # chef.add_recipe "mysql"
72
+ # chef.add_role "web"
73
+ #
74
+ # # You may also specify custom JSON attributes:
75
+ # chef.json = { :mysql_password => "foo" }
76
+ # end
77
+
78
+ # Enable provisioning with chef server, specifying the chef server URL,
79
+ # and the path to the validation key (relative to this Vagrantfile).
80
+ #
81
+ # The Opscode Platform uses HTTPS. Substitute your organization for
82
+ # ORGNAME in the URL and validation key.
83
+ #
84
+ # If you have your own Chef Server, use the appropriate URL, which may be
85
+ # HTTP instead of HTTPS depending on your configuration. Also change the
86
+ # validation key to validation.pem.
87
+ #
88
+ # config.vm.provision :chef_client do |chef|
89
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
90
+ # chef.validation_key_path = "ORGNAME-validator.pem"
91
+ # end
92
+ #
93
+ # If you're using the Opscode platform, your validator client is
94
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
95
+ #
96
+ # IF you have your own Chef Server, the default validation client name is
97
+ # chef-validator, unless you changed the configuration.
98
+ #
99
+ # chef.validation_client_name = "ORGNAME-validator"
100
+ end
data/bin/gadfly ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gadfly'
3
+ Gadfly.install_upstart_script(ARGV[0])
data/gadfly.gemspec ADDED
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'gadfly'
3
+ gem.version = '0.0.1'
4
+ gem.summary = 'run a ruby script as an upstart daemon'
5
+ gem.author = 'Lihan Li'
6
+ gem.email = 'frankieteardrop@gmail.com'
7
+ gem.homepage = 'http://github.com/lihanli/gadfly'
8
+
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11
+ gem.require_paths = ["lib"]
12
+ gem.executables << 'gadfly'
13
+ end
data/lib/gadfly.rb ADDED
@@ -0,0 +1,53 @@
1
+ module Gadfly
2
+ INIT_DIR = '/etc/init'
3
+
4
+ module Helpers
5
+ def self.command?(command)
6
+ system("which #{command} > /dev/null 2>&1")
7
+ end
8
+ end
9
+
10
+ def self.install_upstart_script(script_name)
11
+ script_name = script_name.gsub('.rb', '')
12
+
13
+ raise('script not found') unless File.exists?("#{script_name}.rb")
14
+ raise('upstart not installed') unless Helpers.command?('start') && Helpers.command?('stop')
15
+
16
+ start_script = <<-eos
17
+ #!/bin/bash
18
+
19
+ set -u
20
+ set -e
21
+
22
+ INIT_RBENV='export PATH=$PATH:$HOME/.rbenv/bin; eval "$(rbenv init -)"'
23
+
24
+ CMD="$INIT_RBENV; cd '#{Dir.pwd}'; bundle exec ruby #{script_name}.rb"
25
+
26
+ su - #{ENV['USER']} -c "$CMD";
27
+ eos
28
+
29
+ conf = <<-eos
30
+ description "#{script_name}"
31
+
32
+ start on (local-filesystems and net-device-up IFACE=eth0)
33
+ stop on runlevel [016]
34
+
35
+ console log
36
+ exec #{Dir.pwd}/start_script
37
+ eos
38
+
39
+ `bundle`
40
+
41
+ File.open('start_script', 'w') { |f| f.write(start_script) }
42
+ `chmod +x start_script`
43
+
44
+ File.open("#{script_name}.conf", 'w') { |f| f.write(conf) }
45
+
46
+ [ 'mkdir -p /var/log/upstart',
47
+ "mv #{script_name}.conf #{INIT_DIR}",
48
+ "chown root:root #{INIT_DIR}/#{script_name}.conf",
49
+ "stop #{script_name}",
50
+ "start #{script_name}",
51
+ ].each { |c| system "sudo #{c}" }
52
+ end
53
+ end
data/test/foobar.rb ADDED
@@ -0,0 +1 @@
1
+ puts 'foobar'
data/test/start_script ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ set -u
4
+ set -e
5
+
6
+ INIT_RBENV='export PATH=$PATH:$HOME/.rbenv/bin; eval "$(rbenv init -)"'
7
+
8
+ CMD="$INIT_RBENV; cd '/vagrant/test'; bundle exec ruby foobar.rb"
9
+
10
+ su - vagrant -c "$CMD";
@@ -0,0 +1,28 @@
1
+ require 'minitest/autorun'
2
+ require 'turn'
3
+ require 'selenium-webdriver'
4
+ Turn.config.format = :pretty
5
+
6
+ LOG_FILE = '/var/log/upstart/foobar.log'
7
+
8
+ class GadflyTest < MiniTest::Unit::TestCase
9
+ # TODO find a wait function that doesnt depend on selenium
10
+ def wait_until
11
+ Selenium::WebDriver::Wait.new(timeout: 10).until do
12
+ begin
13
+ yield
14
+ rescue
15
+ false
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_gadfly
21
+ Dir.chdir('test')
22
+ system("sudo rm #{LOG_FILE}") if File.exists?(LOG_FILE)
23
+ assert_equal(true, `../bin/gadfly foobar`.include?('foobar start/running, process'))
24
+
25
+ wait_until { File.exists?(LOG_FILE) }
26
+ assert_equal('foobar', `sudo cat #{LOG_FILE}`.chomp)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gadfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lihan Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: frankieteardrop@gmail.com
15
+ executables:
16
+ - gadfly
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - Rakefile
23
+ - Vagrantfile
24
+ - bin/gadfly
25
+ - gadfly.gemspec
26
+ - lib/gadfly.rb
27
+ - test/foobar.rb
28
+ - test/start_script
29
+ - test/tests/gadfly_test.rb
30
+ homepage: http://github.com/lihanli/gadfly
31
+ licenses: []
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.0.0
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: run a ruby script as an upstart daemon
53
+ test_files:
54
+ - test/foobar.rb
55
+ - test/start_script
56
+ - test/tests/gadfly_test.rb