Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startup-script to install Ops Agent #171

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
# Copyright 2022 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
# limitations under the License.

LEGACY_MONITORING_PACKAGE='stackdriver-agent'
LEGACY_LOGGING_PACKAGE='google-fluentd'
OPSAGENT_PACKAGE='google-cloud-ops-agent'

fail() {
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $*"
exit 1
}

handle_debian() {
is_legacy_monitoring_installed() {
dpkg-query --show --showformat 'dpkg-query: ${Package} is installed\n' ${LEGACY_MONITORING_PACKAGE} |
grep "${LEGACY_MONITORING_PACKAGE} is installed"
}

is_legacy_logging_installed() {
dpkg-query --show --showformat 'dpkg-query: ${Package} is installed\n' ${LEGACY_LOGGING_PACKAGE} |
grep "${LEGACY_LOGGING_PACKAGE} is installed"
}

is_legacy_installed() {
is_legacy_monitoring_installed || is_legacy_logging_installed
}

is_opsagent_installed() {
dpkg-query --show --showformat 'dpkg-query: ${Package} is installed\n' ${OPSAGENT_PACKAGE} |
grep "${OPSAGENT_PACKAGE} is installed"
}

install_opsagent() {
curl -s https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh | bash -s -- --also-install
}
}

handle_redhat() {
is_legacy_monitoring_installed() {
rpm --query --queryformat 'package %{NAME} is installed\n' ${LEGACY_MONITORING_PACKAGE} |
grep "${LEGACY_MONITORING_PACKAGE} is installed"
}

is_legacy_logging_installed() {
rpm --query --queryformat 'package %{NAME} is installed\n' ${LEGACY_LOGGING_PACKAGE} |
grep "${LEGACY_LOGGING_PACKAGE} is installed"
}

is_legacy_installed() {
is_legacy_monitoring_installed || is_legacy_logging_installed
}

is_opsagent_installed() {
rpm --query --queryformat 'package %{NAME} is installed\n' ${OPSAGENT_PACKAGE} |
grep "${OPSAGENT_PACKAGE} is installed"
}

install_opsagent() {
curl -s https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh | bash -s -- --also-install
}
}

main() {
if [ -f /etc/debian_version ]; then
cboneti marked this conversation as resolved.
Show resolved Hide resolved
handle_debian
elif [ -f /etc/redhat-release ]; then
cboneti marked this conversation as resolved.
Show resolved Hide resolved
handle_redhat
else
fail "Unsupported platform."
fi

if is_legacy_installed || is_opsagent_installed; then
fail "Legacy or Ops Agent is already installed."
fi

install_opsagent
}

main