Commit 8cbc4768c2b41cdfe8acf3f0119c46ddf3d3fdb0
1 parent
0537c0fa
Exists in
kalibro-configurations
Adds kalibro-configurations spec
Showing
1 changed file
with
110 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,110 @@ |
1 | +Name: kalibro-configurations | |
2 | +Version: 1.0.0.backport | |
3 | +Release: 1%{?dist} | |
4 | +Summary: Mezuro metrics management backend | |
5 | +Group: Development/Tools | |
6 | +License: AGPLv3 | |
7 | +URL: https://github.com/mezuro/kalibro_configurations | |
8 | +Source0: %{name}-%{version}.tar.gz | |
9 | +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) | |
10 | +BuildArch: noarch | |
11 | +BuildRequires: kalibro-configurations-deps | |
12 | +Requires: kalibro-configurations-deps, rubygem-bundler | |
13 | + | |
14 | +%description | |
15 | + | |
16 | +%prep | |
17 | +%setup -q | |
18 | + | |
19 | +%build | |
20 | +ln -sf /usr/lib/kalibro_configurations/Gemfile . | |
21 | +ln -sf /usr/lib/kalibro_configurations/Gemfile.lock . | |
22 | +ln -sf /usr/lib/kalibro_configurations/.bundle . | |
23 | +ln -sfT /usr/lib/kalibro_configurations/vendor/bundle vendor/bundle | |
24 | +rm -f Gemfile Gemfile.lock .bundle vendor/bundle | |
25 | +rm -rf tmp log | |
26 | +%install | |
27 | +mkdir -p %{buildroot}/usr/lib/kalibro-configurations | |
28 | +cp -r * %{buildroot}/usr/lib/kalibro-configurations | |
29 | +rm -rf %{buildroot}/usr/lib/kalibro-configurations/log | |
30 | +ln -sfT /var/log/kalibro-configurations %{buildroot}/usr/lib/kalibro-configurations/log | |
31 | +ln -sfT /etc/kalibro-configurations/database.yml %{buildroot}/usr/lib/kalibro-configurations/config/database.yml | |
32 | +mkdir -p %{buildroot}/lib/systemd/system | |
33 | +cat >> %{buildroot}/lib/systemd/system/kalibro-configurations.service <<EOF | |
34 | +[Unit] | |
35 | +Description=kalibro-configurations | |
36 | +After=network.target | |
37 | + | |
38 | +[Service] | |
39 | +Type=simple | |
40 | +EnvironmentFile=-/etc/sysconfig/kalibro-configurations | |
41 | +User=kalibro-configurations | |
42 | +WorkingDirectory=/usr/lib/kalibro-configurations | |
43 | +ExecStart=bundle exec rails s -p 8083 | |
44 | +[Install] | |
45 | +WantedBy=multi-user.target | |
46 | +EOF | |
47 | +mkdir -p %{buildroot}/etc/kalibro-configurations | |
48 | +cat >> %{buildroot}/etc/kalibro-configurations/database.yml << EOF | |
49 | +production: | |
50 | + adapter: postgresql | |
51 | + encoding: unicode | |
52 | + database: kalibro_configurations_production | |
53 | + pool: 10 | |
54 | + username: kalibro_configurations | |
55 | + password: | |
56 | +EOF | |
57 | + | |
58 | +#FIXME HACK, REMOVE LATER | |
59 | +sed -i -e "s/require.*database_cleaner/# &/" %{buildroot}/usr/lib/kalibro-configurations/app/controllers/tests_controller.rb | |
60 | + | |
61 | + | |
62 | +%post | |
63 | +groupadd kalibro_configurations || true | |
64 | +if ! id kalibro_configurations; then | |
65 | + adduser kalibro_configurations --system -g kalibro_configurations --shell /bin/sh --home-dir /usr/lib/kalibro-configurations | |
66 | +fi | |
67 | +mkdir -p /var/log/kalibro-configurations | |
68 | +chown -R kalibro_configurations:kalibro_configurations /var/log/kalibro-configurations | |
69 | + | |
70 | + | |
71 | +if [ -x /usr/bin/postgres ]; then | |
72 | + if [ `systemctl is-active postgresql`!="active" ]; then | |
73 | + postgresql-setup initdb || true | |
74 | + systemctl start postgresql | |
75 | + fi | |
76 | + | |
77 | + if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(*) from pg_user where usename = 'kalibro_configurations';")" -eq 0 ]; then | |
78 | + # create user | |
79 | + sudo -u postgres -i createuser kalibro_configurations | |
80 | + fi | |
81 | + | |
82 | + if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(1) from pg_database where datname = 'kalibro_configurations_production';")" -eq 0 ]; then | |
83 | + # create database | |
84 | + sudo -u postgres -i createdb --owner=kalibro_configurations kalibro_configurations_production | |
85 | + fi | |
86 | + | |
87 | + cd /usr/lib/kalibro-configurations/ | |
88 | + su kalibro_configurations -c "RAILS_ENV=production bundle exec rake db:migrate" | |
89 | + if [ $1 -eq 1 ]; then | |
90 | + su kalibro_configurations -c "RAILS_ENV=production bundle exec rake db:seed" | |
91 | + fi | |
92 | +fi | |
93 | + | |
94 | +if [ $1 -gt 1 ]; then | |
95 | + echo 'Restarting kalibro-configurations' | |
96 | + systemctl daemon-reload | |
97 | + systemctl try-restart kalibro-configurations | |
98 | +fi | |
99 | + | |
100 | +%clean | |
101 | +rm -rf %{buildroot} | |
102 | + | |
103 | +%files | |
104 | +%defattr(-,root,root,-) | |
105 | +%doc | |
106 | +/usr/lib/kalibro-configurations | |
107 | +/lib/systemd/system/kalibro-configurations.service | |
108 | +%config(noreplace) /etc/kalibro-configurations/database.yml | |
109 | + | |
110 | +%changelog | ... | ... |