propro 0.1.0 → 0.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: 44863eaac48989c262ccfa894aa983713c25a701
4
- data.tar.gz: 36b7c970ff5ac22f0fde17b9f857d885fe66b499
3
+ metadata.gz: 6bb594745fd646bd208e8c8c322c8072b20f2cf1
4
+ data.tar.gz: a490d0308d9525e9b9581d0921d1dfb011979706
5
5
  SHA512:
6
- metadata.gz: ea73acabe73a73e7b7efaa4929be2c598b050b4197400f0653403c63cce4d66b8dcc9fb090eb382330f9ac092d7764839058630cb69b38ee640c963cc02192fb
7
- data.tar.gz: ef97898a9e82f7e48c1a75fbc9fce979e0bf2b4b312c4124cd3be6f8cacc6c09f4b695c1c75d42ee38427276fa22a39a20fc42a3583b2672422a8148f7f5ce05
6
+ metadata.gz: bbb1f187a215514bdd86eb28d36b8bf1054c0524d2de3dff5ceabd86ee730839bbf5f38abc99eeb4db22972c92f9f20846bf7a60551250322cc64e0fc52f2f5c
7
+ data.tar.gz: 22a73690ae5a412eb51bcd5347ab473460a868ee6634d5e5c29e6b332442f4704bbcc4cf4fe1b4187299b3001f678432504e66acdf32e26feddc6582a7f14029
data/README.md CHANGED
@@ -14,6 +14,7 @@ supports my personal use-cases.
14
14
  ### Creating A .propro Script
15
15
 
16
16
  ```sh
17
+ gem install propro
17
18
  propro init -t vagrant
18
19
  ```
19
20
 
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ function app-monit-install {
3
+ install-packages monit
4
+ }
5
+
6
+ function app-monit-logrotate {
7
+ announce "Create logrotate for Monit"
8
+ tee /etc/logrotate.d/monit <<EOT
9
+ /var/log/monit.log {
10
+ rotate 4
11
+ weekly
12
+ minsize 1M
13
+ missingok
14
+ create 640 root adm
15
+ notifempty
16
+ compress
17
+ delaycompress
18
+ postrotate
19
+ invoke-rc.d monit reload > /dev/null
20
+ endscript
21
+ }
22
+ EOT
23
+ }
24
+
25
+ function app-monit-configure {
26
+ mv /etc/monit/monitrc /etc/monit/monitrc.defaults
27
+ touch /etc/monit/monitrc
28
+ tee "/etc/monit/monitrc" << EOT
29
+ # copy into /etc/monit/monitrc
30
+ # set ownership to root:root
31
+ # set permissions to 600
32
+ set daemon 60
33
+ set logfile syslog facility log_daemon
34
+ set mailserver localhost
35
+ #set alert admin@domain.com
36
+
37
+ set httpd port 2812
38
+
39
+ allow localhost
40
+ allow admin:monit
41
+
42
+ include /etc/monit/conf.d/*
43
+ EOT
44
+ }
45
+
46
+ function provision-app-monit {
47
+ section "Monit"
48
+ app-monit-install
49
+ app-monit-configure
50
+ app-monit-logrotate
51
+ }
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # requires nginx.sh
3
+ # requires app.sh
4
+ # requires app/unicorn.sh
5
+ export APP_UNICORN_NGINX_ACCESS_LOG_FILE_NAME="access.log" # @specify
6
+ export APP_UNICORN_NGINX_ERROR_LOG_FILE_NAME="error.log" # @specify
7
+ export APP_UNICORN_UPSTREAM_PORT=4000 #@specify
8
+ APP_UNICORN_NGINX_ACCESS_LOG_FILE="$NGINX_LOG_DIR/$APP_UNICORN_NGINX_ACCESS_LOG_FILE_NAME"
9
+ APP_UNICORN_NGINX_ERROR_LOG_FILE="$NGINX_LOG_DIR/$APP_UNICORN_NGINX_ERROR_LOG_FILE_NAME"
10
+
11
+ function app-unicorn-monit-install {
12
+ tee "/etc/monit/conf.d/$APP_DOMAIN.conf" <<EOT
13
+ check process unicorn_app
14
+ with pidfile $(get-app-unicorn-pid-file)
15
+ group unicorn
16
+ start program = "/etc/init.d/unicorn start" with timeout 100 seconds
17
+ stop program = "/etc/init.d/unicorn stop"
18
+ EOT
19
+ }
20
+ function provision-app-unicorn-monit {
21
+ announce "installing Unicorn Monit"
22
+ app-unicorn-monit-install
23
+ }
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # requires nginx.sh
3
+ # requires app.sh
4
+ # requires app/unicorn.sh
5
+ export APP_UNICORN_NGINX_ACCESS_LOG_FILE_NAME="access.log" # @specify
6
+ export APP_UNICORN_NGINX_ERROR_LOG_FILE_NAME="error.log" # @specify
7
+ export APP_UNICORN_UPSTREAM_PORT=4000 #@specify
8
+ APP_UNICORN_NGINX_ACCESS_LOG_FILE="$NGINX_LOG_DIR/$APP_UNICORN_NGINX_ACCESS_LOG_FILE_NAME"
9
+ APP_UNICORN_NGINX_ERROR_LOG_FILE="$NGINX_LOG_DIR/$APP_UNICORN_NGINX_ERROR_LOG_FILE_NAME"
10
+
11
+ function provision-app-unicorn-nginx {
12
+ tee "$NGINX_SITES_DIR/$APP_DOMAIN.conf" <<EOT
13
+ upstream $(get-app-id) {
14
+ server 127.0.0.1:$APP_UNICORN_UPSTREAM_PORT fail_timeout=0;
15
+ }
16
+
17
+ # Redirect www.$APP_DOMAIN => $APP_DOMAIN
18
+ server {
19
+ listen 80;
20
+ listen 443 ssl;
21
+ server_name www.$APP_DOMAIN;
22
+ return 301 \$scheme://$APP_DOMAIN\$request_uri;
23
+ }
24
+
25
+ server {
26
+ server_name $APP_DOMAIN;
27
+ root $(get-app-current-public-dir);
28
+
29
+ access_log $APP_UNICORN_NGINX_ACCESS_LOG_FILE combined;
30
+ error_log $APP_UNICORN_NGINX_ERROR_LOG_FILE notice;
31
+
32
+ location ~* \.(eot|ttf|woff)\$ {
33
+ add_header Access-Control-Allow-Origin *;
34
+ }
35
+
36
+ location ~ ^/(assets)/ {
37
+ root $(get-app-current-public-dir);
38
+ expires max;
39
+ add_header Cache-Control public;
40
+ gzip_static on;
41
+ }
42
+
43
+ try_files \$uri/index.html \$uri.html \$uri @rack_app;
44
+
45
+ location @rack_app {
46
+ proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
47
+ proxy_set_header Host \$http_host;
48
+ proxy_redirect off;
49
+ proxy_pass http://$(get-app-id);
50
+ }
51
+
52
+ error_page 500 502 503 504 /500.html;
53
+
54
+ location = /500.html {
55
+ root $(get-app-current-public-dir);
56
+ }
57
+ }
58
+ EOT
59
+ }
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env bash
2
+ export APP_UNICORN_CONFIG_DIR_RELATIVE="config/"
3
+ export APP_UNICORN_CONFIG_FILE_NAME="unicorn.rb" # @specify
4
+
5
+ APP_UNICORN_CONFIG_FILE_RELATIVE="$APP_UNICORN_CONFIG_DIR_RELATIVE/$APP_UNICORN_CONFIG_FILE_NAME"
6
+
7
+ function get-app-unicorn-app-root {
8
+ echo "$(get-app-current-dir)"
9
+ }
10
+
11
+ function get-app-unicorn-pid-file {
12
+ echo "$(get-app-unicorn-app-root)/log/unicorn.pid"
13
+ }
14
+
15
+ function app-unicorn-install {
16
+ announce "Create init.d for Unicorn"
17
+
18
+ tee /etc/init.d/unicorn <<EOT
19
+ #!/bin/sh
20
+ set -u
21
+ set -e
22
+
23
+ # copy this to /etc/init.d/unicorn
24
+ # set owner to root:root
25
+ # chmod a+x
26
+ # update-rc.d unicorn defaults
27
+ # adapted from http://gist.github.com/308216
28
+ APP_ROOT=$(get-app-unicorn-app-root)
29
+ PID=$(get-app-unicorn-pid-file)
30
+ OLD_PID="\$PID.oldbin"
31
+ ENV=$(get-app-env)
32
+ HOME=$(get-app-home)
33
+
34
+ cd \$APP_ROOT || exit 1
35
+
36
+ start_unicorn () {
37
+ su deploy -c "cd \${APP_ROOT} && bin/unicorn -E \${ENV} -D -o 127.0.0.1 -c \${APP_ROOT}/config/unicorn.rb \${APP_ROOT}/config.ru"
38
+ }
39
+
40
+ sig () {
41
+ test -s "\$PID" && kill -\$1 \`cat \$PID\`
42
+ }
43
+
44
+ oldsig () {
45
+ test -s \$OLD_PID && kill -\$1 \`cat \$OLD_PID\`
46
+ }
47
+
48
+
49
+ case \$1 in
50
+ start)
51
+ sig 0 && echo >&2 "Already running" && exit 0
52
+ start_unicorn
53
+ ;;
54
+ stop)
55
+ sig QUIT && exit 0
56
+ echo >&2 "Not running"
57
+ ;;
58
+ force-stop)
59
+ sig TERM && exit 0
60
+ echo >&2 "Not running"
61
+ ;;
62
+ restart|reload)
63
+ sig HUP && echo reloaded OK && exit 0
64
+ echo >&2 "Couldn't reload, starting unicorn instead"
65
+ start_unicorn
66
+ ;;
67
+ upgrade)
68
+ sig USR2 && exit 0
69
+ echo >&2 "Couldn't upgrade, starting unicorn instead"
70
+ start_unicorn
71
+ ;;
72
+ rotate)
73
+ sig USR1 && echo rotated logs OK && exit 0
74
+ echo >&2 "Couldn't rotate logs" && exit 1
75
+ ;;
76
+ *)
77
+ echo >&2 "Usage: \$0 <start|stop|restart|upgrade|rotate|force-stop>"
78
+ exit 1
79
+ ;;
80
+ esac
81
+
82
+ EOT
83
+
84
+ chmod +x /etc/init.d/unicorn
85
+
86
+ }
87
+
88
+ function app-unicorn-sudoers {
89
+ announce "Adding sudoers entries"
90
+ for event in start status stop reload restart upgrade rotate; do
91
+ tee -a /etc/sudoers.d/unicorn.entries <<EOT
92
+ $APP_USER ALL=NOPASSWD: /etc/init.d/unicorn $event
93
+ EOT
94
+ done
95
+ }
96
+
97
+ function app-unicorn-logrotate {
98
+ announce "Create logrotate for Unicorn"
99
+ tee /etc/logrotate.d/unicorn <<EOT
100
+ $(get-app-shared-dir)/log/*.log {
101
+ daily
102
+ missingok
103
+ rotate 90
104
+ compress
105
+ delaycompress
106
+ notifempty
107
+ dateext
108
+ create 640 deploy deploy
109
+ sharedscripts
110
+ postrotate
111
+ /etc/init.d/unicorn rotate
112
+ endscript
113
+ }
114
+ EOT
115
+ }
116
+
117
+ function provision-app-unicorn {
118
+ section "Unicorn"
119
+ app-unicorn-install
120
+ app-unicorn-sudoers
121
+ app-unicorn-logrotate
122
+ }
123
+
data/ext/bash/app.sh CHANGED
@@ -5,6 +5,7 @@ export APP_DOMAIN="" # @require
5
5
  export APP_AUTHORIZED_GITHUB_USERS="" # @require
6
6
  export APP_USER="deploy" # @specify
7
7
  export APPS_DIR="/sites" # @specify
8
+ export APP_ENV="production" # @specify
8
9
 
9
10
  function get-app-dir {
10
11
  echo "$APPS_DIR/$APP_DOMAIN"
@@ -42,6 +43,18 @@ function get-app-current-public-dir {
42
43
  echo "$(get-app-current-dir)/public"
43
44
  }
44
45
 
46
+ function get-app-user {
47
+ echo $APP_USER
48
+ }
49
+
50
+ function get-app-home {
51
+ echo "/home/$(get-app-user)"
52
+ }
53
+
54
+ function get-app-env {
55
+ echo $APP_ENV
56
+ }
57
+
45
58
  function get-app-id {
46
59
  path-to-id $APP_DOMAIN
47
60
  }
data/ext/bash/lib/rvm.sh CHANGED
@@ -2,6 +2,7 @@
2
2
  # requires app.sh
3
3
  export RVM_CHANNEL="stable"
4
4
  RVM_REQUIRED_PACKAGES="curl gawk g++ gcc make libc6-dev libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev"
5
+ RVM_DEFAULT_GEMS="bundler" #@specify
5
6
 
6
7
  # $1 unix user
7
8
  # $2 ruby version
@@ -18,4 +19,7 @@ function rvm-install-for-user {
18
19
 
19
20
  announce "Set Ruby $2 as default for user $1"
20
21
  su - $1 -c "rvm --default use $2"
22
+
23
+ announce "Install default gems"
24
+ su - $1 -c "gem install $RVM_DEFAULT_GEMS"
21
25
  }
@@ -16,9 +16,13 @@ module Propro
16
16
  app/pg
17
17
  app/nginx
18
18
  app/sidekiq
19
+ app/monit
19
20
  app/puma
20
21
  app/puma/nginx
21
22
  app/node
23
+ app/unicorn
24
+ app/unicorn/nginx
25
+ app/unicorn/monit
22
26
  db/pg
23
27
  db/redis
24
28
  vagrant
data/lib/propro/source.rb CHANGED
@@ -66,8 +66,6 @@ module Propro
66
66
 
67
67
  def load_line(line)
68
68
  case
69
- when line.start_with?(COMMENT_BEGIN)
70
- # skip comments
71
69
  when line.start_with?(EXPORT_BEGIN)
72
70
  # collect exported variables from bash modules
73
71
  @exports << Export.parse(line)
@@ -1,3 +1,3 @@
1
1
  module Propro
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Nielsen
@@ -97,6 +97,7 @@ files:
97
97
  - examples/vagrant.propro
98
98
  - examples/vps_webserver.propro
99
99
  - ext/bash/app.sh
100
+ - ext/bash/app/monit.sh
100
101
  - ext/bash/app/nginx.sh
101
102
  - ext/bash/app/node.sh
102
103
  - ext/bash/app/pg.sh
@@ -104,6 +105,9 @@ files:
104
105
  - ext/bash/app/puma/nginx.sh
105
106
  - ext/bash/app/rvm.sh
106
107
  - ext/bash/app/sidekiq.sh
108
+ - ext/bash/app/unicorn.sh
109
+ - ext/bash/app/unicorn/monit.sh
110
+ - ext/bash/app/unicorn/nginx.sh
107
111
  - ext/bash/db/pg.sh
108
112
  - ext/bash/db/redis.sh
109
113
  - ext/bash/lib/extras.sh