icingadb.spec 5.46 KB
Newer Older
Noah Hilverling's avatar
Noah Hilverling committed
1
%global revision 0.rc1.2
Noah Hilverling's avatar
Noah Hilverling committed
2
%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

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

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

%description
Icinga DB

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

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

%gobuild .

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

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

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

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

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

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

Henrik Triem's avatar
Henrik Triem committed
114
#%%install redis
115 116 117

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

Henrik Triem's avatar
Henrik Triem committed
118 119 120 121 122 123 124 125 126
# 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
127 128
%pre
getent group icingadb >/dev/null || groupadd -r icingadb
129
getent passwd icingadb >/dev/null || useradd -r -g icingadb -d /etc/icingadb -s /sbin/nologin -c 'Icinga DB' icingadb
Alexander A. Klimov's avatar
Alexander A. Klimov committed
130

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

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

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

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

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

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

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

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

Markus Frosch's avatar
Markus Frosch committed
201 202 203
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/schema

204
%defattr(0640,icingadb,icingadb,0750)
205 206

%dir %{configdir}
207
%config(noreplace) %{configdir}/icingadb.ini
208

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

216
%changelog
Noah Hilverling's avatar
Noah Hilverling committed
217 218
* Wed Apr 22 2020 Noah Hilverling <noah.hilverling@icinga.com> 1.0.0-0.rc1.3
- Fix icingadb home directory
Noah Hilverling's avatar
Noah Hilverling committed
219 220
* Tue Apr 14 2020 Noah Hilverling <noah.hilverling@icinga.com> 1.0.0-0.rc1.2
- Remove icinga-redis dependency
Noah Hilverling's avatar
Noah Hilverling committed
221 222
* 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
223
* Fri Dec 13 2019 Henrik Triem <henrik.triem@icinga.com> 0.0.0-1
224 225
* Mon Sep 24 2018 Markus Frosch <markus.frosch@icinga.com> 0.0.0-0
- Initial package