o2webappizer 0.1.7 → 0.1.8

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -0
  3. data/lib/o2webappizer/app_builder.rb +45 -13
  4. data/lib/o2webappizer/generators/app_generator.rb +1 -0
  5. data/lib/o2webappizer/version.rb +1 -1
  6. data/o2webappizer.gemspec +1 -1
  7. data/templates/.gitignore.tt +1 -0
  8. data/templates/Capfile +19 -0
  9. data/templates/Gemfile.tt +7 -4
  10. data/templates/Vagrantfile.tt +74 -0
  11. data/templates/app/assets/javascripts/application.js.coffee +1 -1
  12. data/templates/app/views/spree/shared/_head.html.erb +2 -2
  13. data/templates/config/Backup/config.rb +124 -0
  14. data/templates/config/Backup/models/db_backup.rb.tt +91 -0
  15. data/templates/config/deploy.rb.tt +92 -0
  16. data/templates/config/deploy/production.rb +66 -0
  17. data/templates/config/deploy/staging.rb +66 -0
  18. data/templates/config/deploy/vagrant.rb +66 -0
  19. data/templates/config/initializers_tt/mail_interceptor.rb +21 -0
  20. data/templates/config/nginx.app.conf.erb +82 -0
  21. data/templates/config/nginx.conf.erb +102 -0
  22. data/templates/config/routes.rb.tt +3 -0
  23. data/templates/config/secrets.yml.tt +10 -0
  24. data/templates/config/sunzi/files/authorized_keys +1 -0
  25. data/templates/config/sunzi/files/sudoers +1 -0
  26. data/templates/config/sunzi/install.sh +14 -0
  27. data/templates/config/sunzi/recipes/libraries.sh +24 -0
  28. data/templates/config/sunzi/recipes/mysql.sh +19 -0
  29. data/templates/config/sunzi/recipes/nodejs.sh +6 -0
  30. data/templates/config/sunzi/recipes/passenger.sh +19 -0
  31. data/templates/config/sunzi/recipes/postgres.sh +14 -0
  32. data/templates/config/sunzi/recipes/ruby.sh +28 -0
  33. data/templates/config/sunzi/recipes/setup.sh +11 -0
  34. data/templates/config/sunzi/recipes/sunzi.sh +99 -0
  35. data/templates/config/sunzi/recipes/sysstat.sh +8 -0
  36. data/templates/config/sunzi/recipes/update.sh +2 -0
  37. data/templates/config/sunzi/recipes/user.sh +23 -0
  38. data/templates/config/sunzi/roles/admin.sh +20 -0
  39. data/templates/config/sunzi/roles/deployer.sh +7 -0
  40. data/templates/config/sunzi/roles/updater.sh +5 -0
  41. data/templates/config/sunzi/sunzi.yml.tt +26 -0
  42. data/templates/db/migrate/20160114191411_add_mail_interceptors_to_settings.rb +12 -0
  43. data/templates/lib/middleware/turbo_dev.rb +40 -0
  44. data/templates/lib/tasks/app.rake +3 -0
  45. data/templates/lib/tasks/db.rake +9 -0
  46. data/templates/schedule.rb +47 -0
  47. data/templates/vendor/assets/javascripts/modernizr.custom.js +3 -0
  48. metadata +37 -10
  49. data/templates/vendor/assets/javascripts/modernizr.js +0 -3
@@ -0,0 +1,102 @@
1
+ user <%= fetch(:deployer_name) %>;
2
+ worker_processes <%= fetch(:nginx_workers) %>;
3
+ pid /run/nginx.pid;
4
+
5
+ events {
6
+ worker_connections 768;
7
+ # multi_accept on;
8
+ }
9
+
10
+ http {
11
+
12
+ ##
13
+ # Basic Settings
14
+ ##
15
+
16
+ sendfile on;
17
+ tcp_nopush on;
18
+ tcp_nodelay on;
19
+ keepalive_timeout 65;
20
+ types_hash_max_size 2048;
21
+ # server_tokens off;
22
+
23
+ # server_names_hash_bucket_size 64;
24
+ # server_name_in_redirect off;
25
+
26
+ include /etc/nginx/mime.types;
27
+ default_type application/octet-stream;
28
+
29
+ ##
30
+ # SSL Settings
31
+ ##
32
+
33
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
34
+ ssl_prefer_server_ciphers on;
35
+
36
+ ##
37
+ # Logging Settings
38
+ ##
39
+
40
+ access_log /var/log/nginx/access.log;
41
+ error_log /var/log/nginx/error.log;
42
+
43
+ ##
44
+ # Gzip Settings
45
+ ##
46
+
47
+ gzip on;
48
+ gzip_disable "msie6";
49
+
50
+ gzip_vary on;
51
+ gzip_proxied any;
52
+ gzip_comp_level 6;
53
+ gzip_buffers 16 8k;
54
+ gzip_http_version 1.1;
55
+ gzip_types
56
+ text/plain
57
+ text/css
58
+ text/xml
59
+ text/javascript
60
+ application/json
61
+ application/javascript
62
+ application/xml
63
+ application/xml+rss;
64
+
65
+ ##
66
+ # Phusion Passenger config
67
+ ##
68
+ # Uncomment it if you installed passenger or passenger-enterprise
69
+ ##
70
+
71
+ passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
72
+ passenger_ruby /home/<%= fetch(:deployer_name) %>/.rbenv/shims/ruby;
73
+
74
+ ##
75
+ # Virtual Host Configs
76
+ ##
77
+
78
+ include /etc/nginx/conf.d/*.conf;
79
+ include /etc/nginx/sites-enabled/*;
80
+ }
81
+
82
+
83
+ #mail {
84
+ # # See sample authentication script at:
85
+ # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
86
+ #
87
+ # # auth_http localhost/auth.php;
88
+ # # pop3_capabilities "TOP" "USER";
89
+ # # imap_capabilities "IMAP4rev1" "UIDPLUS";
90
+ #
91
+ # server {
92
+ # listen localhost:110;
93
+ # protocol pop3;
94
+ # proxy on;
95
+ # }
96
+ #
97
+ # server {
98
+ # listen localhost:143;
99
+ # protocol imap;
100
+ # proxy on;
101
+ # }
102
+ #}
@@ -1,4 +1,7 @@
1
1
  Rails.application.routes.draw do
2
+ if Rails.env.development?
3
+ mount LetterOpenerWeb::Engine, at: "/letter_opener"
4
+ end
2
5
  mount Rich::Engine => 'rich', as: 'rich'
3
6
  mount RailsAdmin::Engine => 'admin/dashboard', as: 'rails_admin'
4
7
 
@@ -12,17 +12,27 @@
12
12
 
13
13
  development:
14
14
  secret_key_base: <%= app_secret %>
15
+ deployer_password: <%= SecureRandom.hex %>
16
+ deployer_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD+AhnvJ1BMM0jFCAKSH+NCST+wpz2zwXySiBHN8tZ4kui3ozf//OeBnnGZMOFLurXrzAtll+EE5j+A/iLcT5KIwI4aOgzeVzN5SvOZg5bFfbcR+hCDSiKqgaX+EI5UepBqMyzKwmOVW55R1kbTHiNLkG+tt1v+eABvhR1TauI/33u1pteusVpZ15CcrPZ/NBuxslA2Vji+G7QspiN0ZkQupA8Kr2zBInDrA/Q++bEEoQgYUlBB51jDcpoxGPv4MrV5IDCPe5K6b8GsiXCRzNK8KtXVMlwWl7KpGmkS/91mcdw3KWs6Cswmsm7xSm1f55CimqwNZMqcNSHxh1l+gTHc5wTjfTMmPw0Valr/jMjtBj2EC6UP25ooI7kKuJWPqq/sYo7Iz3iT57PjR0jZZi9vCzisu6frm2zu+ci+HHDqGVKwrRNmLU4J4AzEIWhVUGzVJQnfANemhQ4Ojis4Wvlv9MM54DCWkwBEZevYM7svw7NQKbBx8/oqdPgMe3ha5UqafGLh8FdD9hiiTlMx0r2THIwG0br6WVKyJOXlEYIv8+YcCOsqOrRRLQYWzMG4p76urJaEOBgLilrrekybz9Np5s5py7dn6jSczJ7yfF08CWFti5ZjGVC4lFeYcOE21wAM8IdHkwPvtUfY7o0iWLQA/YoHmFQIrt9tTSWl0r5rcQ== sysadmin@o2web.ca"
15
17
 
16
18
  test:
17
19
  secret_key_base: <%= app_secret %>
20
+ deployer_password: <%= SecureRandom.hex %>
21
+ deployer_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD+AhnvJ1BMM0jFCAKSH+NCST+wpz2zwXySiBHN8tZ4kui3ozf//OeBnnGZMOFLurXrzAtll+EE5j+A/iLcT5KIwI4aOgzeVzN5SvOZg5bFfbcR+hCDSiKqgaX+EI5UepBqMyzKwmOVW55R1kbTHiNLkG+tt1v+eABvhR1TauI/33u1pteusVpZ15CcrPZ/NBuxslA2Vji+G7QspiN0ZkQupA8Kr2zBInDrA/Q++bEEoQgYUlBB51jDcpoxGPv4MrV5IDCPe5K6b8GsiXCRzNK8KtXVMlwWl7KpGmkS/91mcdw3KWs6Cswmsm7xSm1f55CimqwNZMqcNSHxh1l+gTHc5wTjfTMmPw0Valr/jMjtBj2EC6UP25ooI7kKuJWPqq/sYo7Iz3iT57PjR0jZZi9vCzisu6frm2zu+ci+HHDqGVKwrRNmLU4J4AzEIWhVUGzVJQnfANemhQ4Ojis4Wvlv9MM54DCWkwBEZevYM7svw7NQKbBx8/oqdPgMe3ha5UqafGLh8FdD9hiiTlMx0r2THIwG0br6WVKyJOXlEYIv8+YcCOsqOrRRLQYWzMG4p76urJaEOBgLilrrekybz9Np5s5py7dn6jSczJ7yfF08CWFti5ZjGVC4lFeYcOE21wAM8IdHkwPvtUfY7o0iWLQA/YoHmFQIrt9tTSWl0r5rcQ== sysadmin@o2web.ca"
18
22
 
19
23
  vagrant:
20
24
  secret_key_base: <%= app_secret %>
25
+ deployer_password: <%= SecureRandom.hex %>
26
+ deployer_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD+AhnvJ1BMM0jFCAKSH+NCST+wpz2zwXySiBHN8tZ4kui3ozf//OeBnnGZMOFLurXrzAtll+EE5j+A/iLcT5KIwI4aOgzeVzN5SvOZg5bFfbcR+hCDSiKqgaX+EI5UepBqMyzKwmOVW55R1kbTHiNLkG+tt1v+eABvhR1TauI/33u1pteusVpZ15CcrPZ/NBuxslA2Vji+G7QspiN0ZkQupA8Kr2zBInDrA/Q++bEEoQgYUlBB51jDcpoxGPv4MrV5IDCPe5K6b8GsiXCRzNK8KtXVMlwWl7KpGmkS/91mcdw3KWs6Cswmsm7xSm1f55CimqwNZMqcNSHxh1l+gTHc5wTjfTMmPw0Valr/jMjtBj2EC6UP25ooI7kKuJWPqq/sYo7Iz3iT57PjR0jZZi9vCzisu6frm2zu+ci+HHDqGVKwrRNmLU4J4AzEIWhVUGzVJQnfANemhQ4Ojis4Wvlv9MM54DCWkwBEZevYM7svw7NQKbBx8/oqdPgMe3ha5UqafGLh8FdD9hiiTlMx0r2THIwG0br6WVKyJOXlEYIv8+YcCOsqOrRRLQYWzMG4p76urJaEOBgLilrrekybz9Np5s5py7dn6jSczJ7yfF08CWFti5ZjGVC4lFeYcOE21wAM8IdHkwPvtUfY7o0iWLQA/YoHmFQIrt9tTSWl0r5rcQ== sysadmin@o2web.ca"
21
27
 
22
28
  staging:
23
29
  secret_key_base: <%= app_secret %>
30
+ deployer_password: <%= SecureRandom.hex %>
31
+ deployer_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD+AhnvJ1BMM0jFCAKSH+NCST+wpz2zwXySiBHN8tZ4kui3ozf//OeBnnGZMOFLurXrzAtll+EE5j+A/iLcT5KIwI4aOgzeVzN5SvOZg5bFfbcR+hCDSiKqgaX+EI5UepBqMyzKwmOVW55R1kbTHiNLkG+tt1v+eABvhR1TauI/33u1pteusVpZ15CcrPZ/NBuxslA2Vji+G7QspiN0ZkQupA8Kr2zBInDrA/Q++bEEoQgYUlBB51jDcpoxGPv4MrV5IDCPe5K6b8GsiXCRzNK8KtXVMlwWl7KpGmkS/91mcdw3KWs6Cswmsm7xSm1f55CimqwNZMqcNSHxh1l+gTHc5wTjfTMmPw0Valr/jMjtBj2EC6UP25ooI7kKuJWPqq/sYo7Iz3iT57PjR0jZZi9vCzisu6frm2zu+ci+HHDqGVKwrRNmLU4J4AzEIWhVUGzVJQnfANemhQ4Ojis4Wvlv9MM54DCWkwBEZevYM7svw7NQKbBx8/oqdPgMe3ha5UqafGLh8FdD9hiiTlMx0r2THIwG0br6WVKyJOXlEYIv8+YcCOsqOrRRLQYWzMG4p76urJaEOBgLilrrekybz9Np5s5py7dn6jSczJ7yfF08CWFti5ZjGVC4lFeYcOE21wAM8IdHkwPvtUfY7o0iWLQA/YoHmFQIrt9tTSWl0r5rcQ== sysadmin@o2web.ca"
24
32
 
25
33
  # Do not keep production secrets in the repository,
26
34
  # instead read values from the environment.
27
35
  production:
28
36
  secret_key_base: <%= app_secret %>
37
+ deployer_password: <%= SecureRandom.hex %>
38
+ deployer_public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD+AhnvJ1BMM0jFCAKSH+NCST+wpz2zwXySiBHN8tZ4kui3ozf//OeBnnGZMOFLurXrzAtll+EE5j+A/iLcT5KIwI4aOgzeVzN5SvOZg5bFfbcR+hCDSiKqgaX+EI5UepBqMyzKwmOVW55R1kbTHiNLkG+tt1v+eABvhR1TauI/33u1pteusVpZ15CcrPZ/NBuxslA2Vji+G7QspiN0ZkQupA8Kr2zBInDrA/Q++bEEoQgYUlBB51jDcpoxGPv4MrV5IDCPe5K6b8GsiXCRzNK8KtXVMlwWl7KpGmkS/91mcdw3KWs6Cswmsm7xSm1f55CimqwNZMqcNSHxh1l+gTHc5wTjfTMmPw0Valr/jMjtBj2EC6UP25ooI7kKuJWPqq/sYo7Iz3iT57PjR0jZZi9vCzisu6frm2zu+ci+HHDqGVKwrRNmLU4J4AzEIWhVUGzVJQnfANemhQ4Ojis4Wvlv9MM54DCWkwBEZevYM7svw7NQKbBx8/oqdPgMe3ha5UqafGLh8FdD9hiiTlMx0r2THIwG0br6WVKyJOXlEYIv8+YcCOsqOrRRLQYWzMG4p76urJaEOBgLilrrekybz9Np5s5py7dn6jSczJ7yfF08CWFti5ZjGVC4lFeYcOE21wAM8IdHkwPvtUfY7o0iWLQA/YoHmFQIrt9tTSWl0r5rcQ== sysadmin@o2web.ca"
@@ -0,0 +1 @@
1
+ <%= @attributes.deployer_public_key %>
@@ -0,0 +1 @@
1
+ <%= @attributes.deployer_name %> ALL=(ALL) NOPASSWD:ALL
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Load base utility functions like sunzi.mute() and sunzi.install()
5
+ source recipes/sunzi.sh
6
+
7
+ # This line is necessary for automated provisioning for Debian/Ubuntu.
8
+ # Remove if you're not on Debian/Ubuntu.
9
+ export DEBIAN_FRONTEND=noninteractive
10
+ export TERM=linux
11
+
12
+ # Add Dotdeb repository. Recommended if you're using Debian. See http://www.dotdeb.org/about/
13
+ # source recipes/dotdeb.sh
14
+ # source recipes/backports.sh
@@ -0,0 +1,24 @@
1
+ if sunzi.to_be_done "install librairies"; then
2
+ sunzi.install "autoconf"
3
+ sunzi.install "bison"
4
+ sunzi.install "libncurses5-dev"
5
+ sunzi.install "libgdbm3"
6
+ sunzi.install "libgdbm-dev"
7
+
8
+ sunzi.install "git-core"
9
+ sunzi.install "zlib1g-dev"
10
+ sunzi.install "build-essential"
11
+ sunzi.install "libssl-dev"
12
+ sunzi.install "libreadline-dev"
13
+ sunzi.install "libyaml-dev"
14
+ sunzi.install "libsqlite3-dev"
15
+ sunzi.install "sqlite3"
16
+ sunzi.install "libxml2-dev"
17
+ sunzi.install "libxslt1-dev"
18
+ sunzi.install "libcurl4-openssl-dev"
19
+ sunzi.install "python-software-properties"
20
+ sunzi.install "libffi-dev"
21
+ sunzi.install "imagemagick"
22
+
23
+ sunzi.done "install librairies"
24
+ fi
@@ -0,0 +1,19 @@
1
+ DB_NAME=<%= @attributes.db_database %>
2
+ DB_USER=<%= @attributes.db_username %>
3
+ DB_PWD=<%= @attributes.db_password %>
4
+ DB_ROOT_PWD=<%= @attributes.mysql_root_password %>
5
+
6
+ if sunzi.to_be_done "install mysql"; then
7
+ sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $DB_ROOT_PWD"
8
+ sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DB_ROOT_PWD"
9
+ sunzi.install "mysql-server"
10
+ sunzi.install "mysql-client"
11
+ sunzi.install "libmysqlclient-dev"
12
+
13
+ sudo -u root mysql -proot -e "create database $DB_NAME;"
14
+ sudo -u root mysql -proot -e "create user '$DB_USER'@'localhost' identified by '$DB_PWD';"
15
+ sudo -u root mysql -proot -e "grant all privileges on $DB_NAME.* to '$DB_USER'@'%' identified by '$DB_PWD';"
16
+ sudo -u root mysql -proot -e "flush privileges;"
17
+
18
+ sunzi.done "install mysql"
19
+ fi
@@ -0,0 +1,6 @@
1
+ if sunzi.to_be_done "install nodejs"; then
2
+ curl -sL https://deb.nodesource.com/setup | sudo bash -
3
+ sunzi.install "nodejs"
4
+
5
+ sunzi.done "install nodejs"
6
+ fi
@@ -0,0 +1,19 @@
1
+ DEPLOYER_NAME=<%= @attributes.deployer_name %>
2
+ DEPLOYER_PATH=/home/$DEPLOYER_NAME
3
+ RBENV_PATH=$DEPLOYER_PATH/.rbenv
4
+
5
+ if sunzi.to_be_done "install passenger"; then
6
+ sunzi.mute "apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7"
7
+ sunzi.install "apt-transport-https"
8
+ sunzi.install "ca-certificates"
9
+ sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
10
+ sunzi.mute "apt-get update"
11
+
12
+ sunzi.install "nginx-extras"
13
+ sunzi.install "passenger"
14
+
15
+ sed -i -e "s|# passenger_root|passenger_root|g" /etc/nginx/nginx.conf
16
+ sed -i -e "s|# passenger_ruby /usr/bin/passenger_free_ruby|passenger_ruby $RBENV_PATH/shims/ruby|g" /etc/nginx/nginx.conf
17
+
18
+ sunzi.done "install passenger"
19
+ fi
@@ -0,0 +1,14 @@
1
+ DB_NAME=<%= @attributes.db_database %>
2
+ DB_USER=<%= @attributes.db_username %>
3
+ DB_PWD=<%= @attributes.db_password %>
4
+
5
+ if sunzi.to_be_done "install postgres"; then
6
+ sunzi.install "postgresql"
7
+ sunzi.install "postgresql-contrib"
8
+ sunzi.install "libpq-dev"
9
+
10
+ sudo -u postgres psql -c "create user $DB_USER with password '$DB_PWD';"
11
+ sudo -u postgres psql -c "create database $DB_NAME owner $DB_USER;"
12
+
13
+ sunzi.done "install postgres"
14
+ fi
@@ -0,0 +1,28 @@
1
+ DEPLOYER_NAME=<%= @attributes.deployer_name %>
2
+ DEPLOYER_PATH=/home/$DEPLOYER_NAME
3
+ RBENV_PATH=$DEPLOYER_PATH/.rbenv
4
+ PLUGINS_PATH=$RBENV_PATH/plugins
5
+ PROFILE=$DEPLOYER_PATH/.bashrc
6
+ RUBY_VERSION=<%= @attributes.ruby_version %>
7
+ RBENV_EXPORT_PATH="export PATH=\"$RBENV_PATH/bin:$PLUGINS_PATH/ruby-build/bin:$PATH\""
8
+ RBENV_INIT='eval "$(rbenv init -)"'
9
+
10
+ if sunzi.to_be_done "install ruby"; then
11
+ git clone git://github.com/sstephenson/rbenv.git $RBENV_PATH
12
+ git clone git://github.com/sstephenson/ruby-build.git $PLUGINS_PATH/ruby-build
13
+ git clone git://github.com/sstephenson/rbenv-gem-rehash.git $PLUGINS_PATH/rbenv-gem-rehash
14
+ git clone git://github.com/dcarley/rbenv-sudo.git $PLUGINS_PATH/rbenv-sudo
15
+
16
+ eval $RBENV_EXPORT_PATH
17
+ eval $RBENV_INIT
18
+ echo $RBENV_EXPORT_PATH >> $PROFILE
19
+ echo $RBENV_INIT >> $PROFILE
20
+
21
+ rbenv install $RUBY_VERSION
22
+ rbenv global $RUBY_VERSION
23
+ echo 'gem: --no-ri --no-rdoc' > $DEPLOYER_PATH/.gemrc
24
+ gem install bundler
25
+ gem install backup
26
+
27
+ sunzi.done "install ruby"
28
+ fi
@@ -0,0 +1,11 @@
1
+ if sunzi.to_be_done "setup system"; then
2
+ sunzi.mute "apt-get update"
3
+ yes | apt-get upgrade
4
+ sunzi.mute "timedatectl set-timezone <%= @attributes.timezone %>"
5
+ sunzi.mute "locale-gen <%= @attributes.locales %>"
6
+ sunzi.mute "dpkg-reconfigure locales"
7
+ sunzi.install "curl"
8
+ sunzi.install "ntp"
9
+
10
+ sunzi.done "setup system"
11
+ fi
@@ -0,0 +1,99 @@
1
+ # This file is used to define functions under the sunzi.* namespace.
2
+
3
+ # Set $sunzi_pkg to "apt-get" or "yum", or abort.
4
+ #
5
+ if which apt-get >/dev/null 2>&1; then
6
+ export sunzi_pkg=apt-get
7
+ elif which yum >/dev/null 2>&1; then
8
+ export sunzi_pkg=yum
9
+ fi
10
+
11
+ if [ "$sunzi_pkg" = '' ]; then
12
+ echo 'sunzi only supports apt-get or yum!' >&2
13
+ exit 1
14
+ fi
15
+
16
+ # Mute STDOUT and STDERR
17
+ #
18
+ function sunzi.mute() {
19
+ echo "Running \"$@\""
20
+ `$@ >/dev/null 2>&1`
21
+ return $?
22
+ }
23
+
24
+ function sunzi.sudo_mute() {
25
+ echo "Running \"$@\""
26
+ `sudo $@ >/dev/null 2>&1`
27
+ return $?
28
+ }
29
+
30
+ # Installer
31
+ #
32
+ function sunzi.installed() {
33
+ if [ "$sunzi_pkg" = 'apt-get' ]; then
34
+ dpkg -s $@ >/dev/null 2>&1
35
+ elif [ "$sunzi_pkg" = 'yum' ]; then
36
+ rpm -qa | grep $@ >/dev/null
37
+ fi
38
+ return $?
39
+ }
40
+
41
+ # When there's "set -e" in install.sh, sunzi.install should be used with if statement,
42
+ # otherwise the script may exit unexpectedly when the package is already installed.
43
+ #
44
+ function sunzi.install() {
45
+ if sunzi.installed "$@"; then
46
+ echo "$@ already installed"
47
+ else
48
+ echo "No packages found matching $@. Installing..."
49
+ sunzi.mute "$sunzi_pkg -y install $@"
50
+ fi
51
+ return 0
52
+ }
53
+
54
+ function sunzi.sudo_install() {
55
+ if sunzi.installed "$@"; then
56
+ echo "$@ already installed"
57
+ else
58
+ echo "No packages found matching $@. Installing..."
59
+ sunzi.sudo_mute "$sunzi_pkg -y install $@"
60
+ fi
61
+ return 0
62
+ }
63
+
64
+ function sunzi.setup_progress() {
65
+ if [[ -e "$HOME/sunzi_progress.txt" ]]; then
66
+ echo "Provisioning already started"
67
+ else
68
+ echo "New provisioning"
69
+ touch "$HOME/sunzi_progress.txt"
70
+ fi
71
+ return 0
72
+ }
73
+
74
+ function sunzi.to_be_done() {
75
+ if [[ -z $(grep -Fx "Done $@" "$HOME/sunzi_progress.txt") ]]; then
76
+ echo "Executing $@"
77
+ return 0
78
+ else
79
+ echo "Done $@"
80
+ return 1
81
+ fi
82
+ }
83
+
84
+ function sunzi.done() {
85
+ echo "Done $@" | tee -a "$HOME/sunzi_progress.txt"
86
+ return 0
87
+ }
88
+
89
+ function sunzi.start_time() {
90
+ echo $(date -u +"%s")
91
+ }
92
+
93
+ function sunzi.elapsed_time() {
94
+ start=$1
95
+ finish=$(date -u +"%s")
96
+ elapsed_time=$(($finish-$start))
97
+ echo "$(($elapsed_time / 60)) minutes and $(($elapsed_time % 60)) seconds elapsed."
98
+ return 0
99
+ }
@@ -0,0 +1,8 @@
1
+ if sunzi.to_be_done "install sysstat"; then
2
+ sunzi.install "sysstat"
3
+
4
+ sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
5
+ /etc/init.d/sysstat restart
6
+
7
+ sunzi.done "install sysstat"
8
+ fi
@@ -0,0 +1,2 @@
1
+ sunzi.mute "apt-get update"
2
+ yes | apt-get upgrade
@@ -0,0 +1,23 @@
1
+ DEPLOYER_NAME=<%= @attributes.deployer_name %>
2
+ DEPLOYER_PWD=<%= @attributes.deployer_password %>
3
+ DEPLOYER_PATH=/home/$DEPLOYER_NAME
4
+
5
+ if sunzi.to_be_done "create deployer"; then
6
+ adduser $DEPLOYER_NAME --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password
7
+ echo "$DEPLOYER_NAME:$DEPLOYER_PWD" | sudo chpasswd
8
+ adduser $DEPLOYER_NAME sudo
9
+
10
+ mkdir $DEPLOYER_PATH/.ssh
11
+ chmod 700 $DEPLOYER_PATH/.ssh
12
+
13
+ mv files/authorized_keys $DEPLOYER_PATH/.ssh/authorized_keys
14
+ chmod 644 $DEPLOYER_PATH/.ssh/authorized_keys
15
+
16
+ chown -R $DEPLOYER_NAME:$DEPLOYER_NAME $DEPLOYER_PATH
17
+
18
+ mv files/sudoers /etc/sudoers.d/$DEPLOYER_NAME
19
+ chown root:root /etc/sudoers.d/$DEPLOYER_NAME
20
+ chmod 0440 /etc/sudoers.d/$DEPLOYER_NAME
21
+
22
+ sunzi.done "create deployer"
23
+ fi
@@ -0,0 +1,20 @@
1
+ sunzi.setup_progress
2
+
3
+ start=$(sunzi.start_time)
4
+
5
+ source recipes/setup.sh
6
+ source recipes/libraries.sh
7
+ source recipes/nodejs.sh
8
+ <% case @attributes.db_adapter -%>
9
+ <% when 'postgresql' -%>
10
+ source recipes/postgres.sh
11
+ <% when 'mysql', 'mysql2' -%>
12
+ source recipes/mysql.sh
13
+ <% end -%>
14
+ source recipes/passenger.sh
15
+ source recipes/user.sh
16
+ source recipes/sysstat.sh
17
+
18
+ sunzi.elapsed_time $start
19
+
20
+ reboot