oysters 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 652098cb586a45b1f5c294fb69ec1afe7684e265
4
- data.tar.gz: 9d97d41d3fa08dfd38fb3b1ba11f78260513a89a
3
+ metadata.gz: 77e2c07fed3028aa5219a5c9ed553f328d22c81e
4
+ data.tar.gz: 13d20eb912f5f23a9dc82e08187a397b91d994e4
5
5
  SHA512:
6
- metadata.gz: 9de0fb6195f597dd31d312eb50268cd33fed011f8726c967f12a386eba63035ecd1dfde0854d8fefbb4d11458bb4a55da26ea66f3e35cf5c8933fce65c51cc1d
7
- data.tar.gz: 7f96b02e513210ecc9a131b38db8bb8f5ee3589fcb9e75faac7424c12a5b8b6600eab10e631470100f53b21b2f5a7ab89d829331886ddd2bf0b3bf1c8576c7e5
6
+ metadata.gz: 7af8777078870368a508c2256269b98555251818062fd511908ce81a5a59ec8f9afa83bfc32dbbde04ad3cd0ada105aee60fd62c74de8fdc6f5796b0bd79490d
7
+ data.tar.gz: 4a74dc3ce4c7e0e17c7e738faff1cfc4302b4ff16f54ba3220c70de45090e60ed121f0664030fd3dd33416ed6da4486c6d2bf283d7602d08b49afc86e94a0643
data/README.md CHANGED
@@ -1,4 +1,15 @@
1
1
  # Oysters
2
+ Oysters is a set of capistrano tasks that allow users to manage application daemons like Resque Scheduler, KEWatcher(resque-sliders), Unicorn.
3
+
4
+ It allows to:
5
+
6
+ 1. Install/Uninstall init.d scripts for daemons.
7
+
8
+ 2. Start/Stop/Restart daemons
9
+
10
+ Oysters is compatible with Capistrano 2.x.
11
+
12
+
2
13
 
3
14
  ## Installation
4
15
 
@@ -9,16 +20,97 @@ gem 'oysters'
9
20
  ```
10
21
 
11
22
  And then execute:
23
+ ```
24
+ $ bundle
25
+ ```
26
+ Or install it yourself as:
27
+ ```
28
+ $ gem install oysters
29
+ ```
30
+ ## Unified Oysters Usage
12
31
 
13
- $ bundle
32
+ Require 'oysters/unified_oysters' in your deploy.rb:
33
+ ```
34
+ require 'oysters/unified_oysters'
35
+ ```
36
+ ### init.d scripts installation
14
37
 
15
- Or install it yourself as:
38
+ Set all needed configuration variables in your capistrano environment configs. See 'lib/oysters/unified/templates/app_sysconfig.sh.erb' for a list of all variables.:
39
+
40
+ ```
41
+ set :app_user, 'svc_iris'
42
+ set :dynamic_schedule, true
43
+ set :scheduler_background, true
44
+ set :scheduler_verbose, 1
45
+ set :kewatcher_max_workers, 20
46
+ set :kewacther_redis_config, "#{current_path}/config/redis.yml"
47
+ set :kewatcher_verbose, '-vv'
48
+ set :unicorn_config_path, "#{current_path}/config/unicorn/unicorn.rb"
49
+ ```
50
+
51
+ Install application sysconfig, used by init.d scripts. File '/etc/sysconfig/deployed_application' will be created:
52
+ ```
53
+ cap <environment> oysters:unified:initd:sysconfig:install
54
+ ```
55
+
56
+ Install necessary init.d scripts:
57
+ ```
58
+ cap <environment> oysters:unified:initd:kewatcher:install
59
+ cap <environment> oysters:unified:initd:resque_scheduler:install
60
+ cap <environment> oysters:unified:initd:unicorn:install
61
+ ```
62
+ You can install sysconfig and all init.d scripts simultaneously via 'install_all' task:
63
+ ```
64
+ cap <environment> oysters:unified:initd:install_all
65
+ ```
66
+ init.d scripts use ~/.bash_profile to load rvm. File example:
67
+ ```
68
+ # .bash_profile
69
+
70
+ # Get the aliases and functions
71
+ if [ -f ~/.bashrc ]; then
72
+ . ~/.bashrc
73
+ fi
74
+
75
+ # User specific environment and startup programs
76
+
77
+ PATH=$PATH:$HOME/bin
78
+
79
+ export PATH
80
+
81
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
82
+ ```
16
83
 
17
- $ gem install oysters
84
+ NOTE: You need sudo access to install init.d scripts and sysconfig
18
85
 
19
- ## Usage
86
+ ### Managing daemons
87
+
88
+ You can manage daemons using next tasks:
89
+ ```
90
+ cap <environment> oysters:unified:kewatcher:restart
91
+ cap <environment> oysters:unified:kewatcher:start
92
+ cap <environment> oysters:unified:kewatcher:stop
93
+
94
+ cap <environment> oysters:unified:resque_scheduler:restart
95
+ cap <environment> oysters:unified:resque_scheduler:start
96
+ cap <environment> oysters:unified:resque_scheduler:stop
97
+
98
+ cap <environment> oysters:unified:unicorn:restart
99
+ cap <environment> oysters:unified:unicorn:start
100
+ cap <environment> oysters:unified:unicorn:stop
101
+ ```
102
+ ### Removing scripts
103
+
104
+ Individual init.d script:
105
+ ```
106
+ cap <environment> oysters:unified:initd:unicorn:uninstall
107
+ ```
108
+ All scripts and sysconfig:
109
+ ```
110
+ cap <environment> oysters:unified:initd:uninstall_all
111
+ ```
20
112
 
21
- TODO: Write usage instructions here
113
+ NOTE: You need sudo access to uninstall init.d scripts and sysconfig
22
114
 
23
115
  ## Development
24
116
 
@@ -0,0 +1,21 @@
1
+ require 'oysters'
2
+ require 'erb'
3
+
4
+ Oysters.with_configuration do
5
+ namespace :unified do
6
+ # This tasks are used to start/stop/restart next application daemons:
7
+ # - KEWatcher from resque-sliders gem
8
+ # - Resque Scheduler
9
+ # - Unicorn
10
+ [:kewatcher, :resque_scheduler, :unicorn].each do |program|
11
+ namespace "#{program}" do
12
+ [:stop, :start, :restart].each do |action|
13
+ desc "#{action.to_s.capitalize} #{program.to_s.capitalize}"
14
+ task action do
15
+ run "/etc/init.d/#{application}_#{program} #{action.to_s}", pty: true
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ require 'oysters'
2
+ require 'erb'
3
+
4
+ Oysters.with_configuration do
5
+ namespace :unified do
6
+ namespace :initd do
7
+ # This tasks install/uninstall initd scripts for:
8
+ # - KEWatcher from resque-sliders gem
9
+ # - Resque Scheduler
10
+ # - Unicorn
11
+ [:kewatcher, :resque_scheduler, :unicorn].each do |program|
12
+ namespace "#{program}" do
13
+ #Run this task as a sudo user!
14
+ desc "Install #{program}"
15
+ task :install, roles: :app do
16
+ tmp_config_path = "/tmp/#{program}_initd_script.sh"
17
+ # Remove old tmp config if present
18
+ run "sudo rm -f #{tmp_config_path}", pty: true, shell: :bash
19
+
20
+ config = File.read(File.expand_path("../scripts/#{program}_initd_script.sh", __FILE__))
21
+ put config, tmp_config_path, shell: :bash
22
+
23
+ run "sudo cp #{tmp_config_path} /etc/init.d/#{application}_#{program}", pty: true, shell: :bash
24
+ run "sudo chmod +x /etc/init.d/#{application}_#{program}", pty: true, shell: :bash
25
+ run "sudo chkconfig --add #{application}_#{program}", pty: true, shell: :bash
26
+ run "rm -f #{tmp_config_path}", shell: :bash
27
+ end
28
+
29
+ #Run this task as a sudo user!
30
+ desc "Remove #{program} init.d script"
31
+ task :uninstall, roles: :app do
32
+ run "sudo chkconfig --del #{application}_#{program}", pty: true, shell: :bash
33
+ run "sudo rm -f /etc/init.d/#{application}_#{program}", pty: true, shell: :bash
34
+ end
35
+ end
36
+ end
37
+
38
+ # This tasks install/uninstall sysconfig that contains configuration information for:
39
+ # - KEWatcher from resque-sliders gem
40
+ # - Resque Scheduler
41
+ # - Unicorn
42
+ namespace :sysconfig do
43
+ #Run this task as a sudo user!
44
+ desc 'Generate sysconfig used by init.d scripts and put it into /etc/sysconfig'
45
+ task :install, roles: :app do
46
+ tmp_config_path = "/tmp/deployed_application_sysconfig.sh"
47
+ # Remove old tmp config if present
48
+ run "sudo rm -f #{tmp_config_path}", pty: true, shell: :bash
49
+
50
+ location = File.expand_path('../templates/app_sysconfig.sh.erb', __FILE__)
51
+ config = ERB.new(File.read(location))
52
+ put config.result(binding), tmp_config_path, shell: :bash
53
+
54
+ run "sudo cp #{tmp_config_path} /etc/sysconfig/deployed_application", pty: true, shell: :bash
55
+ run "rm -f #{tmp_config_path}", shell: :bash
56
+ end
57
+
58
+ #Run this task as a sudo user!
59
+ desc 'Remove sysconfig'
60
+ task :uninstall, roles: :app do
61
+ run "sudo rm -f /etc/sysconfig/deployed_application", pty: true, shell: :bash
62
+ end
63
+ end
64
+
65
+ #Run this task as a sudo user!
66
+ desc "Install all initd scripts(KEWatcher, Unicorn, Scheduler)"
67
+ task :install_all, roles: :app do
68
+ unified.initd.sysconfig.install
69
+ unified.initd.kewatcher.install
70
+ unified.initd.resque_scheduler.install
71
+ unified.initd.unicorn.install
72
+ end
73
+
74
+ #Run this task as a sudo user!
75
+ desc "Uninstall all initd scripts(KEWatcher, Unicorn, Scheduler)"
76
+ task :uninstall_all, roles: :app do
77
+ unified.initd.sysconfig.uninstall
78
+ unified.initd.kewatcher.uninstall
79
+ unified.initd.resque_scheduler.uninstall
80
+ unified.initd.unicorn.uninstall
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,74 @@
1
+ #!/bin/sh
2
+ # chkconfig: 345 99 55
3
+ # description: script to start kewatcher
4
+ # /etc/init.d/[application]_kewatcher
5
+
6
+ # source functions library
7
+ . /etc/rc.d/init.d/functions
8
+
9
+ # source application params
10
+ . /etc/sysconfig/deployed_application
11
+
12
+ start() {
13
+ local program
14
+ local options
15
+
16
+ echo "Starting KEWatcher"
17
+ if [ -e $KEWATCHER_PIDFILE ] && kill -0 `cat $KEWATCHER_PIDFILE` > /dev/null 2>&1; then
18
+ echo "KEWatcher is already Running"
19
+ echo_success
20
+ return 0
21
+ fi
22
+
23
+ options="-m $KEWATCHER_MAX_WORKERS -c $KEWATCHER_REDIS_CONFIG -p $KEWATCHER_PIDFILE $KEWATCHER_VERBOSE"
24
+
25
+ su $APP_USER -c "cd $ROOT_PATH; source /home/$APP_USER/.bash_profile; RAILS_ENV=$RAILS_ENV nohup bundle exec $ROOT_PATH/bin/kewatcher $options 2>&1 >> $KEWATCHER_LOGFILE &"
26
+ RETVAL=$?
27
+
28
+ sleep 5
29
+
30
+ if [ $RETVAL -eq 0 ]; then
31
+ echo_success
32
+ else
33
+ echo_failure
34
+ fi
35
+ echo
36
+ }
37
+
38
+ stop() {
39
+ echo "Stopping KEWatcher"
40
+
41
+ if [ -f $KEWATCHER_PIDFILE ]; then
42
+ kill -s QUIT $(cat $KEWATCHER_PIDFILE)
43
+ RETVAL=$?
44
+ sleep 10
45
+ else
46
+ RETVAL=1
47
+ fi
48
+
49
+ echo "Killing stuck workers"
50
+ kill -s KILL `pgrep -xf "[r]esque-[0-9]+.*" | xargs` > /dev/null 2>&1
51
+
52
+ if [ $RETVAL -eq 0 ]; then
53
+ echo_success
54
+ rm -f $KEWATCHER_PIDFILE
55
+ else
56
+ echo "Resque KEWatcher is not running"
57
+ echo_failure
58
+ fi
59
+ }
60
+
61
+ case "$1" in
62
+ start) start ;;
63
+ stop) stop ;;
64
+ restart)
65
+ echo "Restarting Resque KEWatcher ... "
66
+ stop
67
+ start
68
+ ;;
69
+ *)
70
+ echo "Usage: $0 {start|stop|restart}"
71
+ exit 1
72
+ esac
73
+
74
+ exit $?
@@ -0,0 +1,71 @@
1
+ #!/bin/sh
2
+ # chkconfig: 345 99 55
3
+ # description: script to start resque scheduler
4
+ # /etc/init.d/[application]_resque_scheduler
5
+
6
+ # source functions library
7
+ . /etc/rc.d/init.d/functions
8
+
9
+ # source application params
10
+ . /etc/sysconfig/deployed_application
11
+
12
+ start() {
13
+ local program
14
+ local options
15
+
16
+ cd $ROOT_PATH
17
+
18
+ echo "Starting Resque Scheduler"
19
+ options="RAILS_ENV=$RAILS_ENV VERBOSE=$SCHEDULER_VERBOSE BACKGROUND=$BACKGROUND DYNAMIC_SCHEDULE=$DYNAMIC_SCHEDULE PIDFILE=$SCHEDULER_PIDFILE"
20
+ program="source /home/$APP_USER/.bash_profile; bundle exec rake resque:scheduler $options 2>&1 >> $SCHEDULER_LOGFILE"
21
+
22
+ if [[ $APP_USER == $USER ]]
23
+ then
24
+ daemon --pidfile=$SCHEDULER_PIDFILE $program
25
+ else
26
+ daemon --user $APP_USER --pidfile=$SCHEDULER_PIDFILE $program
27
+ fi
28
+ RETVAL=$?
29
+
30
+ if [ $RETVAL -eq 0 ]; then
31
+ echo_success
32
+ else
33
+ echo_failure
34
+ fi
35
+ echo
36
+ }
37
+
38
+ stop() {
39
+ echo "Stopping Resque Scheduler"
40
+
41
+ if [ -f $SCHEDULER_PIDFILE ]; then
42
+ kill -s QUIT $(cat $SCHEDULER_PIDFILE)
43
+ RETVAL=$?
44
+ else
45
+ RETVAL=1
46
+ fi
47
+
48
+ if [ $RETVAL -eq 0 ]; then
49
+ echo_success
50
+ rm -f $SCHEDULER_PIDFILE
51
+ else
52
+ echo "Resque Scheduler is not running"
53
+ echo_failure
54
+ fi
55
+ }
56
+
57
+ case "$1" in
58
+ start) start ;;
59
+ stop) stop ;;
60
+ restart)
61
+ echo "Restarting Resque scheduler ... "
62
+ stop
63
+ sleep 2
64
+ start
65
+ ;;
66
+ *)
67
+ echo "Usage: $0 {start|stop|restart}"
68
+ exit 1
69
+ esac
70
+
71
+ exit $?
@@ -0,0 +1,73 @@
1
+ #!/bin/sh
2
+ # chkconfig: 345 99 55
3
+ # description: script to start unicorn
4
+ # /etc/init.d/[application]_unicorn
5
+
6
+ # source functions library
7
+ . /etc/rc.d/init.d/functions
8
+
9
+ # source application params
10
+ . /etc/sysconfig/deployed_application
11
+
12
+ start() {
13
+ local program
14
+ local options
15
+ local env_vars
16
+
17
+ cd $ROOT_PATH
18
+
19
+ echo "Starting Unicorn"
20
+ env_vars="RAILS_ENV=$RAILS_ENV BUNDLE_GEMFILE=$BUNDLE_GEMFILE"
21
+ options="-c $UNICORN_CONFIG -E $RAILS_ENV -D "
22
+ program="source /home/$APP_USER/.bash_profile; $env_vars bundle exec unicorn $options"
23
+
24
+ if [[ $APP_USER == $USER ]]
25
+ then
26
+ daemon --pidfile=$UNICORN_PIDFILE $program
27
+ else
28
+ daemon --user $APP_USER --pidfile=$UNICORN_PIDFILE $program
29
+ fi
30
+ RETVAL=$?
31
+
32
+ if [ $RETVAL -eq 0 ]; then
33
+ echo_success
34
+ else
35
+ echo_failure
36
+ fi
37
+ echo
38
+ }
39
+
40
+ stop() {
41
+ echo "Stopping Unicorn"
42
+
43
+ if [ -f $UNICORN_PIDFILE ]; then
44
+ kill -s QUIT $(cat $UNICORN_PIDFILE)
45
+ RETVAL=$?
46
+ else
47
+ RETVAL=1
48
+ fi
49
+
50
+ if [ $RETVAL -eq 0 ]; then
51
+ echo_success
52
+ rm -f $UNICORN_PIDFILE
53
+ else
54
+ echo "Unicorn is not running"
55
+ echo_failure
56
+ fi
57
+ }
58
+
59
+ case "$1" in
60
+ start) start ;;
61
+ stop) stop ;;
62
+ restart)
63
+ echo "Restarting Unicorn ... "
64
+ stop
65
+ sleep 5
66
+ start
67
+ ;;
68
+ *)
69
+ echo "Usage: $0 {start|stop|restart}"
70
+ exit 1
71
+ esac
72
+
73
+ exit $?
@@ -0,0 +1,28 @@
1
+ # /etc/sysconfig/deployed_application
2
+ # Configuration file for application services: Unicorn, KEWatcher and Resque Scheduler.
3
+
4
+ #Main params
5
+ RAILS_ENV=<%= rails_env %> # (development, staging, production)
6
+ APP_USER=<%= app_user %> # user that will run daemons
7
+
8
+ ROOT_PATH=<%= current_path %> # path to app directory
9
+ SHARED_PATH=<%= shared_path %> # path to shared directory
10
+
11
+ #Scheduler params
12
+ SCHEDULER_LOGFILE=$SHARED_PATH/log/resque_scheduler.log
13
+ SCHEDULER_PIDFILE=$SHARED_PATH/pids/scheduler.pid
14
+ DYNAMIC_SCHEDULE=<%= dynamic_schedule %> # (true,false)
15
+ BACKGROUND=<%= scheduler_background %> # (true,false)
16
+ SCHEDULER_VERBOSE=<%= scheduler_verbose %> # (1,0)
17
+
18
+ #KEWatcher params
19
+ KEWATCHER_LOGFILE=$SHARED_PATH/log/kewatcher.log
20
+ KEWATCHER_PIDFILE=$SHARED_PATH/pids/kewatcher.pid
21
+ KEWATCHER_REDIS_CONFIG=<%= kewacther_redis_config %> # path to redis config
22
+ KEWATCHER_MAX_WORKERS=<%= kewatcher_max_workers %> # max number of workers (integer)
23
+ KEWATCHER_VERBOSE=<%= kewatcher_verbose %> # log verbosity (-v,-vv)
24
+
25
+ #Unicorn params
26
+ UNICORN_CONFIG=<%= unicorn_config_path %>
27
+ UNICORN_PIDFILE=$SHARED_PATH/pids/unicorn.pid
28
+ BUNDLE_GEMFILE=$ROOT_PATH/Gemfile
@@ -0,0 +1,5 @@
1
+ require 'oysters'
2
+
3
+ Dir[File.dirname(__FILE__) + '/unified/*.rb'].each do |f|
4
+ require f
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Oysters
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oysters
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Samoilov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,13 @@ files:
81
81
  - lib/oysters/templates/kewatcher_init.sh.erb
82
82
  - lib/oysters/templates/logrotate_config.erb
83
83
  - lib/oysters/templates/unicorn_init.sh.erb
84
+ - lib/oysters/unified/application_control.rb
85
+ - lib/oysters/unified/initd.rb
86
+ - lib/oysters/unified/scripts/kewatcher_initd_script.sh
87
+ - lib/oysters/unified/scripts/resque_scheduler_initd_script.sh
88
+ - lib/oysters/unified/scripts/unicorn_initd_script.sh
89
+ - lib/oysters/unified/templates/app_sysconfig.sh.erb
90
+ - lib/oysters/unified_oysters.rb
84
91
  - lib/oysters/version.rb
85
92
  - oysters.gemspec
86
93
  homepage: https://github.com/rsamoilov/oysters