-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoogle-cloud-workload-agent.spec
117 lines (101 loc) · 3.58 KB
/
google-cloud-workload-agent.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
#
%include %build_rpm_options
Summary: Google Cloud Workload Agent
Group: Application
License: ASL 2.0
Vendor: Google, Inc.
Provides: google-cloud-workload-agent
%description
Google Cloud Workload Agent
%define _confdir /etc/%{name}
%define _bindir /usr/bin
%define _docdir /usr/share/doc/%{name}
%define _servicedir /usr/share/%{name}/service
%install
# clean away any previous RPM build root
/bin/rm --force --recursive "${RPM_BUILD_ROOT}"
%include %build_rpm_install
%files
%defattr(-,root,root)
%attr(755,root,root) %{_bindir}/google_cloud_workload_agent
%config(noreplace) %attr(0644,root,root) %{_confdir}/configuration.json
%attr(0644,root,root) %{_servicedir}/%{name}.service
%attr(0644,root,root) %{_docdir}/LICENSE
%attr(0644,root,root) %{_docdir}/README.md
%attr(0644,root,root) %{_docdir}/THIRD_PARTY_NOTICES
%pre
# If we need to check install / upgrade ($1 = 1 is install, $1 = 2 is upgrade)
# if the agent is running - stop it
if `systemctl is-active --quiet %{name} > /dev/null 2>&1`; then
systemctl stop %{name}
fi
%post
# link the systemd service and reload the daemon
# RHEL
if [ -d "/lib/systemd/system/" ]; then
cp -f %{_servicedir}/%{name}.service /lib/systemd/system/%{name}.service
systemctl daemon-reload
fi
# SLES
if [ -d "/usr/lib/systemd/system/" ]; then
cp -f %{_servicedir}/%{name}.service /usr/lib/systemd/system/%{name}.service
systemctl daemon-reload
fi
# enable and start the agent
systemctl enable %{name}
systemctl start %{name}
# log usage metrics for install
timeout 30 %{_bindir}/google_cloud_workload_agent logusage -s INSTALLED &> /dev/null || true
# next steps instructions
echo ""
echo "##########################################################################"
echo "Google Cloud Workload Agent has been installed"
echo ""
echo "You can view the logs in /var/log/%{name}.log"
echo ""
echo "Verify the agent is running with: "
echo " sudo systemctl status %{name}"
echo ""
echo "Configuration is available in %{_confdir}/configuration.json"
echo ""
echo "Documentation can be found at https://cloud.google.com/solutions/"
echo "##########################################################################"
echo ""
%preun
# $1 == 0 is uninstall, $1 == 1 is upgrade
if [ "$1" = "0" ]; then
# Uninstall
# if the agent is running - stop it
if `type "systemctl" > /dev/null 2>&1 && systemctl is-active --quiet %{name}`; then
systemctl stop %{name}
fi
# if the agent is enabled - disable it
if `type "systemctl" > /dev/null 2>&1 && systemctl is-enabled --quiet %{name}`; then
systemctl disable %{name}
fi
# log usage metrics for uninstall
timeout 30 %{_bindir}/google_cloud_workload_agent logusage -s UNINSTALLED &> /dev/null || true
fi
%postun
# $1 == 0 is uninstall, $1 == 1 is upgrade
if [ "$1" = "0" ]; then
# Uninstall
rm -f /lib/systemd/system/%{name}.service
rm -f /usr/lib/systemd/system/%{name}.service
rm -fr %{_docdir}
else
# log usage metrics for upgrade
timeout 30 %{_bindir}/google_cloud_workload_agent logusage -s UPDATED -agent-version "%{name}-%{VERSION}-%{RELEASE}" &> /dev/null || true
fi