Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit ec7ac26

Browse files
committed
Merge pull request #110 from bflad/release/v4.0
Add DIY backup and Move pid file
2 parents e4b72af + 94591ae commit ec7ac26

File tree

13 files changed

+267
-31
lines changed

13 files changed

+267
-31
lines changed

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,57 @@ url | URL for Stash install | String | auto-detected (see attributes/default.rb)
5858
user | user to run Stash | String | stash
5959
version | Stash version to install | String | 3.10.2
6060

61-
### Stash Backup Client Attributes
61+
### Stash Backup Attributes (Shared)
6262

63-
These attributes are under the `node['stash']['backup_client']` namespace. Some of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
63+
These attributes are under the `node['stash']['backup']` namespace. Some of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
6464

6565
Attribute | Description | Type | Default
6666
----------|-------------|------|--------
6767
backup_path | Path for backups | String | /tmp
6868
baseurl | Stash base URL | String | `https://#{node['fqdn']}/`
69-
checksum | SHA256 checksum for Stash Backup Client install | String | auto-detected (see attributes/default.rb)
70-
install_path | location to install Stash Backup Client | String | /opt/atlassian-stash-backup-client
7169
password | Stash administrative user password | String | changeit
72-
url_base | URL base for Stash Backup Client install | String | http://downloads.atlassian.com/software/stash/downloads/stash-backup-distribution
70+
strategy | [Stash backup strategy](https://confluence.atlassian.com/display/STASH/Data+recovery+and+backups#Datarecoveryandbackups-TwowaystobackupStash): 'backup_client' or 'backup_diy' | String | backup_client
7371
user | Stash administrative user | String | admin
72+
73+
### Stash Backup Client Attributes
74+
Documentation: [Using the Stash Backup Client](https://confluence.atlassian.com/display/STASH/Using+the+Stash+Backup+Client)
75+
76+
These attributes are under the `node['stash']['backup_client']` namespace. Some of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
77+
78+
Attribute | Description | Type | Default
79+
----------|-------------|------|--------
80+
checksum | SHA256 checksum for Stash Backup Client install | String | auto-detected (see attributes/default.rb)
81+
install_path | location to install Stash Backup Client | String | /opt/atlassian/stash-backup-client
82+
url_base | URL base for Stash Backup Client install | String | http://downloads.atlassian.com/software/stash/downloads/stash-backup-distribution
7483
version | Stash Backup Client version to install | String | 1.9.1
7584

76-
### Stash Backup Client Cron Attributes
85+
### Stash DIY Backup Attributes
86+
Documentation: [Using Stash DIY Backup](https://confluence.atlassian.com/display/STASH/Using+Stash+DIY+Backup)
87+
88+
These attributes are under the `node['stash']['backup_diy']` namespace. Some of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
7789

78-
These attributes are under the `node['stash']['backup_client']['cron']` namespace. All of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
90+
Attribute | Description | Type | Default
91+
----------|-------------|------|--------
92+
backup_archive_type | The way how to backup the stash home | String | tar
93+
backup_home_type | The way how to backup the stash home | String | rsync
94+
exclude_repos | List of repo IDs which should be excluded from the backup | List | []
95+
gpg_recipient | GPG recipient name (only if `['backup_archive_type]'` is `'tar-gpg'`) | String | ""
96+
install_path | location to place Stash DIY Backup scripts | String | /opt/atlassian/stash-diy-backup
97+
hipchat_room | HipChat room where notifications should be sent | String | ""
98+
hipchat_token | Authorization token for the HipChat server | String | ""
99+
hipchat_url | URL to the HipChat server for sending notifications | String | 'https://api.hipchat.com'
100+
repo_url | Git repository URL where Stash DIY Backup scripts are stored | String | https://bitbucket.org/atlassianlabs/atlassian-stash-diy-backup.git
101+
revision | Git revision (or a branch, or a tag) wich should be checked out | String | master
102+
temp_path | A temporary path where backup essentials should be placed before packing to the archive | String | /tmp/stash-backup-temp
103+
verbose | Should the script output be verbose or not | Boolean | true
104+
105+
### Stash Backup Cron Attributes
106+
107+
These attributes are under the `node['stash']['backup']['cron']` namespace. All of these attributes are overridden by `stash/stash` encrypted data bag (Hosted Chef) or data bag (Chef Solo), if it exists.
79108

80109
Attribute | Description | Type | Default
81110
----------|-------------|------|--------
111+
enable | Configure cron job to backup Stash periodically | Boolean | false
82112
day | Day of month | String | *
83113
hour | Hour of day | String | 0
84114
minute | Minute of hour | String | 0

attributes/default.rb

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,20 @@
135135
default['stash']['apache2']['ssl']['key_file'] = '/etc/ssl/private/ssl-cert-snakeoil.key'
136136
end
137137

138-
default['stash']['backup_client']['backup_path'] = '/tmp'
139-
default['stash']['backup_client']['baseurl'] = "https://#{node['fqdn']}/"
138+
default['stash']['backup']['strategy'] = 'backup_client'
139+
140+
default['stash']['backup']['backup_path'] = '/tmp'
141+
default['stash']['backup']['baseurl'] = "https://#{node['fqdn']}/"
142+
default['stash']['backup']['password'] = 'changeit'
143+
default['stash']['backup']['user'] = 'admin'
144+
145+
default['stash']['backup']['cron']['enable'] = false
146+
default['stash']['backup']['cron']['day'] = '*'
147+
default['stash']['backup']['cron']['hour'] = '0'
148+
default['stash']['backup']['cron']['minute'] = '0'
149+
default['stash']['backup']['cron']['month'] = '*'
150+
default['stash']['backup']['cron']['weekday'] = '*'
151+
140152
default['stash']['backup_client']['install_path'] = node['stash']['install_path']
141153
default['stash']['backup_client']['password'] = 'changeit'
142154
default['stash']['backup_client']['user'] = 'admin'
@@ -177,11 +189,20 @@
177189
when '1.9.1' then '3cdad3393611d2c8d151c7d265ebd04764cbaba4a4d745a8b534dd9b8cf77d7b'
178190
end
179191

180-
default['stash']['backup_client']['cron']['day'] = '*'
181-
default['stash']['backup_client']['cron']['hour'] = '0'
182-
default['stash']['backup_client']['cron']['minute'] = '0'
183-
default['stash']['backup_client']['cron']['month'] = '*'
184-
default['stash']['backup_client']['cron']['weekday'] = '*'
192+
default['stash']['backup_diy']['install_path'] = "#{node['stash']['install_path']}/stash-diy-backup"
193+
default['stash']['backup_diy']['repo_url'] = 'https://bitbucket.org/atlassianlabs/atlassian-stash-diy-backup.git'
194+
default['stash']['backup_diy']['revision'] = 'master'
195+
196+
default['stash']['backup_diy']['backup_home_type'] = 'rsync'
197+
default['stash']['backup_diy']['backup_archive_type'] = 'tar'
198+
default['stash']['backup_diy']['exclude_repos'] = []
199+
default['stash']['backup_diy']['gpg_recipient'] = ''
200+
default['stash']['backup_diy']['temp_path'] = '/tmp/stash-backup-temp'
201+
default['stash']['backup_diy']['verbose'] = true
202+
203+
default['stash']['backup_diy']['hipchat_url'] = 'https://api.hipchat.com'
204+
default['stash']['backup_diy']['hipchat_room'] = ''
205+
default['stash']['backup_diy']['hipchat_token'] = ''
185206

186207
default['stash']['database']['type'] = 'mysql'
187208
default['stash']['database']['version'] = '5.6'

libraries/stash.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ def self.default_database_port(type)
4444
nil
4545
end
4646
end
47+
48+
def self.check_for_old_attributes!(node)
49+
backup_attrs = %w(backup_path baseurl password user cron)
50+
backup_attrs.each do |attr|
51+
unless node['stash']['backup_client'][attr].nil?
52+
node.default['stash']['backup_client'][attr] = node['stash']['backup'][attr]
53+
Chef::Log.warn "node['stash']['backup_client']['#{attr}'] has been changed to node['stash']['backup']['#{attr}']"
54+
end
55+
end
56+
Chef::Log.warn <<-EOH
57+
This renaming introduces the common approach for both of backup strategies:
58+
'backup_client' and 'backup_diy'. Attributes metioned above will be gracefully
59+
converted for you, but this warning and conversion will be removed in the next
60+
major release of the 'stash' cookbook.
61+
EOH
62+
end
4763
end
4864
end
4965
end

metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
depends 'mysql_connector'
3333
depends 'perl'
3434
depends 'postgresql'
35+
depends 'yum-epel'

recipes/backup_client.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Stash.check_for_old_attributes!(node)
12

23
settings = Stash.settings(node)
34

@@ -17,10 +18,28 @@
1718
template "#{node['stash']['home_path']}/backup-config.properties" do
1819
source 'backup-config.properties.erb'
1920
owner node['stash']['user']
20-
mode '0644'
21-
variables :backup_client => settings['backup_client']
21+
mode '0600'
22+
variables :backup => settings['backup']
2223
end
2324

2425
link "#{node['stash']['backup_client']['install_path']}/stash-backup-client/backup-config.properties" do
2526
to "#{node['stash']['home_path']}/backup-config.properties"
2627
end
28+
29+
directory node['stash']['backup']['backup_path'] do
30+
owner node['stash']['user']
31+
mode '0750'
32+
action :create
33+
not_if { ::Dir.exist?(node['stash']['backup']['backup_path']) }
34+
end
35+
36+
cron_d 'atlassian-stash-backup-client' do
37+
hour settings['backup']['cron']['hour']
38+
minute settings['backup']['cron']['minute']
39+
day settings['backup']['cron']['day']
40+
month settings['backup']['cron']['month']
41+
weekday settings['backup']['cron']['weekday']
42+
command "java -jar #{node['stash']['backup_client']['install_path']}/stash-backup-client/stash-backup-client.jar"
43+
user node['stash']['user']
44+
action(settings['backup']['cron']['enable'] ? :create : :delete)
45+
end

recipes/backup_client_cron.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
Stash.check_for_old_attributes!(node)
2+
3+
Chef::Log.warn <<-EOH
4+
Recipe 'stash::backup_client_cron' is deprecated. Please, set attrite
5+
`node['stash']['backup']['crone']['enable'] = true` to configure crond to run
6+
Stash backup periodically. This recipe will be removed in the next major release
7+
of the 'stash' cookbook.
8+
EOH
19

210
settings = Stash.settings(node)
311

412
cron_d 'atlassian-stash-backup-client' do
5-
hour settings['backup_client']['cron']['hour']
6-
minute settings['backup_client']['cron']['minute']
7-
day settings['backup_client']['cron']['day']
8-
month settings['backup_client']['cron']['month']
9-
weekday settings['backup_client']['cron']['weekday']
13+
hour settings['backup']['cron']['hour']
14+
minute settings['backup']['cron']['minute']
15+
day settings['backup']['cron']['day']
16+
month settings['backup']['cron']['month']
17+
weekday settings['backup']['cron']['weekday']
1018
command "java -jar #{node['stash']['backup_client']['install_path']}/stash-backup-client/stash-backup-client.jar"
1119
user node['stash']['user']
20+
action(settings['backup']['cron']['enable'] ? :create : :delete)
1221
end

recipes/backup_diy.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Stash.check_for_old_attributes!(node)
2+
3+
settings = Stash.settings(node)
4+
5+
include_recipe 'yum-epel' if node['platform_family'] == 'rhel'
6+
7+
package 'jq'
8+
package 'perl-Time-Piece' if node['platform_family'] == 'rhel'
9+
package 'rsync'
10+
11+
directory node['stash']['backup_diy']['install_path'] do
12+
owner node['stash']['user']
13+
mode 00755
14+
action :create
15+
recursive true
16+
end
17+
18+
git 'stash-diy-backup' do
19+
repository node['stash']['backup_diy']['repo_url']
20+
revision node['stash']['backup_diy']['revision']
21+
destination node['stash']['backup_diy']['install_path']
22+
user node['stash']['user']
23+
end
24+
25+
template "#{node['stash']['backup_diy']['install_path']}/stash.diy-backup.vars.sh" do
26+
source 'backup-diy-vars.sh.erb'
27+
owner node['stash']['user']
28+
mode '0600'
29+
variables(
30+
:backup => settings['backup'],
31+
:backup_diy => settings['backup_diy'],
32+
:database => settings['database']
33+
)
34+
end
35+
36+
directory node['stash']['backup']['backup_path'] do
37+
owner node['stash']['user']
38+
mode '0750'
39+
action :create
40+
not_if { ::Dir.exist?(node['stash']['backup']['backup_path']) }
41+
end
42+
43+
cron_d 'atlassian-stash-diy-backup' do
44+
hour settings['backup']['cron']['hour']
45+
minute settings['backup']['cron']['minute']
46+
day settings['backup']['cron']['day']
47+
month settings['backup']['cron']['month']
48+
weekday settings['backup']['cron']['weekday']
49+
command "#{node['stash']['backup_diy']['install_path']}/stash.diy-backup.sh"
50+
user node['stash']['user']
51+
action(settings['backup']['cron']['enable'] ? :create : :delete)
52+
end

recipes/default.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
include_recipe 'stash::tomcat_configuration'
1616
include_recipe 'stash::apache2'
1717
include_recipe "stash::service_#{node['stash']['service_type']}"
18-
include_recipe 'stash::backup_client' if node['stash']['backup_client']['version']
18+
19+
case node['stash']['backup']['strategy']
20+
when 'backup_client'
21+
include_recipe 'stash::backup_client'
22+
when 'backup_diy'
23+
include_recipe 'stash::backup_diy'
24+
end

recipes/tomcat_configuration.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@
4545
mode '0644'
4646
notifies :restart, 'service[stash]', :delayed
4747
end
48+
49+
directory '/var/run/stash' do
50+
owner 'stash'
51+
group 'stash'
52+
mode '0755'
53+
action :create
54+
end

templates/default/3.8+/setenv.sh.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ fi
288288
# set the location of the pid file
289289
if [ -z "$CATALINA_PID" ] ; then
290290
if [ -n "$CATALINA_BASE" ] ; then
291-
CATALINA_PID="$CATALINA_BASE"/work/catalina.pid
291+
CATALINA_PID=/var/run/stash/catalina.pid
292292
elif [ -n "$CATALINA_HOME" ] ; then
293-
CATALINA_PID="$CATALINA_HOME"/work/catalina.pid
293+
CATALINA_PID=/var/run/stash/catalina.pid
294294
fi
295295
fi
296296
export CATALINA_PID

0 commit comments

Comments
 (0)