fixingthenet-installer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cef1f66f36fcf75fceeeaf5054e9f69b9340659e
4
+ data.tar.gz: 8a689e079f82a96a669363394266c135559732bf
5
+ SHA512:
6
+ metadata.gz: d6ead90af49b3c5ed97ee0011e35f8316288099e2ec78e928cc909d46a40cfcc51fedd95cf48658a00cb1da8b56e74c64cf711c370f9559daae9029e7e8caa7b
7
+ data.tar.gz: 7afb6c3b520dd4e1c9e089e244da9ff96d2e838cd5048f936a40ea903f9f4a7cb428aed282224a4de5c18cfa99f059468a266c6f33c294ec75e5ca2571dc4463
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fixingthenet-installer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Peter Schrammel
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.md ADDED
@@ -0,0 +1,43 @@
1
+ # Fixingthenet::Installer
2
+
3
+ This gem provides some tools to (un)install, check and fixing-the-net apps in the system.
4
+
5
+ ## Installation
6
+
7
+
8
+ Installation:
9
+
10
+ $ gem install fixingthenet-installer
11
+
12
+ ## Usage
13
+
14
+ $ ftn install -p 9004 my_app
15
+
16
+ or
17
+ $ ftn uninstall -p 9004 my_app
18
+
19
+ this copies the needed templates into the system and start the app.
20
+
21
+ ## TODO
22
+ Lots! This is a first scratch. More is needed:
23
+ * code reorg
24
+ * sidekiq in init.d file
25
+ * status
26
+ * monit
27
+ * global config file /etc/fixingthenet/installer.json
28
+ * env support
29
+ * use meta files of plugins for installation
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/fixingthenet-installer/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ftn ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'fixingthenet/installer'
5
+
6
+
7
+ # install
8
+ # uninstall
9
+ # status
10
+
11
+
12
+ command = ARGV.shift
13
+
14
+ case command
15
+ when 'install'
16
+ Fixingthenet::Installer::InstallCommand.new(Fixingthenet::Installer::DEFAULT_OPTIONS, ARGV)
17
+ when 'uninstall'
18
+ Fixingthenet::Installer::UninstallCommand.new(Fixingthenet::Installer::DEFAULT_OPTIONS, ARGV)
19
+ #when 'status'
20
+ else
21
+ STDERR.puts "unknown command: '#{command}'"
22
+ exit 1
23
+ end
24
+
25
+
26
+ # bin/app_installer -v -p 9000 -m / -n root
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fixingthenet/installer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fixingthenet-installer"
8
+ spec.version = Fixingthenet::Installer::VERSION
9
+ spec.authors = ["Peter Schrammel"]
10
+ spec.email = ["peter.schrammel@gmx.de"]
11
+
12
+ # if spec.respond_to?(:metadata)
13
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ # end
15
+
16
+ spec.summary = %q{Command line tools to install and uninstall ftn apps on the fixingthenet platform.}
17
+ spec.description = %q{Fixingthenet command line installer.}
18
+ spec.homepage = "https://github.com/fixingthenet/fixingthenet-installer"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "bin"
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'ostruct'
2
+
3
+ module Fixingthenet
4
+ module Installer
5
+ class App < OpenStruct
6
+
7
+ def full_name
8
+ "fixingthenet-#{name}"
9
+ end
10
+
11
+ def root
12
+ apps_root.join(full_name)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module Fixingthenet
2
+ module Installer
3
+ class Command
4
+ attr_reader :args
5
+ attr_reader :options
6
+
7
+ def initialize(_options, args=[])
8
+ @options=_options
9
+ @args=args
10
+ parse_options unless args.empty?
11
+
12
+ app=App.new(options)
13
+ puts "options: #{options}" if options[:verbose]
14
+ command(app)
15
+ end
16
+
17
+ private
18
+
19
+ def parse_common_options(opts)
20
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
21
+ options[:verbose] = v
22
+ end
23
+
24
+ opts.on("-e", "--env ENV", "environment") do |v|
25
+ options[:env] = v
26
+ end
27
+
28
+ opts.on("-r", "--root ROOTPATH", "Root") do |op|
29
+ options[:apps_root] = Pathmame.new(op)
30
+ end
31
+
32
+ opts.on("-n", "--name NAME", "Name of the plugin") do |op|
33
+ options[:name] = op
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,52 @@
1
+ require 'erb'
2
+
3
+ module Fixingthenet
4
+ module Installer
5
+
6
+
7
+ #installs some templates for nginx and init.d
8
+ class InstallCommand < Command
9
+ private
10
+ def parse_options
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: ftn install [options]"
13
+
14
+ parse_common_options(opts)
15
+
16
+ opts.on("-p", "--port PORT", "Port") do |op|
17
+ options[:port] = op
18
+ end
19
+
20
+ opts.on("-m", "--mount MOUNT_PATH", "Mount path") do |op|
21
+ options[:mount_path] = op
22
+ end
23
+
24
+ opts.on("-t", "--template TEMPLATE_PATH", "Template path") do |op|
25
+ options[:template_path] = Pathname.new(op)
26
+ end
27
+ end.parse!(args)
28
+ end
29
+
30
+ def command(app)
31
+ {app.template_path.join('nginx_app.conf.erb') => NGINX_SITES_DIR.join(app.full_name),
32
+ app.template_path.join('initd.conf.erb') => INITD_DIR.join(app.full_name)
33
+ }.each do |template_name, destination|
34
+ template=File.read(template_name)
35
+ content=ERB.new(template).result(binding)
36
+ puts "#{template_name} -> #{destination}" if options[:verbose]
37
+ write_content(destination, content)
38
+ end
39
+
40
+ `sudo /etc/init.d/#{app.full_name} reload`
41
+ end
42
+
43
+ def write_content(file, content)
44
+ File.open(file, "w") do |fd|
45
+ fd.write content
46
+ end
47
+ FileUtils.chmod("u+x", file)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ module Fixingthenet
2
+ module Installer
3
+
4
+
5
+ #uninstalls
6
+ class UninstallCommand < Command
7
+ private
8
+ def parse_options
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: ftn uninstall [options]"
11
+
12
+ parse_common_options(opts)
13
+
14
+ end.parse!(args)
15
+ end
16
+
17
+ def command(app)
18
+ initd_filename="/etc/init.d/#{app.full_name}"
19
+ `sudo #{initd_filename} stop` if File.exist?(initd_filename)
20
+ [
21
+ NGINX_SITES_DIR.join(app.full_name),
22
+ INITD_DIR.join(app.full_name)
23
+
24
+ ].each do |destination|
25
+ FileUtils.rm(destination) if File.exist?(destination)
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module Fixingthenet
2
+ module Installer
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'pathname'
2
+ require 'optparse'
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ require "fixingthenet/installer/version"
7
+ require "fixingthenet/installer/app"
8
+ require "fixingthenet/installer/command"
9
+ require "fixingthenet/installer/install_command"
10
+ require "fixingthenet/installer/uninstall_command"
11
+
12
+
13
+ module Fixingthenet
14
+ module Installer
15
+
16
+ TEMPLATES_DIR=Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '..','templates')))
17
+ NGINX_SITES_DIR=Pathname.new "/etc/nginx/sites-enabled/"
18
+ INITD_DIR=Pathname.new("/etc/init.d/")
19
+
20
+ DEFAULT_OPTIONS = {:apps_root => Pathname.new('/vagrant/apps'),
21
+ :template_path => TEMPLATES_DIR,
22
+ :env => 'development',
23
+ :server_name => '192.168.40.10'
24
+ }
25
+
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ #! /bin/sh
2
+
3
+ ### BEGIN INIT INFO
4
+ # Provides: fixingthenet-root
5
+ # Required-Start: $all
6
+ # Required-Stop: $network $local_fs $syslog
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: starts fixingthenet-root
10
+ # Description: starts fixingthenet-root
11
+ ### END INIT INFO
12
+
13
+ # Change these to match your app:
14
+ APP_NAME=<%= app.app_name %>
15
+ DESC="fixingthenet-<%= app.name %>"
16
+
17
+ USER=vagrant
18
+ APP_ENV="<%= app.env %>"
19
+ APP_ROOT="<%= app.root %>"
20
+
21
+ SET_PATH="cd $APP_ROOT"
22
+ DAEMON="RAILS_ENV=$APP_ENV bundle exec rails server thin"
23
+ PID="$APP_ROOT/tmp/pids/server.pid"
24
+ STDOUTLOG="$APP_ROOT/log/$APP_NAME-$APP_ENV"
25
+ DAEMON_OPTS="-p <%= app.port %> -b 0.0.0.0 -e $APP_ENV -d"
26
+
27
+ CMD="$SET_PATH; $DAEMON $DAEMON_OPTS"
28
+
29
+ cd $APP_ROOT || exit 1
30
+
31
+ sig () {
32
+ test -s "$PID" && kill -$1 `cat $PID`
33
+ }
34
+
35
+ oldsig () {
36
+ test -s $OLD_PID && kill -$1 `cat $OLD_PID`
37
+ }
38
+
39
+ case ${1-help} in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ su - $USER -c "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig QUIT #&& echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ su - $USER -c "$CMD"
56
+ ;;
57
+
58
+ *)
59
+ echo >&2 "Usage: $0 <start|stop|restart|force-stop>"
60
+ exit 1
61
+ ;;
62
+ esac
63
+
64
+ exit 0
@@ -0,0 +1,55 @@
1
+ #map $http_upgrade $connection_upgrade {
2
+ # default upgrade;
3
+ # '' close;
4
+ #}
5
+
6
+ #upstream websocket {
7
+ # server localhost:<%= app.port %>;
8
+ #}
9
+
10
+ #server {
11
+ # listen 8020;
12
+ # location / {
13
+ # proxy_pass http://websocket;
14
+ # proxy_http_version 1.1;
15
+ # proxy_set_header Upgrade $http_upgrade;
16
+ # proxy_set_header Connection $connection_upgrade;
17
+ # }
18
+ #}
19
+
20
+
21
+ server {
22
+ #listen *:80 default_server;
23
+ #server_name _;
24
+
25
+ listen 80;
26
+ server_name <%= app.server_name %>;
27
+ server_tokens off;
28
+
29
+ access_log /var/log/nginx/access.log;
30
+ error_log /var/log/nginx/error.log;
31
+
32
+
33
+ location <%= app.mount_path %> {
34
+ proxy_pass http://localhost:<%= app.port %>;
35
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
36
+ proxy_set_header Host $http_host;
37
+ proxy_redirect off;
38
+ }
39
+
40
+
41
+ # location ~ ^<%= app.root_path %>(assets|system)/ {
42
+ # root <%= app.root %>/public;
43
+ # expires 1y;
44
+ # add_header Cache-Control public;
45
+ # gzip_static on;
46
+ # add_header ETag "";
47
+ # break;
48
+ # }
49
+
50
+
51
+ # location ~ ^/(robots\.txt|favicon\.ico|.*\.html).*$ {
52
+ # root <%= app.root %>/public;
53
+ # }
54
+
55
+ }
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixingthenet-installer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Fixingthenet command line installer.
42
+ email:
43
+ - peter.schrammel@gmx.de
44
+ executables:
45
+ - ftn
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/ftn
56
+ - fixingthenet-installer.gemspec
57
+ - lib/fixingthenet/installer.rb
58
+ - lib/fixingthenet/installer/app.rb
59
+ - lib/fixingthenet/installer/command.rb
60
+ - lib/fixingthenet/installer/install_command.rb
61
+ - lib/fixingthenet/installer/uninstall_command.rb
62
+ - lib/fixingthenet/installer/version.rb
63
+ - templates/initd.conf.erb
64
+ - templates/nginx_app.conf.erb
65
+ homepage: https://github.com/fixingthenet/fixingthenet-installer
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.2.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Command line tools to install and uninstall ftn apps on the fixingthenet
89
+ platform.
90
+ test_files: []