icingadb.spec 4.89 KB
Newer Older
Alexander A. Klimov's avatar
Alexander A. Klimov committed
1 2
%define revision 1

3
%global provider        github
4
%global provider_tld    com
5
%global project         Icinga
6 7 8 9
%global repo            icingadb
%global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo}
%global import_path     %{provider_prefix}

10
%global golang_min_version 1.11
Markus Frosch's avatar
Markus Frosch committed
11 12 13 14 15 16

%if "%{_vendor}" == "suse"
%global golang_pkg      go
%else # suse
%global golang_pkg      golang
%endif # suse
17 18 19 20 21 22 23 24 25 26 27 28 29 30

%if 0%{?golang_scl:1}
%global golang_scl_prefix %{golang_scl}-
%global golang_scl_enable scl enable %{golang_scl} --
%endif

%if ! 0%{?gobuild:1}
%define gobuild(o:) %{?golang_scl_enable} go build -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n')" -a -v -x %{?**};
%endif

%if ! 0%{?gopath:1}
%define gopath %(%{?golang_scl_enable} go env GOPATH)
%endif

Alexander A. Klimov's avatar
Alexander A. Klimov committed
31
Name:       icingadb
32
Version:    0.0.0
Alexander A. Klimov's avatar
Alexander A. Klimov committed
33 34 35
Release:    %{revision}%{?dist}
Summary:    Icinga DB
Group:      System Environment/Daemons
Markus Frosch's avatar
Markus Frosch committed
36 37 38
%if "%{_vendor}" == "suse"
License:    GPL-2.0-or-later
%else
Markus Frosch's avatar
Markus Frosch committed
39
License:    GPLv2+
Markus Frosch's avatar
Markus Frosch committed
40
%endif # suse
41
URL:        https://%{provider_prefix}
42
Source0:    https://%{import_path}/archive/v%{version}.tar.gz
Alexander A. Klimov's avatar
Alexander A. Klimov committed
43

Henrik Triem's avatar
Henrik Triem committed
44 45 46 47
Source1:    icingadb-redis.service.suse
Source2:    icingadb-redis.service.rhel
Source3:    icingadb-redis.conf

Alexander A. Klimov's avatar
Alexander A. Klimov committed
48
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}
49

Markus Frosch's avatar
Markus Frosch committed
50
BuildRequires:  %{?golang_scl_prefix}%{golang_pkg} >= %{golang_min_version}
51
BuildRequires:  git
Alexander A. Klimov's avatar
Alexander A. Klimov committed
52 53 54 55

%{?systemd_requires}
BuildRequires:  systemd

Noah Hilverling's avatar
Noah Hilverling committed
56 57
%define debug_package %nil

Noah Hilverling's avatar
Noah Hilverling committed
58 59
Requires:       icinga-redis

60
%if "%{_vendor}" == "suse"
61 62 63 64 65 66 67
PreReq:         permissions
Provides:       user(icingadb)
Provides:       group(icingadb)
Requires(pre):  shadow
Requires(post): shadow
%else # suse
Requires(pre):  shadow-utils
Markus Frosch's avatar
Markus Frosch committed
68
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
69 70 71 72 73 74 75

%define configdir %{_sysconfdir}/%{name}
%define service %{name}.service

%description
Icinga DB

Henrik Triem's avatar
Henrik Triem committed
76 77 78 79 80 81 82 83
%package redis
Summary:	Icinga Redis for Icinga DB
Group:          System/Monitoring
Requires:	icinga-redis

%description redis
Redis service for Icinga DB.

Alexander A. Klimov's avatar
Alexander A. Klimov committed
84
%prep
85
%setup -q
Alexander A. Klimov's avatar
Alexander A. Klimov committed
86 87

%build
Noah Hilverling's avatar
Noah Hilverling committed
88
export GO111MODULE=on
89 90 91 92 93 94 95 96

%gobuild .

%check
%if ! 0%{?gotest:1}
%global gotest %{?golang_scl_enable} go test
%endif

Noah Hilverling's avatar
Noah Hilverling committed
97
#%%gotest ./...
Alexander A. Klimov's avatar
Alexander A. Klimov committed
98 99

%install
100 101 102 103 104
install -d -m 0755 %{buildroot}%{_sbindir}
install -d -m 0755 %{buildroot}%{configdir}
install -d -m 0755 %{buildroot}%{_unitdir}

install -m 0755 icingadb %{buildroot}%{_sbindir}/
105
install -m 0644 icingadb.ini %{buildroot}%{configdir}/icingadb.ini
106
install -m 0644 etc/%{service} %{buildroot}%{_unitdir}/
Alexander A. Klimov's avatar
Alexander A. Klimov committed
107

Markus Frosch's avatar
Markus Frosch committed
108 109 110
install -d -m 0755 %{buildroot}%{_datadir}/%{name}
(umask 0022 && cp -rv etc/schema %{buildroot}%{_datadir}/%{name}/)

Markus Frosch's avatar
Markus Frosch committed
111 112 113 114
%if "%{_vendor}" == "suse"
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
%endif # suse

Henrik Triem's avatar
Henrik Triem committed
115 116 117 118 119 120 121 122 123 124
#%%install redis
# Install custom systemd service file for icingadb-redis. Source1 is SUSE, Source2 is RHEL.
%if "%{_vendor}" == "suse"
  install -D -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/icingadb-redis.service
%else
  install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/icingadb-redis.service
%endif

install -D -m 0640 %{SOURCE3} %{buildroot}%{_sysconfdir}/icinga-redis/icingadb-redis.conf

Alexander A. Klimov's avatar
Alexander A. Klimov committed
125 126 127 128
%pre
getent group icingadb >/dev/null || groupadd -r icingadb
getent passwd icingadb >/dev/null || useradd -r -g icingadb -d / -s /sbin/nologin -c 'Icinga DB' icingadb

Markus Frosch's avatar
Markus Frosch committed
129 130 131 132
%if "%{_vendor}" == "suse"
%service_add_pre %{service}
%endif # suse

Henrik Triem's avatar
Henrik Triem committed
133 134 135 136 137
%pre redis
%if "%{_vendor}" == "suse"
  %service_add_pre icingadb-redis.service
%endif

Alexander A. Klimov's avatar
Alexander A. Klimov committed
138
%post
Markus Frosch's avatar
Markus Frosch committed
139 140 141
%if "%{_vendor}" == "suse"
%service_add_post %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
142
%systemd_post %{service}
Markus Frosch's avatar
Markus Frosch committed
143
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
144

Henrik Triem's avatar
Henrik Triem committed
145 146 147 148 149 150 151 152 153
%post redis
%if "%{_vendor}" == "suse"
%fillup_only  icingadb-redis
%service_add_post icingadb-redis.service
%else
# rhel
%systemd_post icingadb-redis.service
%endif

Alexander A. Klimov's avatar
Alexander A. Klimov committed
154
%preun
Markus Frosch's avatar
Markus Frosch committed
155 156 157
%if "%{_vendor}" == "suse"
%service_del_preun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
158
%systemd_preun %{service}
Markus Frosch's avatar
Markus Frosch committed
159
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
160

Henrik Triem's avatar
Henrik Triem committed
161 162 163 164 165 166 167 168 169
%preun redis
# suse
%if "%{_vendor}" == "suse"
%service_del_preun icingadb-redis.service
%else # rhel
%systemd_preun icingadb-redis.service
%endif # suse / rhel
exit 0

Alexander A. Klimov's avatar
Alexander A. Klimov committed
170
%postun
Markus Frosch's avatar
Markus Frosch committed
171 172 173
%if "%{_vendor}" == "suse"
%service_del_postun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
174
%systemd_postun %{service}
Markus Frosch's avatar
Markus Frosch committed
175
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
176

Henrik Triem's avatar
Henrik Triem committed
177 178 179 180 181 182 183 184 185
%postun redis
# suse
%if "%{_vendor}" == "suse"
%service_del_postun icingadb-redis.service
%else # rhel
%systemd_postun_with_restart icingadb-redis.service
%endif # suse / rhel
exit 0

Alexander A. Klimov's avatar
Alexander A. Klimov committed
186 187 188 189 190
%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
191
#%%doc AUTHORS COPYING README.md
192 193 194
%{_sbindir}/icingadb
%{_unitdir}/%{service}

Markus Frosch's avatar
Markus Frosch committed
195 196 197 198
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

Markus Frosch's avatar
Markus Frosch committed
199 200 201
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/schema

202
%defattr(0640,icingadb,icingadb,0750)
203 204

%dir %{configdir}
205
%config(noreplace) %{configdir}/icingadb.ini
206

Henrik Triem's avatar
Henrik Triem committed
207 208 209 210 211 212
%files redis
%defattr(-,root,root,-)
#%%doc AUTHORS COPYING README.md
%config(noreplace) %attr(0640,icinga-redis,icinga-redis) %{_sysconfdir}/icinga-redis/icingadb-redis.conf
%attr(644,root,root) %{_unitdir}/icingadb-redis.service

213
%changelog
Henrik Triem's avatar
Henrik Triem committed
214
* Fri Dec 13 2019 Henrik Triem <henrik.triem@icinga.com> 0.0.0-1
215 216
* Mon Sep 24 2018 Markus Frosch <markus.frosch@icinga.com> 0.0.0-0
- Initial package