icingadb.spec 5.26 KB
Newer Older
Noah Hilverling's avatar
Noah Hilverling committed
1 2
%global revision 0.rc1.1
%global src_version_suffix -rc1
Alexander A. Klimov's avatar
Alexander A. Klimov committed
3

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

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

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

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

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

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

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

%{?systemd_requires}
BuildRequires:  systemd

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

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

61
%if "%{_vendor}" == "suse"
62 63 64 65 66 67 68
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
69
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
70 71 72 73 74 75 76

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

%description
Icinga DB

Henrik Triem's avatar
Henrik Triem committed
77 78 79 80 81 82 83 84
%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
85
%prep
Noah Hilverling's avatar
Noah Hilverling committed
86
%setup -q -n %{name}-%{version}%{?src_version_suffix}
Alexander A. Klimov's avatar
Alexander A. Klimov committed
87 88

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

%gobuild .

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

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

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

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

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

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

Henrik Triem's avatar
Henrik Triem committed
116
#%%install redis
117 118 119

install -d -m 0755 %{buildroot}%{_sharedstatedir}/icinga-redis/icingadb-redis

Henrik Triem's avatar
Henrik Triem committed
120 121 122 123 124 125 126 127 128
# 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
129 130 131 132
%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
133 134 135 136
%if "%{_vendor}" == "suse"
%service_add_pre %{service}
%endif # suse

Henrik Triem's avatar
Henrik Triem committed
137 138 139 140 141
%pre redis
%if "%{_vendor}" == "suse"
  %service_add_pre icingadb-redis.service
%endif

Alexander A. Klimov's avatar
Alexander A. Klimov committed
142
%post
Markus Frosch's avatar
Markus Frosch committed
143 144 145
%if "%{_vendor}" == "suse"
%service_add_post %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
146
%systemd_post %{service}
Markus Frosch's avatar
Markus Frosch committed
147
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
148

Henrik Triem's avatar
Henrik Triem committed
149 150 151 152 153 154 155 156 157
%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
158
%preun
Markus Frosch's avatar
Markus Frosch committed
159 160 161
%if "%{_vendor}" == "suse"
%service_del_preun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
162
%systemd_preun %{service}
Markus Frosch's avatar
Markus Frosch committed
163
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
164

Henrik Triem's avatar
Henrik Triem committed
165 166 167 168 169 170 171 172 173
%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
174
%postun
Markus Frosch's avatar
Markus Frosch committed
175 176 177
%if "%{_vendor}" == "suse"
%service_del_postun %{service}
%else # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
178
%systemd_postun %{service}
Markus Frosch's avatar
Markus Frosch committed
179
%endif # suse
Alexander A. Klimov's avatar
Alexander A. Klimov committed
180

Henrik Triem's avatar
Henrik Triem committed
181 182 183 184 185 186 187 188 189
%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
190 191 192 193 194
%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)
Noah Hilverling's avatar
Noah Hilverling committed
195
%doc LICENSE AUTHORS README.md CHANGELOG.md
196 197 198
%{_sbindir}/icingadb
%{_unitdir}/%{service}

Markus Frosch's avatar
Markus Frosch committed
199 200 201 202
%if "%{_vendor}" == "suse"
%{_sbindir}/rc%{name}
%endif # suse

Markus Frosch's avatar
Markus Frosch committed
203 204 205
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/schema

206
%defattr(0640,icingadb,icingadb,0750)
207 208

%dir %{configdir}
209
%config(noreplace) %{configdir}/icingadb.ini
210

Henrik Triem's avatar
Henrik Triem committed
211 212 213 214 215
%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
216
%dir %attr(750,icinga-redis,icinga-redis) %{_sharedstatedir}/icinga-redis/icingadb-redis
Henrik Triem's avatar
Henrik Triem committed
217

218
%changelog
Noah Hilverling's avatar
Noah Hilverling committed
219 220
* Fri Mar 13 2020 Noah Hilverling <noah.hilverling@icinga.com> 1.0.0-0.rc1.1
- Release 1.0.0-rc1 
Henrik Triem's avatar
Henrik Triem committed
221
* Fri Dec 13 2019 Henrik Triem <henrik.triem@icinga.com> 0.0.0-1
222 223
* Mon Sep 24 2018 Markus Frosch <markus.frosch@icinga.com> 0.0.0-0
- Initial package