Repository navigation
Expand file tree
/
Copy pathgoogle-cloud-workload-agent.spec
More file actions
142 lines (124 loc) · 4.66 KB
/
Copy pathgoogle-cloud-workload-agent.spec
File metadata and controls
142 lines (124 loc) · 4.66 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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 Agent for Compute Workloads
Group: Application
License: ASL 2.0
Vendor: Google, Inc.
Provides: google-cloud-workload-agent
%description
Google Cloud Agent for Compute Workloads
%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
%define _sqlserver_agent_installed false
# Backup configuration from google-cloud-sql-server-agent
if `systemctl is-active --quiet google-cloud-sql-server-agent > /dev/null 2>&1`; then
_sqlserver_agent_installed=true
# Backup the configuration file
if [ -f /etc/google-cloud-sql-server-agent/configuration.json ]; then
cp /etc/google-cloud-sql-server-agent/configuration.json /etc/google-cloud-workload-agent/cfg_sqlserver_backup.json
# Migrate the configuration file
timeout 30 %{_bindir}/google_cloud_workload_agent migrate
# Log usage metrics for migrated
timeout 30 %{_bindir}/google_cloud_workload_agent logusage -s ACTION -a 1 &> /dev/null || true
fi
fi
# enable and start the agent
systemctl enable %{name}
systemctl start %{name}
# Uninstall google-cloud-sql-server-agent
if [ "${_sqlserver_agent_installed}" = true ]; then
if command -v yum &> /dev/null; then
nohup sleep 30 && yum remove -y google-cloud-sql-server-agent > /dev/null 2>&1 &
elif command -v zypper &> /dev/null; then
nohup sleep 30 && zypper remove -y google-cloud-sql-server-agent > /dev/null 2>&1 &
else
true
fi
fi
# 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 Agent for Compute Workloads 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