capistrano-addon-fm 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fc7d4b0461652faa8410d3fc1e523d8859e39658e72efcc280bb7ac85cb8499b
4
+ data.tar.gz: f174c148881f0c23c6e437cf412edc2e3f94df850304e025eb944f736e91d93a
5
+ SHA512:
6
+ metadata.gz: adcffbf7e1fad3b5225f3726bd6bc3ee07435553cab44610b30e045f3518343826d6448d66399f3abcee85aad72db9c76b7dd2ff6be1b3b06fad4b3337383791
7
+ data.tar.gz: 2060cf4a8fa6ec36eab7ebd411228785a4178c591dbb485ba471d7c5c6bc6a48ca1d317fe9e4bb01bc8d36b033bc5308347f2b7e177370ceff377cd84090d02c
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.1.0] - 2025-02-18
5
+ ### Added
6
+ - add generic tasks - documented in README.md
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in capistrano-addon-fm.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Florin Motoc
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,121 @@
1
+ # capistrano-addon-fm
2
+
3
+ ---
4
+
5
+ ## Installation
6
+
7
+ - Add this to your `Gemfile`
8
+ ```ruby
9
+ gem 'capistrano-addon-fm'
10
+ ```
11
+ - Run `bundle install`
12
+ - Add this to your `Capfile`
13
+ ```ruby
14
+ require 'capistrano/addon/fm'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### this will add new tasks for `cap` command
20
+ new tasks (example run: cap prod TASK - replace 'prod' with your stage (devel/local/etc))
21
+ #### supervisor related commands:
22
+ cap prod supervisor:start Will run supervisorctl `start all`
23
+ cap prod supervisor:stop Will run supervisorctl `stop all`
24
+ cap prod supervisor:restart Will restart all supervisor processes (via stop and start)
25
+ cap prod supervisor:reread Will run supervisorctl `reread`
26
+ cap prod supervisor:update Will run supervisorctl `update`
27
+ cap prod supervisor:status Will display all supervisor processes
28
+ cap prod supervisor:status | grep RUNNING Will display all supervisor processes in RUNNING state
29
+ cap prod supervisor:status | grep -v RUNNING Will display all supervisor processes without the ones in RUNNING state
30
+ #### nginx related commands:
31
+ cap prod nginx:start
32
+ cap prod nginx:stop
33
+ cap prod nginx:reload
34
+ cap prod nginx:restart
35
+ cap prod nginx:status
36
+ #### fpm related commands: TO-BE-ADDED
37
+ #### system related commands:
38
+ cap prod php Run 'php -v'
39
+ cap prod composer Run 'composer --version'
40
+ cap prod hostname Run `hostname`
41
+ cap prod cpu Run `cat /proc/cpuinfo | egrep 'model name|MHz'`
42
+ cap prod uptime Run `uptime`
43
+ cap prod kernel Run `lsb_release -a && uname -a`
44
+ cap prod hosts Run `cat /etc/hosts`
45
+ cap prod ufw:status Run 'ufw status verbose'
46
+ cap prod list:users Run 'ls -lah /home'
47
+ cap prod list:supervisor Run 'ls -lah /etc/supervisor/conf.d/* && ls -lah /etc/supervisor/conf.d/*/'
48
+ cap prod redis:cfg:show Run 'cat /etc/redis/redis.conf | egrep -v "^\s*(#|$)"'
49
+ cap prod systemctl:daemon-reload Run 'systemctl daemon-reload'
50
+ cap prod haproxy|ssh|xz|redis :version (ex: cap prod haproxy:version)
51
+ cap prod system:disk_space: all|df|zfs|btrfs
52
+ cap prod system:connections:count: total|per_address|via_ss
53
+ #### env-with-secrets:
54
+ cap env:upload Will upload .env file to server and decrypt
55
+ cap env:upload:diff Will run `diff` command to server's .env versus local .env - decrypted
56
+ cap env:local:encrypt_file Will encrypt `cap-secrets-LOCAL.txt` to `ap-secrets.enc.b64`
57
+ cap env:local:decrypt_file Will decrypt `ap-secrets.enc.b64` into `cap-secrets-LOCAL.txt`
58
+ cap env:local:secrets cat `cap-secrets-LOCAL.txt`
59
+ #### custom related commands:
60
+ cap prod cat:env Run `cat /var/www/*/*/.env`
61
+ cap prod empty_file:check Run `la -lah on nginx, fpm, laravel and var/www/*/current/logs/*`
62
+ cap prod empty_file: nginx|fpm|laravel|logs2 Run `truncate -s 0 && rm ` on nginx, fpm, laravel and var/www/*/current/logs/*`
63
+ cap prod empty_file:all Run check + truncate/rm + check on all
64
+ #### Helpful commands
65
+ cap prod command ROLES=role1,role2 Run command on specified role(s)
66
+ cap prod command HOSTS=host1,host2 Run command on specified host(s)
67
+
68
+ ## Configuration
69
+
70
+ Following variables are available to be changed (shown with defaults)
71
+
72
+ ```ruby
73
+ # env-with-secrets
74
+ set :local_path, './'
75
+ set :file_to_encrypt, 'cap-secrets-LOCAL.txt'
76
+ set :file_to_decrypt, 'cap-secrets.enc.b64'
77
+ set :encryption_key_file, 'cap-secrets-encryption-key-LOCAL.txt'
78
+ ```
79
+
80
+ ## env-with-secrets
81
+ ### This will allow you to have .env files committed to git with secrets inside (encrypted)
82
+ - Inside .env file you need to use `="CAP_ENCRYPTED_SECRETS[something]"`. Examples:
83
+ - `DB_PASSWORD="CAP_ENCRYPTED_SECRETS[DB_PASSWORD]"`
84
+ - `MAIL_PASSWORD="CAP_ENCRYPTED_SECRETS[MAIL_PASSWORD]"`
85
+ - After deploy, the `CAP_ENCRYPTED_SECRETS[DB_PASSWORD]` will be replaced to whatever secret you wrote in the secrets file for key `DB_PASSWORD`
86
+ - Also, the `CAP_ENCRYPTED_SECRETS` will be removed; this is used for the regex to know when to replace
87
+ - You also need 3 files - generate them by running `cap {prod} env:local:encrypt_file` - this will generate the files when they don't exist
88
+ - `cap-secrets-encryption-key-LOCAL.txt`
89
+ - Don't push this to git.
90
+ - You need to manually share this with other colleagues to be able to deploy and/or encrypt/decrypt .env files.
91
+ - This is the encryption key. You can change it to whatever you want. Default is 40 random chars.
92
+ - `cap-secrets-LOCAL.txt`
93
+ - Don't push this to git.
94
+ - Generated by `cap {prod} env:local:decrypt_file`
95
+ - Decrypts `cap-secrets.enc.b64` into `cap-secrets-LOCAL.txt`
96
+ - This file stores `SOME_KEY="secret"` on each line
97
+ - The `SOME_KEY` will be used in .env files like this: `SOME_VAR="CAP_ENCRYPTED_SECRETS[SOME_KEY]"`
98
+ - `cap-secrets.enc.b64`
99
+ - Push this to git.
100
+ - Generated by `cap {prod} env:local:encrypt_file`
101
+ - Encrypts `cap-secrets-LOCAL.txt` into `cap-secrets.enc.b64`
102
+ - You can also change the location and name of these files by changing the 4 variables from `Configuration`
103
+ - You can also use subdirectories, but you need to create directories first.
104
+ - Everything is related to `Capfile`
105
+ - If you don't set anything, then the default is root of project (or, near the Capfile)
106
+ - Finally, you need to have this in your `deploy.rb` or `stages/{stage}.rb`
107
+ - `before "deploy:symlink:release", "env:upload:diff"`
108
+ - I like having `diff` too, before `upload`, to see in `cap {prod} deploy` output the diff - if any
109
+ - So it will be:
110
+ - `before "deploy:symlink:release", "env:upload:diff"`
111
+ - `before "deploy:symlink:release", "env:upload"`
112
+ - Also, for each `server` line, you need to specify which .env file to use via `env_file_location`. Example:
113
+ - `server "web1", user: "user1", roles: %w{ app web etc }, env_file_location: '.env.prod.web1'`
114
+ - File `.env.prod.web1` should exist at root of project
115
+ - Preferably to update `.gitignore` file with the 2 `LOCAL` files
116
+ - `cap-secrets-LOCAL.txt`
117
+ - `cap-secrets-encryption-key-LOCAL.txt`
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,51 @@
1
+
2
+ namespace 'cat' do
3
+ task 'env' do
4
+ on release_roles(:fpm) do
5
+ execute "cat /var/www/*/*/.env", raise_on_non_zero_exit: false
6
+ end
7
+ end
8
+ end
9
+
10
+ namespace "empty_file" do
11
+ task "all" do
12
+ invoke! "empty_file:check"
13
+ invoke! "empty_file:nginx"
14
+ invoke! "empty_file:fpm"
15
+ invoke! "empty_file:laravel"
16
+ invoke! "empty_file:logs2"
17
+ invoke! "empty_file:check"
18
+ end
19
+ task "check" do
20
+ on release_roles(:app) do
21
+ execute "ls -lahS /var/log/nginx/*.log", raise_on_non_zero_exit: false
22
+ execute "ls -lahS /var/log/php*-fpm.log", raise_on_non_zero_exit: false
23
+ execute "ls -lahS /var/www/*/current/storage/logs/*", raise_on_non_zero_exit: false
24
+ execute "ls -lahS /var/www/*/current/logs/*", raise_on_non_zero_exit: false
25
+ end
26
+ end
27
+ task "nginx" do
28
+ on release_roles(:app) do
29
+ execute "sudo truncate -s 0 /var/log/nginx/*.log", raise_on_non_zero_exit: false
30
+ end
31
+ end
32
+ task "fpm" do
33
+ on release_roles(:app) do
34
+ execute "sudo truncate -s 0 /var/log/php*-fpm.log", raise_on_non_zero_exit: false
35
+ end
36
+ end
37
+ task "laravel" do
38
+ on release_roles(:app) do
39
+ execute "sudo truncate -s 0 /var/www/*/current/storage/logs/*.log && sudo truncate -s 0 /var/www/*/current/storage/logs/*.err", raise_on_non_zero_exit: false
40
+ execute "sudo rm /var/www/*/current/storage/logs/*.log.*", raise_on_non_zero_exit: false
41
+ execute "sudo rm /var/www/*/current/storage/logs/*.err.*", raise_on_non_zero_exit: false
42
+ end
43
+ end
44
+ task "logs2" do
45
+ on release_roles(:app) do
46
+ execute "sudo truncate -s 0 /var/www/*/current/logs/*.log && sudo truncate -s 0 /var/www/*/current/logs/*.err", raise_on_non_zero_exit: false
47
+ execute "sudo rm /var/www/*/current/logs/*.log.*", raise_on_non_zero_exit: false
48
+ execute "sudo rm /var/www/*/current/logs/*.err.*", raise_on_non_zero_exit: false
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,159 @@
1
+ namespace "env" do
2
+ # Set default values
3
+ set :default_local_path, './'
4
+ set :default_file_to_encrypt, 'cap-secrets-LOCAL.txt'
5
+ set :default_file_to_decrypt, 'cap-secrets.enc.b64'
6
+ set :default_encryption_key_file, 'cap-secrets-encryption-key-LOCAL.txt'
7
+
8
+ # uploads .env to server (.env.tmp copied to .env)
9
+ task "upload" do
10
+ invoke! "env:local:check:files:exist"
11
+ invoke "env:upload_local_env_file"
12
+ invoke! "env:decrypt_remote_env_tmp_file"
13
+ on roles(:app) do
14
+ execute "cd #{shared_path} && cp .env.tmp .env", raise_on_non_zero_exit: false
15
+ end
16
+ end
17
+ # compares server .env with local .env (via .env.tmp)
18
+ task "upload:diff" do
19
+ invoke! "env:local:check:files:exist"
20
+ invoke "env:upload_local_env_file"
21
+ invoke! "env:decrypt_remote_env_tmp_file"
22
+ on roles(:app) do
23
+ execute "cd #{shared_path} && diff .env .env.tmp", raise_on_non_zero_exit: false
24
+ end
25
+ end
26
+ # upload local env to server (.env.tmp) - does not decrypt
27
+ task "upload_local_env_file" do
28
+ on roles(:app) do |host|
29
+ if !File.exists?("#{host.properties.env_file_location}")
30
+ puts "local env file `#{host.properties.env_file_location}` does not exist. skipping .env file upload!"
31
+ else
32
+ upload! "#{host.properties.env_file_location}", "#{shared_path}/.env.tmp"
33
+ end
34
+ end
35
+ end
36
+ # decrypt .env file on server (encrypted .env.tmp to decrypted .env.tmp)
37
+ task "decrypt_remote_env_tmp_file" do
38
+ on roles(:app) do
39
+ encryption_key_file = fetch(:encryption_key_file, fetch(:default_encryption_key_file))
40
+ base64_file = fetch(:file_to_decrypt, fetch(:default_file_to_decrypt))
41
+ encrypted_file = base64_file.gsub('.b64', '')
42
+ decrypted_file_tmp = "cap-secrets-tmp.txt"
43
+
44
+ # Read the .env file
45
+ env_file = capture(:cat, "#{shared_path}/.env.tmp")
46
+
47
+ # Read the encryption key from the local file
48
+ encryption_key = File.read(encryption_key_file).strip
49
+
50
+ # Decode and decrypt cap-secrets.enc.b64 into a temporary file cap-secrets-tmp.txt
51
+ execute "base64 -d #{release_path}/#{base64_file} > #{shared_path}/#{encrypted_file} && openssl enc -aes-256-cbc -d -pbkdf2 -in #{shared_path}/#{encrypted_file} -out #{shared_path}/#{decrypted_file_tmp} -pass pass:#{encryption_key}"
52
+
53
+ # Read the secrets from the temporary cap-secrets-tmp.txt file
54
+ secrets = {}
55
+ capture(:cat, "#{shared_path}/#{decrypted_file_tmp}").each_line do |line|
56
+ key, value = line.strip.split('=', 2)
57
+ secrets[key] = value.delete('"')
58
+ end
59
+
60
+ # Clean up the temporary files
61
+ execute "rm #{shared_path}/#{encrypted_file} && rm #{shared_path}/#{decrypted_file_tmp}"
62
+
63
+ # Replace the placeholders in the .env file with the actual secrets
64
+ decrypted_lines = env_file.each_line.map do |line|
65
+ line.gsub(/CAP_ENCRYPTED_SECRETS\[(.*?)\]/) do
66
+ secrets[$1]
67
+ end
68
+ end
69
+
70
+ # Write the modified .env file back to the server
71
+ execute :echo, "'#{decrypted_lines.join}' > #{shared_path}/.env.tmp", verbosity: :DEBUG
72
+ end
73
+ end
74
+ namespace :local do
75
+ desc 'Encrypt a local file'
76
+ task :encrypt_file do
77
+ invoke! "env:local:check:files:exist"
78
+ use_local_path = fetch(:local_path, fetch(:default_local_path))
79
+ Dir.chdir(use_local_path) do
80
+ encryption_key_file = fetch(:encryption_key_file, fetch(:default_encryption_key_file))
81
+ file = fetch(:file_to_encrypt, fetch(:default_file_to_encrypt))
82
+ base64_file = fetch(:file_to_decrypt, fetch(:default_file_to_decrypt))
83
+ encrypted_file = base64_file.gsub('.b64', '')
84
+
85
+ key = File.read(encryption_key_file).strip
86
+
87
+ # Encrypt the file
88
+ system("openssl enc -aes-256-cbc -pbkdf2 -in #{file} -out #{encrypted_file} -k #{key}")
89
+ # Encode the encrypted file with base64
90
+ system("base64 -i #{encrypted_file} -o #{base64_file}")
91
+ # Remove tmp file
92
+ system("rm #{encrypted_file}")
93
+
94
+ puts "File #{use_local_path}/#{file} has been encrypted to #{use_local_path}/#{encrypted_file} and base64-encoded to #{use_local_path}/#{base64_file}"
95
+ end
96
+ end
97
+
98
+ desc 'Decrypt a local file'
99
+ task :decrypt_file do
100
+ invoke! "env:local:check:files:exist"
101
+ use_local_path = fetch(:local_path, fetch(:default_local_path))
102
+ Dir.chdir(use_local_path) do
103
+ encryption_key_file = fetch(:encryption_key_file, fetch(:default_encryption_key_file))
104
+ base64_file = fetch(:file_to_decrypt, fetch(:default_file_to_decrypt))
105
+ encrypted_file = base64_file.gsub('.b64', '')
106
+ decrypted_file = fetch(:file_to_encrypt, fetch(:default_file_to_encrypt))
107
+
108
+ unless File.exist?(base64_file)
109
+ puts "Nothing to decrypt. Run `env:local:encrypt_file` first - to generate initial files with a random encryption key"
110
+ else
111
+ key = File.read(encryption_key_file).strip
112
+
113
+ # Decode the base64 file
114
+ system("base64 -d -i #{base64_file} -o #{encrypted_file}")
115
+ # Decrypt the file
116
+ system("openssl enc -d -aes-256-cbc -pbkdf2 -in #{encrypted_file} -out #{decrypted_file} -k #{key}")
117
+ # Remove tmp file
118
+ system("rm #{encrypted_file}")
119
+
120
+ puts "File #{use_local_path}/#{base64_file} has been base64-decoded to tmp file #{use_local_path}/#{encrypted_file} and decrypted to #{use_local_path}/#{decrypted_file}"
121
+ end
122
+ end
123
+ end
124
+ task "secrets" do
125
+ invoke! "env:local:check:files:exist"
126
+ use_local_path = fetch(:local_path, fetch(:default_local_path))
127
+ Dir.chdir(use_local_path) do
128
+ file = fetch(:file_to_encrypt, fetch(:default_file_to_encrypt))
129
+ puts "Contents of file #{use_local_path}/#{file}:\n\n"
130
+ system("cat #{file}")
131
+ end
132
+ end
133
+ task "check:files:exist" do
134
+ use_local_path = fetch(:local_path, fetch(:default_local_path))
135
+ unless Dir.exist?(use_local_path)
136
+ raise "Directory `#{use_local_path}` does not exist. create it first"
137
+ end
138
+ Dir.chdir(use_local_path) do
139
+ encryption_key_file = fetch(:encryption_key_file, fetch(:default_encryption_key_file))
140
+ file = fetch(:file_to_encrypt, fetch(:default_file_to_encrypt))
141
+
142
+ # Create encryption key file if it doesn't exist
143
+ unless File.exist?(encryption_key_file)
144
+ key = Array.new(40) { rand(65..90).chr }.join
145
+ File.write(encryption_key_file, key)
146
+ puts "Encryption key file #{encryption_key_file} created with a 40-character random key."
147
+ else
148
+ key = File.read(encryption_key_file).strip
149
+ end
150
+
151
+ # Create file to encrypt if it doesn't exist
152
+ unless File.exist?(file)
153
+ File.write(file, "ABC=\"def\"\n")
154
+ puts "File to encrypt #{file} created with default content."
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,60 @@
1
+
2
+ namespace "mysql" do
3
+ task "start" do
4
+ on release_roles(:mysql) do
5
+ sudo "systemctl start mysql", raise_on_non_zero_exit: false
6
+ end
7
+ end
8
+ task "stop" do
9
+ on release_roles(:mysql) do
10
+ sudo "systemctl stop mysql", raise_on_non_zero_exit: false
11
+ end
12
+ end
13
+ task "restart" do
14
+ on release_roles(:mysql), in: :sequence, wait: 5 do
15
+ sudo "systemctl restart mysql", raise_on_non_zero_exit: false
16
+ end
17
+ end
18
+ task "status" do
19
+ on release_roles(:mysql) do
20
+ sudo "systemctl status mysql", raise_on_non_zero_exit: false
21
+ end
22
+ end
23
+ task "cfg:show" do
24
+ on release_roles(:mysql) do
25
+ execute 'cat /etc/mysql/mysql.conf.d/mysqld.cnf | egrep -v "^\s*(#|$)"', raise_on_non_zero_exit: false # filter ` space + # ` too
26
+ end
27
+ end
28
+ task "cfg:show:auto" do
29
+ on release_roles(:mysql) do
30
+ sudo 'cat /var/lib/mysql/auto.cnf', raise_on_non_zero_exit: false
31
+ end
32
+ end
33
+ task "tail" do
34
+ on release_roles(:mysql) do
35
+ sudo "tail /var/log/mysql/error.log -f -n 1", raise_on_non_zero_exit: false
36
+ end
37
+ end
38
+ task "tail:multi" do
39
+ on release_roles(:mysql) do
40
+ sudo "tail /var/log/syslog /var/log/mysql/error.log -f -n 1", raise_on_non_zero_exit: false
41
+ end
42
+ end
43
+ task "ls:logs" do
44
+ on release_roles(:mysql) do
45
+ sudo "ls -lah /var/log/mysql/", raise_on_non_zero_exit: false
46
+ end
47
+ end
48
+ task "ps" do
49
+ on release_roles(:mysql) do
50
+ execute 'ps aux | grep /usr/sbin/mysqld', raise_on_non_zero_exit: false
51
+ end
52
+ end
53
+ task "size" do
54
+ on release_roles(:mysql) do
55
+ sudo "du -msh /var/lib/mysql", raise_on_non_zero_exit: false
56
+ end
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,27 @@
1
+ namespace "nginx" do
2
+ task "start" do
3
+ on release_roles(:nginx) do
4
+ sudo "systemctl start nginx.service"
5
+ end
6
+ end
7
+ task "stop" do
8
+ on release_roles(:nginx) do
9
+ sudo "systemctl stop nginx.service"
10
+ end
11
+ end
12
+ task "reload" do
13
+ on release_roles(:nginx) do
14
+ sudo "systemctl reload nginx.service"
15
+ end
16
+ end
17
+ task "restart" do
18
+ on release_roles(:nginx) do
19
+ sudo "systemctl restart nginx.service"
20
+ end
21
+ end
22
+ task "status" do
23
+ on release_roles(:nginx) do
24
+ sudo "systemctl status nginx.service"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ namespace "supervisor" do
2
+ task "start" do
3
+ on release_roles(:supervisor) do
4
+ sudo "supervisorctl start all", raise_on_non_zero_exit: false
5
+ end
6
+ end
7
+ task "stop" do
8
+ on release_roles(:supervisor) do
9
+ sudo "supervisorctl stop all", raise_on_non_zero_exit: false
10
+ end
11
+ end
12
+ task "restart" do
13
+ on release_roles(:supervisor) do
14
+ invoke! "supervisor:stop"
15
+ invoke! "supervisor:start"
16
+ end
17
+ end
18
+ task "reread" do
19
+ on release_roles(:supervisor) do
20
+ sudo "supervisorctl reread", raise_on_non_zero_exit: false
21
+ end
22
+ end
23
+ task "update" do
24
+ on release_roles(:supervisor) do
25
+ sudo "supervisorctl update", raise_on_non_zero_exit: false
26
+ end
27
+ end
28
+ task "status" do
29
+ on release_roles(:supervisor) do
30
+ sudo "supervisorctl status", raise_on_non_zero_exit: false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,145 @@
1
+
2
+ task "php" do
3
+ on release_roles(:fpm) do
4
+ execute "hostname && php -v"
5
+ end
6
+ end
7
+ task "composer" do
8
+ on release_roles(:fpm) do
9
+ execute "hostname && sudo runuser -u www-data -- composer --version"
10
+ end
11
+ end
12
+
13
+ task "hostname" do
14
+ on release_roles(:app) do execute "hostname" end
15
+ end
16
+ task "cpu" do
17
+ on release_roles(:app) do
18
+ execute "hostname && cat /proc/cpuinfo | egrep 'model name|MHz'"
19
+ end
20
+ end
21
+ task "uptime" do
22
+ on release_roles(:app) do
23
+ execute "hostname && uptime"
24
+ end
25
+ end
26
+ task "kernel" do
27
+ on release_roles(:app) do
28
+ execute "hostname && lsb_release -a && uname -a"
29
+ end
30
+ end
31
+
32
+ task "hosts" do
33
+ on release_roles(:app) do
34
+ execute "hostname && cat /etc/hosts"
35
+ end
36
+ end
37
+
38
+ task "ufw:status" do
39
+ on release_roles(:all) do
40
+ sudo "ufw status verbose"
41
+ end
42
+ end
43
+
44
+ task "haproxy:version" do
45
+ on release_roles(:haproxy) do
46
+ execute "haproxy -v"
47
+ end
48
+ end
49
+ task "ssh:version" do
50
+ on release_roles(:all) do
51
+ execute "ssh -V"
52
+ end
53
+ end
54
+ task "xz:version" do
55
+ on release_roles(:all) do
56
+ execute "xz -V"
57
+ end
58
+ end
59
+
60
+ namespace "list" do
61
+ task "users" do
62
+ on release_roles(:app) do
63
+ execute "ls -lah /home", raise_on_non_zero_exit: false
64
+ end
65
+ end
66
+ task "supervisor" do
67
+ on release_roles(:supervisor) do
68
+ execute "ls -lah /etc/supervisor/conf.d/* && ls -lah /etc/supervisor/conf.d/*/", raise_on_non_zero_exit: false
69
+ end
70
+ end
71
+ end
72
+
73
+ # redis
74
+ namespace "redis" do
75
+ task "cfg:show" do
76
+ on release_roles(:redis) do
77
+ sudo 'cat /etc/redis/redis.conf | egrep -v "^\s*(#|$)"', raise_on_non_zero_exit: false # filter ` space + # ` too
78
+ end
79
+ end
80
+ task "version" do
81
+ on release_roles(:redis) do
82
+ execute 'redis-server --version', raise_on_non_zero_exit: false
83
+ end
84
+ end
85
+ end
86
+
87
+ # systemctl
88
+ namespace "systemctl" do
89
+ task "daemon-reload" do
90
+ on release_roles(:all) do
91
+ sudo "systemctl daemon-reload", raise_on_non_zero_exit: false
92
+ end
93
+ end
94
+ task "reboot" do
95
+ on release_roles(:all) do
96
+ sudo "systemctl reboot", raise_on_non_zero_exit: false
97
+ end
98
+ end
99
+ end
100
+
101
+ # system
102
+ namespace "system" do
103
+ # disk_space
104
+ namespace "disk_space" do
105
+ task "all" do
106
+ invoke! "system:disk_space:df"
107
+ invoke! "system:disk_space:zfs"
108
+ invoke! "system:disk_space:btrfs"
109
+ end
110
+ task "df" do
111
+ on release_roles(:all) do
112
+ execute "df -HT"
113
+ end
114
+ end
115
+ task "zfs" do
116
+ on release_roles(:all) do
117
+ execute "sudo zpool list"
118
+ end
119
+ end
120
+ task "btrfs" do
121
+ on release_roles(:all) do
122
+ execute "sudo btrfs filesystem show"
123
+ end
124
+ end
125
+ end # end disk_space
126
+ # connections
127
+ namespace "connections:count" do
128
+ task "total" do
129
+ on release_roles(:app) do
130
+ execute "hostname && netstat -ant | grep ESTABLISHED | wc -l", raise_on_non_zero_exit: false
131
+ end
132
+ end
133
+ task "per_address" do
134
+ on release_roles(:app) do
135
+ execute "hostname && netstat -natu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n", raise_on_non_zero_exit: false
136
+ end
137
+ end
138
+ task "via_ss" do
139
+ on release_roles(:app) do
140
+ execute "hostname && ss -s", raise_on_non_zero_exit: false
141
+ end
142
+ end
143
+ end # end connections
144
+ end # end system
145
+
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module Addon
5
+ module Fm
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "fm/version"
4
+
5
+ # Load all .rake files from the tasks directory
6
+ Dir.glob(File.expand_path("./fm/tasks/**/*.rake", __dir__)).each { |r| load r }
7
+
8
+ module Capistrano
9
+ module Addon
10
+ module Fm
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "addon/fm"
4
+
5
+ module Capistrano
6
+ module Addon
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Capistrano
2
+ module Addon
3
+ module Fm
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-addon-fm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florin Motoc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: capistrano addon - generic tasks - by FlorinMotoc
28
+ email:
29
+ - gems@mflorin.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/capistrano/addon.rb
40
+ - lib/capistrano/addon/fm.rb
41
+ - lib/capistrano/addon/fm/tasks/custom.rake
42
+ - lib/capistrano/addon/fm/tasks/env-with-secrets.rake
43
+ - lib/capistrano/addon/fm/tasks/mysql.rake
44
+ - lib/capistrano/addon/fm/tasks/nginx.rake
45
+ - lib/capistrano/addon/fm/tasks/supervisor.rake
46
+ - lib/capistrano/addon/fm/tasks/system.rake
47
+ - lib/capistrano/addon/fm/version.rb
48
+ - sig/capistrano/addon/fm.rbs
49
+ homepage: https://github.com/FlorinMotoc/capistrano-addon-fm
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/FlorinMotoc/capistrano-addon-fm
54
+ source_code_uri: https://github.com/FlorinMotoc/capistrano-addon-fm
55
+ changelog_uri: https://github.com/FlorinMotoc/capistrano-addon-fm/blob/main/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.6.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.3.11
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: capistrano addon - generic tasks
75
+ test_files: []