salted_rails_server 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +181 -43
- data/Vagrantfile +71 -0
- data/lib/generators/salted_rails_server/salted_rails_server_generator.rb +23 -26
- data/lib/generators/salted_rails_server/templates/pillars/default.sls +24 -0
- data/lib/generators/salted_rails_server/templates/roster +24 -0
- data/lib/generators/salted_rails_server/templates/states/backup.sls +52 -0
- data/lib/generators/salted_rails_server/templates/states/backup/files/home/deploy/bin/backup.rb +64 -0
- data/lib/generators/salted_rails_server/templates/states/backup/files/home/deploy/config/schedule.rb +24 -0
- data/lib/generators/salted_rails_server/templates/states/elasticsearch.sls +3 -2
- data/lib/generators/salted_rails_server/templates/states/imagemagick.sls +2 -0
- data/lib/generators/salted_rails_server/templates/states/logrotate.sls +5 -0
- data/lib/generators/salted_rails_server/templates/states/logrotate/files/etc/logrotate.d/rails +10 -0
- data/lib/generators/salted_rails_server/templates/states/monit.sls +20 -0
- data/lib/generators/salted_rails_server/templates/states/monit/etc/monit/monitrc +331 -0
- data/lib/generators/salted_rails_server/templates/states/monit/redis.sls +2 -0
- data/lib/generators/salted_rails_server/templates/states/mysql.sls +18 -18
- data/lib/generators/salted_rails_server/templates/states/node.sls +5 -4
- data/lib/generators/salted_rails_server/templates/states/rails.sls +4 -3
- data/lib/generators/salted_rails_server/templates/states/redis.sls +2 -0
- data/lib/generators/salted_rails_server/templates/states/rvm.sls +10 -9
- data/lib/generators/salted_rails_server/templates/states/setup.sls +7 -2
- data/lib/salted_rails_server/version.rb +1 -1
- metadata +15 -5
- data/lib/generators/salted_rails_server/templates/pillars/default/init.sls +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2bab325d477149bedd2bed2b71a290b4a5b6753
|
4
|
+
data.tar.gz: 3690989f0e972979fca60717bdfee1dd8875ae28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942cf95085373bf1e7d09e1ab5b4683d832da5a151b3e935d0f90216d8f004c68d0aad85d3cf7cfeaf1492ab9cc6f8ad55bd84d8718d6b03885c5e6ddc1437a2
|
7
|
+
data.tar.gz: b19855780ddb0b86f6303da0b9831c00a3448c84462b94cb0fc81c1872b4bc26e1492f493aafabb545b0c58a9a21ed7334d4a5ca06d2576d274b08c4ab41ac38
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,36 @@
|
|
1
|
-
#
|
1
|
+
# Salted _ Rails _ Server
|
2
2
|
|
3
|
-
|
3
|
+
## Description
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
5
|
+
A ruby on rails generator for provisioning a new server using salt-ssh
|
6
|
+
|
7
|
+
Supports the following:
|
8
|
+
|
9
|
+
* [Backup](https://github.com/backup/backup)
|
10
|
+
* [ElasticSearch](https://info.elastic.co/branded-ggl-elastic-exact-v3.html?camp=Branded-GGL-Exact&src=adwords&mdm=cpc&trm=elasticsearch&gclid=EAIaIQobChMIhuuXsc6E2AIVEoGzCh1JFgyzEAAYAiAAEgKRZ_D_BwE)
|
11
|
+
* [ImageMagick](https://www.imagemagick.org/script/index.php)
|
12
|
+
* [LogRotate](http://www.thegeekstuff.com/2010/07/logrotate-examples/)
|
13
|
+
* [Monit](https://mmonit.com/monit)
|
14
|
+
* [MySQL](https://www.mysql.com/)
|
15
|
+
* [NGINX](https://www.nginx.com/)
|
16
|
+
* [Node](https://nodejs.org/)
|
17
|
+
* [Redis](https://redis.io/)
|
18
|
+
* [RubyOnRails](http://rubyonrails.org/)
|
19
|
+
* [RVM](https://rvm.io/)
|
20
|
+
* User - User setup
|
21
|
+
|
22
|
+
All installations are the latest packages for the managed system unless there is a version section in the pillars/default.sls.
|
12
23
|
|
13
24
|
## Tested on
|
14
25
|
|
15
|
-
* Ubuntu
|
16
|
-
* Ubuntu
|
26
|
+
* Ubuntu Trust
|
27
|
+
* Ubuntu Xenial
|
17
28
|
|
18
|
-
No reason this should not work on any other
|
29
|
+
No reason this should not work on any other salt stack supported OS. If you have tried this on any other OS and it did not work, please let me know.
|
19
30
|
|
20
31
|
## salt-ssh installation
|
21
32
|
|
22
|
-
This code requires that you have Saltstack's salt-ssh already installed the system you are deploying from and a compatible version of python on the system you are deploying to.
|
23
|
-
|
33
|
+
This code requires that you have Saltstack's salt-ssh already installed on the system you are deploying from and a compatible version of python on the system you are deploying to. If you are a mac user attempting to use this and you have issues, try using [salt-ssh-vm](https://github.com/vmcilwain/salt-ssh-vm)
|
24
34
|
|
25
35
|
Consult the following documentation for your OS:
|
26
36
|
https://docs.saltstack.com/en/latest/topics/installation/index.html
|
@@ -43,81 +53,209 @@ And then generate code:
|
|
43
53
|
rails g salted_rails_server
|
44
54
|
```
|
45
55
|
|
46
|
-
The following files will be generated:
|
56
|
+
The following files will be generated in the root directory:
|
47
57
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
```
|
59
|
+
./master
|
60
|
+
./roster # DO NOT CHECK IN THIS FILE!!!
|
61
|
+
./Saltfile
|
62
|
+
./salt_ssh
|
63
|
+
├── pillars
|
64
|
+
│ ├── default.sls
|
65
|
+
│ └── top.sls
|
66
|
+
└── states
|
67
|
+
├── backup
|
68
|
+
│ └── files
|
69
|
+
│ └── home
|
70
|
+
│ └── deploy
|
71
|
+
│ ├── bin
|
72
|
+
│ │ └── backup.rb
|
73
|
+
│ └── config
|
74
|
+
│ └── schedule.rb
|
75
|
+
├── backup.sls
|
76
|
+
├── elasticsearch.sls
|
77
|
+
├── imagemagick.sls
|
78
|
+
├── logrotate
|
79
|
+
│ └── files
|
80
|
+
│ └── etc
|
81
|
+
│ └── logrotate.d
|
82
|
+
│ └── rails
|
83
|
+
├── logrotate.sls
|
84
|
+
├── monit
|
85
|
+
│ ├── etc
|
86
|
+
│ │ └── monit
|
87
|
+
│ │ └── monitrc
|
88
|
+
│ └── redis.sls
|
89
|
+
├── monit.sls
|
90
|
+
├── mysql.sls
|
91
|
+
├── nginx.sls
|
92
|
+
├── node.sls
|
93
|
+
├── redis.sls
|
94
|
+
├── rails.sls
|
95
|
+
├── rvm.sls
|
96
|
+
├── setup.sls
|
97
|
+
└── user.sls
|
98
|
+
```
|
53
99
|
|
54
100
|
## Configuration
|
55
101
|
|
56
|
-
Add
|
102
|
+
Add custom options to the following files:
|
57
103
|
|
58
104
|
* roster - remote host(s) information
|
59
|
-
* pillars/default
|
105
|
+
* pillars/default.sls - RAILS_ENV, Remote Username with ssh-key, MYSQL root and rails user user password and versions of ruby and elasticsearch to be installed.
|
106
|
+
|
107
|
+
## Setting up Remote system
|
60
108
|
|
109
|
+
Add your public ssh key to the authorized_keys on remote server that you plan to manage. I normally add this to root but it needs to be added to a user with sudo privileges.
|
61
110
|
|
62
|
-
##
|
111
|
+
## Testing salt-ssh connection
|
63
112
|
|
64
|
-
|
113
|
+
From within the appliation root directory type:
|
65
114
|
|
66
115
|
```
|
67
|
-
sudo salt-ssh -i '*'
|
116
|
+
sudo salt-ssh -i '*' test.ping
|
117
|
+
```
|
118
|
+
|
119
|
+
The following should be returned:
|
120
|
+
```
|
121
|
+
managed:
|
122
|
+
True
|
68
123
|
```
|
69
124
|
|
70
|
-
|
125
|
+
If that is not returned, salt-ssh should give you an accurate reason to why it was not able to connect. Another tool to use is the verbose option on the ssh command.
|
71
126
|
|
72
127
|
```
|
73
|
-
|
128
|
+
ssh -vv user@remote-host
|
74
129
|
```
|
75
130
|
|
76
|
-
|
131
|
+
## The States (Remote Management)
|
132
|
+
|
133
|
+
### Available States
|
77
134
|
|
135
|
+
* backup
|
78
136
|
* elasticsearch
|
137
|
+
* imagemagick
|
138
|
+
* logrotate
|
139
|
+
* monit
|
79
140
|
* mysql
|
80
141
|
* nginx
|
81
142
|
* node
|
143
|
+
* redis
|
82
144
|
* rails
|
83
145
|
* rvm
|
84
|
-
*
|
146
|
+
* setup
|
147
|
+
* user - User setup
|
85
148
|
|
86
|
-
|
149
|
+
### The Setup State
|
87
150
|
|
88
|
-
|
151
|
+
```
|
152
|
+
sudo salt-ssh -i '*' state.apply setup
|
153
|
+
```
|
89
154
|
|
90
|
-
|
155
|
+
This runs the minimum set of states in a specific order. Be sure to look at salt_ssh/states/setup.sls to comment or uncomment any additional items you do or don't want installed during the setup process.
|
91
156
|
|
92
|
-
|
93
|
-
Update pillars/default/init.sls to add your ssh key to log in as the user created in the user state
|
157
|
+
This takes a while and there aren't any status updates as things progress. Be patient!
|
94
158
|
|
95
|
-
###
|
159
|
+
### Individual States
|
160
|
+
|
161
|
+
```
|
162
|
+
sudo salt-ssh -i '*' state.apply state_file
|
163
|
+
```
|
164
|
+
|
165
|
+
## State Details
|
166
|
+
|
167
|
+
### Backup State
|
168
|
+
|
169
|
+
Installs the [backup](https://github.com/backup/backup) and [whenever](https://github.com/javan/whenever) gems for backing up your rails application.
|
170
|
+
|
171
|
+
The backup configuration is stored in `/home/username/bin`
|
172
|
+
|
173
|
+
Whenever configuration is stored in `/home/username/config`
|
174
|
+
|
175
|
+
Backups are stored in `/var/backups/rails`
|
176
|
+
|
177
|
+
It has configurations for using AWS S3 and SES. Those configurations can be added to the roster file. You can see an example of this in the roster file.
|
96
178
|
|
97
|
-
|
98
|
-
Sets the default to the specified version in pillars/default/init.sls
|
179
|
+
### ElasticSearch State (Debian/Ubuntu Only)
|
99
180
|
|
181
|
+
Installs the specified version of elasticsearch found in salt_ssh/pillars/default.sls. The fallback is version 2.3.4. This also installs the openjdk_7_jre dependency.
|
182
|
+
|
183
|
+
### ImageMagick State
|
184
|
+
|
185
|
+
Installs the lates version of ImageMagick via the package manager for the OS.
|
186
|
+
|
187
|
+
### LogRotate State
|
188
|
+
|
189
|
+
Ensures logrotate is installed on the remote system (it most likely is) via the package manager for the OS. Adds a rails config in /etc/logrotate.d.
|
190
|
+
|
191
|
+
### Monit State
|
192
|
+
|
193
|
+
Ensures monit is installed via the package manager for the OS
|
194
|
+
and running. Makes a backup of the original /etc/monit/monitrc then replaces it with config that monitors any monit configs stored within the rails application.
|
195
|
+
|
196
|
+
The monit config file is setup to use AWS SES which you can add the credentials to the roster file.
|
197
|
+
|
198
|
+
### MySQL state
|
199
|
+
|
200
|
+
Ensures MySQL is installed via the package manager for the OS and running. Currently, you will need to create the user account due to the following open issues:
|
201
|
+
|
202
|
+
[29265](https://github.com/saltstack/salt/issues/29265)
|
203
|
+
|
204
|
+
[44200](https://github.com/saltstack/salt/issues/44200)
|
205
|
+
|
206
|
+
Once resolved, the option to create MySQL users will be re-enabled.
|
207
|
+
|
208
|
+
The code is commented out in salt_ssh/states/user.sls if you decide you want to try and use it before the issues are resolved.
|
209
|
+
|
210
|
+
### NGINX State
|
211
|
+
|
212
|
+
Installs NGINX via the package manager for the OS and ensures it is running.
|
213
|
+
|
214
|
+
### Node State
|
215
|
+
|
216
|
+
Ensures nodejs is installed via the package manager for the OS and creates a node symlink if it doesn't exist.
|
217
|
+
|
218
|
+
### Redis State
|
219
|
+
|
220
|
+
Ensures redis is installed via the package manager for the OS and is running.
|
100
221
|
### Rails state
|
101
222
|
|
102
|
-
Installs the following gems
|
223
|
+
Installs the following gems under RVM:
|
103
224
|
|
104
225
|
* Bundler
|
105
226
|
* Rails
|
106
227
|
* Unicorn
|
107
228
|
|
108
|
-
|
229
|
+
creates /var/www if it doesn't exist and sets the owner of that directory to the specified user in the user state.
|
109
230
|
|
110
|
-
###
|
231
|
+
### RVM state
|
111
232
|
|
112
|
-
|
113
|
-
Sets the root password to what is specified in pillar/default/init.sls
|
233
|
+
Installs RVM under the specified user in the user state. Sets the default to the specified version in salt_ssh/pillars/default.sls.
|
114
234
|
|
235
|
+
### User state
|
236
|
+
|
237
|
+
Creates a user that is defined in salt_ssh/pillars/default.sls. If a user is not found it will default to user named deploy. This state also adds the user to /etc/sudoers for executing code without the need for a password.
|
238
|
+
|
239
|
+
#### RSA key
|
240
|
+
|
241
|
+
Update salt_ssh/pillars/default/init.sls to add your ssh key to log in as the user created in the user state. This is required since the user created does not have a default password assigned. This is done for strong security!.
|
115
242
|
|
116
243
|
## Caution
|
117
244
|
|
118
245
|
Take a look at the code before you use it to make sure that it works the way you expect or want. After the code is generated you can modify it to fit your needs before executing.
|
119
246
|
|
120
|
-
|
247
|
+
|
248
|
+
## Uninstalling
|
249
|
+
|
250
|
+
To uninstall salted_rails_server simply delete the following files:
|
251
|
+
|
252
|
+
* /master
|
253
|
+
* /roster
|
254
|
+
* /Saltfile
|
255
|
+
* /salt.log
|
256
|
+
* /salt_ssh #directory
|
257
|
+
|
258
|
+
## Contributing
|
121
259
|
|
122
260
|
I am looking for constructive criticisim on making this better and easier for everyone who could use it.
|
123
261
|
|
data/Vagrantfile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
5
|
+
# configures the configuration version (we support older styles for
|
6
|
+
# backwards compatibility). Please don't change it unless you know what
|
7
|
+
# you're doing.
|
8
|
+
Vagrant.configure(2) do |config|
|
9
|
+
# The most common configuration options are documented and commented below.
|
10
|
+
# For a complete reference, please see the online documentation at
|
11
|
+
# https://docs.vagrantup.com.
|
12
|
+
|
13
|
+
# Every Vagrant development environment requires a box. You can search for
|
14
|
+
# boxes at https://atlas.hashicorp.com/search.
|
15
|
+
config.vm.box = "ubuntu/trusty64"
|
16
|
+
|
17
|
+
# Disable automatic box update checking. If you disable this, then
|
18
|
+
# boxes will only be checked for updates when the user runs
|
19
|
+
# `vagrant box outdated`. This is not recommended.
|
20
|
+
# config.vm.box_check_update = false
|
21
|
+
|
22
|
+
# Create a forwarded port mapping which allows access to a specific port
|
23
|
+
# within the machine from a port on the host machine. In the example below,
|
24
|
+
# accessing "localhost:8080" will access port 80 on the guest machine.
|
25
|
+
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
26
|
+
|
27
|
+
# Create a private network, which allows host-only access to the machine
|
28
|
+
# using a specific IP.
|
29
|
+
config.vm.network "private_network", ip: "192.168.33.15"
|
30
|
+
|
31
|
+
# Create a public network, which generally matched to bridged network.
|
32
|
+
# Bridged networks make the machine appear as another physical device on
|
33
|
+
# your network.
|
34
|
+
# config.vm.network "public_network"
|
35
|
+
|
36
|
+
# Share an additional folder to the guest VM. The first argument is
|
37
|
+
# the path on the host to the actual folder. The second argument is
|
38
|
+
# the path on the guest to mount the folder. And the optional third
|
39
|
+
# argument is a set of non-required options.
|
40
|
+
# config.vm.synced_folder "../data", "/vagrant_data"
|
41
|
+
|
42
|
+
# Provider-specific configuration so you can fine-tune various
|
43
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
44
|
+
# Example for VirtualBox:
|
45
|
+
#
|
46
|
+
# config.vm.provider "virtualbox" do |vb|
|
47
|
+
# # Display the VirtualBox GUI when booting the machine
|
48
|
+
# vb.gui = true
|
49
|
+
#
|
50
|
+
# # Customize the amount of memory on the VM:
|
51
|
+
# vb.memory = "1024"
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# View the documentation for the provider you are using for more
|
55
|
+
# information on available options.
|
56
|
+
|
57
|
+
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
|
58
|
+
# such as FTP and Heroku are also available. See the documentation at
|
59
|
+
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
|
60
|
+
# config.push.define "atlas" do |push|
|
61
|
+
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
|
62
|
+
# end
|
63
|
+
|
64
|
+
# Enable provisioning with a shell script. Additional provisioners such as
|
65
|
+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
66
|
+
# documentation for more information about their specific syntax and use.
|
67
|
+
# config.vm.provision "shell", inline: <<-SHELL
|
68
|
+
# sudo apt-get update
|
69
|
+
# sudo apt-get install -y apache2
|
70
|
+
# SHELL
|
71
|
+
end
|
@@ -1,56 +1,53 @@
|
|
1
1
|
class SaltedRailsServerGenerator < Rails::Generators::Base
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
3
|
|
4
|
-
desc 'create
|
4
|
+
desc 'create directories'
|
5
5
|
def create_file_structure
|
6
|
-
run 'mkdir -p
|
7
|
-
run 'mkdir -p
|
8
|
-
run 'mkdir -p
|
6
|
+
run 'mkdir -p salt_ssh/pillars'
|
7
|
+
run 'mkdir -p salt_ssh/states/backup/files/home/deploy/bin'
|
8
|
+
run 'mkdir -p salt_ssh/states/backup/files/home/deploy/config'
|
9
|
+
run 'mkdir -p salt_ssh/states/logrotate/files/etc/logrotate.d'
|
10
|
+
run 'mkdir -p salt_ssh/states/monit/etc/monit'
|
9
11
|
end
|
10
12
|
|
11
|
-
desc 'generatre
|
13
|
+
desc 'generatre default pillar'
|
12
14
|
def copy_pillar_files
|
13
|
-
copy_file 'pillars/default
|
14
|
-
copy_file 'pillars/top.sls', '
|
15
|
+
copy_file 'pillars/default.sls', 'salt_ssh/pillars/default.sls'
|
16
|
+
copy_file 'pillars/top.sls', 'salt_ssh/pillars/top.sls'
|
15
17
|
end
|
16
|
-
|
17
|
-
desc 'generate
|
18
|
+
|
19
|
+
desc 'generate state files'
|
18
20
|
def copy_state_files
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
copy_file 'states/node.sls', 'salted_rails_server/states/node.sls'
|
23
|
-
copy_file 'states/rails.sls', 'salted_rails_server/states/rails.sls'
|
24
|
-
copy_file 'states/rvm.sls', 'salted_rails_server/states/rvm.sls'
|
25
|
-
copy_file 'states/setup.sls', 'salted_rails_server/states/setup.sls'
|
26
|
-
copy_file 'states/user.sls', 'salted_rails_server/states/user.sls'
|
21
|
+
Dir["#{__dir__}/templates/states/**/*"].each do |file|
|
22
|
+
copy_file file, "salt_ssh/#{file.gsub(__dir__+'/templates/', '')}" unless File.directory? file
|
23
|
+
end
|
27
24
|
end
|
28
|
-
|
29
|
-
desc 'generate
|
25
|
+
|
26
|
+
desc 'generate roster file'
|
30
27
|
def copy_roster
|
31
28
|
copy_file 'roster', 'roster'
|
32
29
|
end
|
33
|
-
|
34
|
-
desc 'generate
|
30
|
+
|
31
|
+
desc 'generate master file'
|
35
32
|
def generate_master
|
36
33
|
create_file 'master', <<-CODE
|
37
34
|
file_roots:
|
38
35
|
base:
|
39
|
-
- #{Rails.root}/
|
36
|
+
- #{Rails.root}/salt_ssh/states
|
40
37
|
|
41
38
|
pillar_roots:
|
42
39
|
base:
|
43
|
-
- #{Rails.root}/
|
40
|
+
- #{Rails.root}/salt_ssh/pillars
|
44
41
|
CODE
|
45
42
|
end
|
46
|
-
|
47
|
-
desc 'generate
|
43
|
+
|
44
|
+
desc 'generate Saltfile file'
|
48
45
|
def generate_saltfile
|
49
46
|
create_file "Saltfile", <<-CODE
|
50
47
|
salt-ssh:
|
51
48
|
config_dir: #{Rails.root}
|
52
49
|
roster_file: #{Rails.root}/roster
|
53
|
-
log_file: #{Rails.root}/
|
50
|
+
log_file: #{Rails.root}/salt.log
|
54
51
|
CODE
|
55
52
|
end
|
56
53
|
end
|