From 6118b037ddf5f2603f226fad9f6643b649daa2dd Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 6 Aug 2018 14:53:44 -0700 Subject: [PATCH 1/7] version bump --- pdagent/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdagent/__init__.py b/pdagent/__init__.py index 47457ba8..bbcbab14 100644 --- a/pdagent/__init__.py +++ b/pdagent/__init__.py @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -__version__ = "1.4" +__version__ = "1.5" def enum(*sequential, **named): enums = dict(zip(sequential, range(len(sequential))), **named) From 62350ccf4435709a6c850f4b57f79d39641c2f86 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Wed, 8 Aug 2018 09:54:29 -0700 Subject: [PATCH 2/7] update rpm package release env due to deprecated ruby version --- build-linux/make_common.env | 2 +- build-linux/make_package.sh | 4 ++-- build-linux/make_rpm.sh | 25 +++++++++---------------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/build-linux/make_common.env b/build-linux/make_common.env index 4028335d..d62cfe0f 100644 --- a/build-linux/make_common.env +++ b/build-linux/make_common.env @@ -1,3 +1,3 @@ ## common variables for make_* scripts -FPM_VERSION=1.7.0 +FPM_VERSION=1.4.0 diff --git a/build-linux/make_package.sh b/build-linux/make_package.sh index c2c5bb43..b518dfed 100644 --- a/build-linux/make_package.sh +++ b/build-linux/make_package.sh @@ -145,8 +145,8 @@ else fi _PKG_MAINTAINER="$_PKG_MAINTAINER (PagerDuty, Inc.) " if [ "$pkg_type" = "rpm" ]; then - source /opt/rh/ruby193/enable - FPM=/opt/rh/ruby193/root/usr/local/share/gems/gems/fpm-$FPM_VERSION/bin/fpm + source /opt/rh/rh-ruby23/enable + FPM=/opt/rh/rh-ruby23/root/usr/local/share/gems/gems/fpm-$FPM_VERSION/bin/fpm else FPM=fpm fi diff --git a/build-linux/make_rpm.sh b/build-linux/make_rpm.sh index e558411f..37998978 100644 --- a/build-linux/make_rpm.sh +++ b/build-linux/make_rpm.sh @@ -29,7 +29,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -set -e +set -x # do stuff in the script's directory. basedir=$(dirname $0) @@ -48,27 +48,20 @@ rpm_install_root=$install_root/rpm [ -d "$rpm_install_root" ] || mkdir -p $rpm_install_root # install required packages. -[ $(sudo rpm -q rpm-build ruby193 createrepo \ +[ $(sudo rpm -q rpm-build rh-ruby23 createrepo \ gcc gcc-c++ kernel-devel | \ grep -vc 'not installed') -eq 7 ] || { echo "Installing required packages. This may take a few minutes..." sudo yum install -y -q rpm-build createrepo gcc gcc-c++ kernel-devel - sudo yum install -y -q centos-release-SCL - sudo yum install -y -q ruby193 ruby193-ruby-devel - source /opt/rh/ruby193/enable - CUR_PWD=`pwd` - echo "Installing rubygems ..." - cd /tmp - sudo wget --no-check-certificate https://rubygems.org/rubygems/rubygems-2.6.8.tgz - sudo tar xzf rubygems-2.6.8.tgz - cd rubygems-2.6.8 - sudo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" /opt/rh/ruby193/root/usr/bin/ruby setup.rb - cd $CUR_PWD - echo "Done installing." + sudo yum install -y -q centos-release-scl + sudo yum install -y -q rh-ruby23 rh-ruby23-ruby-devel } -{ gem list fpm | grep fpm >/dev/null ; } || { + +source /opt/rh/rh-ruby23/enable + +{ sudo /opt/rh/rh-ruby23/root/usr/bin/gem list fpm | grep fpm >/dev/null ; } || { echo "Installing fpm gem..." - sudo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" /opt/rh/ruby193/root/usr/bin/gem install -q -v $FPM_VERSION fpm + sudo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" /opt/rh/rh-ruby23/root/usr/bin/gem install -q -v $FPM_VERSION fpm echo "Done installing." } From 9703fde4869b29dc20843adf090401e1415265b0 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Wed, 8 Aug 2018 17:42:25 -0700 Subject: [PATCH 3/7] check for python minor ver > 6 for source_address arg --- build-linux/howto.txt | 6 +++++- conf/pdagent.conf | 1 + pdagent/thirdparty/httpswithverify.py | 12 +++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build-linux/howto.txt b/build-linux/howto.txt index 6a358cef..c0d3d4ce 100644 --- a/build-linux/howto.txt +++ b/build-linux/howto.txt @@ -1,4 +1,3 @@ - # Linux Build Instructions These instructions assume you're running this on a Mac with Vagrant installed, @@ -9,6 +8,11 @@ should happen automatically) To build Linux packages, you will need GPG keys to sign the packages. +NOTE: you'll need to generate your dev keys with gpg1 not gpg2. The command +sequence below should generate files: pubring.gpg, secring.gpg and trustdb.gpg. +If you see a file called pubring.kbx and a bunch of socket files then you're using +gpg2. + For development, you can generate new keys as follows: ``` diff --git a/conf/pdagent.conf b/conf/pdagent.conf index 790b7ab1..ab6cdb95 100644 --- a/conf/pdagent.conf +++ b/conf/pdagent.conf @@ -28,4 +28,5 @@ retry_limit_for_possible_errors = 60 # Source address used when connecting to PagerDuty. Use 0.0.0.0 if you want to # let your OS choosing the source address automaticaly. +# NOTE - ignored on python2.6 envs source_address = 0.0.0.0 diff --git a/pdagent/thirdparty/httpswithverify.py b/pdagent/thirdparty/httpswithverify.py index 4c4cffc4..702c6833 100644 --- a/pdagent/thirdparty/httpswithverify.py +++ b/pdagent/thirdparty/httpswithverify.py @@ -64,6 +64,7 @@ import httplib import urllib2 import socket +import sys from pdagent.pdagentutil import find_in_sys_path from pdagent.thirdparty.ssl_match_hostname import \ @@ -94,13 +95,22 @@ class VerifyingHTTPSConnection(httplib.HTTPSConnection): def __init__(self, host, **kwargs): self.ca_certs = kwargs.pop("ca_certs", None) self.source_addr = kwargs.pop("source_address", '0.0.0.0') + + if sys.version_info[1] > 6: + self.gt_python_26 = True + else: + self.gt_python_26 = False + httplib.HTTPSConnection.__init__(self, host, **kwargs) def connect(self): """Connects to a host on a given (SSL) port, using a certificate-verifying socket wrapper.""" - args = [(self.host, self.port), self.timeout, (self.source_addr, 0)] + args = [(self.host, self.port), self.timeout] + if self.gt_python_26: + args.append((self.source_addr, 0)) + sock = socket.create_connection(*args) end_host = self.host if self._tunnel_host: From 5a9ddaa8f055df850bfcf2c57ce92e89b8de1cd8 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Thu, 9 Aug 2018 18:12:10 -0700 Subject: [PATCH 4/7] added centos72 env and update self_signed cert to 2048 bit --- Vagrantfile | 46 ++++++++++++++----------- pdagenttest/self_signed.pem | 69 ++++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 634df625..8153abba 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,45 +1,49 @@ # -*- mode: ruby -*- # vi: set ft=ruby : - _bento_centos65 = { - "box" => "bento_centos65", - "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box", + "box" => "bento_centos65", + "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box", +} +_bento_centos72 = { + "box" => "bento_centos72", + "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.2_chef-provisionerless.box", } _bento_ubuntu1204 = { - "box" => "bento_ubuntu1204", - "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04_chef-provisionerless.box", + "box" => "bento_ubuntu1204", + "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04_chef-provisionerless.box", } _bento_ubuntu1404 = { - "box" => "bento_ubuntu1404", - "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box", + "box" => "bento_ubuntu1404", + "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box", } _bento_ubuntu1604 = { - "box" => "bento_ubuntu1604", - "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-16.04_chef-provisionerless.box", + "box" => "bento_ubuntu1604", + "box_url" => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-16.04_chef-provisionerless.box", } vms = { - "agent-minimal-centos65" => _bento_centos65, - "agent-minimal-ubuntu1204" => _bento_ubuntu1204, - "agent-minimal-ubuntu1404" => _bento_ubuntu1404, - "agent-minimal-ubuntu1604" => _bento_ubuntu1604 + "agent-minimal-centos65" => _bento_centos65, + "agent-minimal-centos72" => _bento_centos72, + "agent-minimal-ubuntu1204" => _bento_ubuntu1204, + "agent-minimal-ubuntu1404" => _bento_ubuntu1404, + "agent-minimal-ubuntu1604" => _bento_ubuntu1604 } Vagrant.configure("2") do |conf_outer| - vms.each do |name, conf| + vms.each do |name, conf| - conf_outer.vm.define name do |config| + conf_outer.vm.define name do |config| - config.vm.box = conf["box"] - config.vm.box_url = conf["box_url"] + config.vm.box = conf["box"] + config.vm.box_url = conf["box_url"] - # Public/bridged network so VM can install packages from the internet - config.vm.network :public_network, :bridge => "en0: Wi-Fi (AirPort)" + # Public/bridged network so VM can install packages from the internet + config.vm.network :public_network, :bridge => "en0: Wi-Fi (AirPort)" - end # conf_outer.vm.define + end # conf_outer.vm.define - end # vms.each + end # vms.each end # Vagrant.configure diff --git a/pdagenttest/self_signed.pem b/pdagenttest/self_signed.pem index 88d40ff9..d474022c 100644 --- a/pdagenttest/self_signed.pem +++ b/pdagenttest/self_signed.pem @@ -1,23 +1,50 @@ -----BEGIN CERTIFICATE----- -MIICMzCCAd2gAwIBAgIJAORnQnpo/Ty/MA0GCSqGSIb3DQEBBQUAMEcxCzAJBgNV -BAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMQ8wDQYDVQQKEwZNeSBPcmcxEjAQ -BgNVBAMTCWxvY2FsaG9zdDAgFw0xNDAyMTQyMzU0MDZaGA8yMTE0MDEyMTIzNTQw -NlowRzELMAkGA1UEBhM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qZ+6hXSfHpqqeQsihbREcLHIEErkJsnmlFFs5lTvbwO9p7E +XRZjyBHlmC4CwTG6BRZtOXZWofUCgYEAymHUW7klE8QB0W+wcyfXLZCZYlGLklZy +JvQLXR9R0tx3+HdbcM+tc/UFrLYC+t3d0Y/7FmWiASjzfnWHj4lJ2z9y6uJjgMyo +yI4QY3kT1PnVmiAGaEN3SmXTZU7IgLKIb2K/JH7/sLMw7AEqyRN94QUXCCUn6bJE +XXgB3rcwrSECgYB0IDUOgAV+8Mr0XSWit5oE46+hqAVzjZUkJjRh7hfUmcvxMQJD +aV/f5XGnbAzIJVXpDSYfUZ9h/4RuFcU5E8QEHPQRJ1Vft8DKMfFuwyag9zCzTNZL +6TVyfVK64fmQnCzOw8X9ctu+YakcX7d3sjqToXtICmvLSYqLB4RvZidFDQKBgQDA +WJBrCKFLktujgQJzv+bLwIV3I0eCsrRVf1aZj93FiZJgTJhUtJ0G+1YEWwyj/2AF +/1DFbZy2e4RIqU1Ix1OxlDEVOksVq+2yhwreb8HAhh5UGKHeUFi9Fd//hgwb/RKc +wn4mIqnC99vEQiu25daamarVK/MuMia1qwwj73nM4QKBgDbWg0KV2dQJTufn71MH +fcG6sWwCodvQVdVHdB+5f4D0k7QSXXwAt7gzITobpYy4iXc1ORh91WT0Zc4+DiwA +DPsDFzaWcs2VLf/gh4oHsDp0c+kd7eFim3iOOENJysqXVGvvqw2om5+UGi+0zzh5 +4BaIiTv42cCKSahZIVQLpk1Y +-----END PRIVATE KEY----- From a8756d919a40e635ff77f2720f68f22d5491ecd8 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Fri, 10 Aug 2018 17:38:53 -0700 Subject: [PATCH 5/7] package tweaks for proper state transitions --- Vagrantfile | 3 +- build-linux/deb/postrm | 39 ++++++++++++++++++ build-linux/make_package.sh | 28 ++++++------- build-linux/rpm/postinst | 23 +++++++++-- build-linux/rpm/postrm | 39 ++++++++++++++++++ build-linux/rpm/posttrans | 50 ++++++++++++++++++++++++ build-linux/rpm/preinst | 40 +++++++++++++++++++ build-linux/rpm/prerm | 39 ++++++++++++------ pdagenttestinteg/util.sh | 2 +- scripts/rev_deb.sh | 3 ++ scripts/rev_pkgs.sh | 6 +-- scripts/rev_rpm.sh | 3 ++ scripts/rm_pkgs.sh | 2 - scripts/setup_upgrade_test_centos72.sh | 3 ++ scripts/setup_upgrade_test_ubuntu1604.sh | 3 ++ vagrant-setup.txt | 4 +- 16 files changed, 244 insertions(+), 43 deletions(-) create mode 100644 build-linux/deb/postrm create mode 100644 build-linux/rpm/postrm create mode 100644 build-linux/rpm/posttrans create mode 100644 build-linux/rpm/preinst create mode 100755 scripts/rev_deb.sh create mode 100755 scripts/rev_rpm.sh delete mode 100755 scripts/rm_pkgs.sh create mode 100755 scripts/setup_upgrade_test_centos72.sh create mode 100755 scripts/setup_upgrade_test_ubuntu1604.sh diff --git a/Vagrantfile b/Vagrantfile index 8153abba..28c87858 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -39,8 +39,9 @@ Vagrant.configure("2") do |conf_outer| config.vm.box = conf["box"] config.vm.box_url = conf["box_url"] + ## no longer necessary with Vagrant 2.1.2? # Public/bridged network so VM can install packages from the internet - config.vm.network :public_network, :bridge => "en0: Wi-Fi (AirPort)" + # config.vm.network :public_network, :bridge => "en0: Wi-Fi (AirPort)" end # conf_outer.vm.define diff --git a/build-linux/deb/postrm b/build-linux/deb/postrm new file mode 100644 index 00000000..eb18e2e7 --- /dev/null +++ b/build-linux/deb/postrm @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Copyright (c) 2013-2014, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +set -e + +if [ $# -gt 1 ]; then # this is an upgrade + : # no-op +else # this is a remove + : # no-op +fi + +exit 0 diff --git a/build-linux/make_package.sh b/build-linux/make_package.sh index b518dfed..ba5d958c 100644 --- a/build-linux/make_package.sh +++ b/build-linux/make_package.sh @@ -87,7 +87,7 @@ mkdir -p \ data/var/lib/pdagent/outqueue/err \ data/var/lib/pdagent/outqueue/suc mkdir -p data/var/lib/pdagent/scripts -# stage sysV & systemd service files for deb postinst +# stage sysV & systemd service files for pkg postinst cp pdagent.init data/var/lib/pdagent/scripts/pdagent.init cp pdagent.service data/var/lib/pdagent/scripts/pdagent.service @@ -95,14 +95,6 @@ echo = /etc/... mkdir -p data/etc/ cp ../conf/pdagent.conf data/etc/ -if [ "$pkg_type" = "rpm" ]; then - # marks /etc/init.d/pdagent as co-owned by old_rpm && new_rpm and saves it from removal - # during yum update cleanu of old_rpm (yum cleanup internals regardless of prerm script) - mkdir -p data/etc/init.d - cp pdagent.init data/etc/init.d/pdagent - chmod 755 data/etc/init.d/pdagent -fi - if [ "$pkg_type" = "deb" ]; then _PY_SITE_PACKAGES=data/usr/lib/python2.7/dist-packages else @@ -118,7 +110,6 @@ find pdagent -type f \( -name "*.py" -o -name "ca_certs.pem" \) \ -exec cp {} build-linux/$_PY_SITE_PACKAGES/{} \; cd - - # copy the libraries for python2.7 rpm users if [ "$pkg_type" = "rpm" ]; then mkdir -p "$_PY27_SITE_PACKAGES" @@ -133,6 +124,11 @@ if [ "$pkg_type" = "rpm" ]; then _SIGN_OPTS="--rpm-sign" fi +_POST_TRANS_OPT="" +if [ "$pkg_type" = "rpm" ]; then + _POST_TRANS_OPT="--rpm-posttrans ../rpm/posttrans" +fi + cd target _DESC="The PagerDuty Agent package @@ -151,12 +147,6 @@ else FPM=fpm fi -if [ "$pkg_type" = "deb" ]; then - _BEFORE_AND_AFTER_OPTS="--before-install ../$pkg_type/preinst --after-install ../$pkg_type/postinst --before-remove ../$pkg_type/prerm" -else - _BEFORE_AND_AFTER_OPTS="--after-install ../$pkg_type/postinst --before-remove ../$pkg_type/prerm" -fi - $FPM -s dir \ -t $pkg_type \ --name "pdagent" \ @@ -172,7 +162,11 @@ $FPM -s dir \ --${pkg_type}-user root \ --${pkg_type}-group root \ --config-files /etc/pdagent.conf \ - $_BEFORE_AND_AFTER_OPTS \ + --before-install ../$pkg_type/preinst \ + --after-install ../$pkg_type/postinst \ + --before-remove ../$pkg_type/prerm \ + --after-remove ../$pkg_type/postrm \ + $_POST_TRANS_OPT \ -C ../data \ etc usr var diff --git a/build-linux/rpm/postinst b/build-linux/rpm/postinst index 906240b5..84be6f33 100755 --- a/build-linux/rpm/postinst +++ b/build-linux/rpm/postinst @@ -30,6 +30,19 @@ set -e +install_init () { + cp /var/lib/pdagent/scripts/pdagent.init /etc/init.d/pdagent + chmod +x /etc/init.d/pdagent + chkconfig --add pdagent + service pdagent restart +} + +install_systemd () { + cp /var/lib/pdagent/scripts/pdagent.service /lib/systemd/system + systemctl enable pdagent + systemctl restart pdagent +} + # Create pdagent user & group /usr/bin/getent passwd pdagent >/dev/null || \ /usr/sbin/adduser --system --shell /bin/false --no-create-home pdagent @@ -52,8 +65,10 @@ fi # Compile module .py to .pyc python -m compileall -q -f "$INSTALL_PATH/" -# Register daemon -chkconfig --add pdagent +if which systemctl >/dev/null; then + install_systemd +else + install_init +fi -# Restart daemon -service pdagent restart +exit 0 diff --git a/build-linux/rpm/postrm b/build-linux/rpm/postrm new file mode 100644 index 00000000..0b86af8c --- /dev/null +++ b/build-linux/rpm/postrm @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Copyright (c) 2013-2014, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +set -e + +if [ $1 -gt 0 ]; then # this is an upgrade + : # no-op +else # this is a remove + : # no-op +fi + +exit 0 diff --git a/build-linux/rpm/posttrans b/build-linux/rpm/posttrans new file mode 100644 index 00000000..5bec83a4 --- /dev/null +++ b/build-linux/rpm/posttrans @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Copyright (c) 2013-2014, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +set -e + +reinstate_init () { + cp /var/lib/pdagent/scripts/pdagent.init /etc/init.d/pdagent + chmod +x /etc/init.d/pdagent +} + +if [ -e "/tmp/pdagent_upgrade.txt" ]; then + # reinstate /etc/init.d/pdagent that was deleted by v1.4 pkg removal + if which systemctl >/dev/null; then + : + else + reinstate_init + fi + + # cleanup tmp file + rm /tmp/pdagent_upgrade.txt +fi + +exit 0 diff --git a/build-linux/rpm/preinst b/build-linux/rpm/preinst new file mode 100644 index 00000000..a5657c15 --- /dev/null +++ b/build-linux/rpm/preinst @@ -0,0 +1,40 @@ +#!/bin/sh +# +# Copyright (c) 2013-2014, PagerDuty, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +set -e + +if [ $1 -gt 1 ]; then # this is an upgrade + # drop a file so posttrans knows this is an upgrade + touch /tmp/pdagent_upgrade.txt +else # this is a remove + : # no-op +fi + +exit 0 diff --git a/build-linux/rpm/prerm b/build-linux/rpm/prerm index ebb67ab0..6a39a839 100644 --- a/build-linux/rpm/prerm +++ b/build-linux/rpm/prerm @@ -30,20 +30,33 @@ set -e -case "$*" in - 0) # remove-only; not upgrade. - # Stop daemon - service pdagent stop +uninstall_init () { + service pdagent stop + chkconfig --del pdagent +} - # Unregister daemon - chkconfig --del pdagent +uninstall_systemd () { + systemctl stop pdagent + systemctl disable pdagent +} - # Clean up module .pyc - find /usr/lib/python2.6/site-packages/pdagent/ \ - -name "*.pyc" -exec rm {} \; - ;; - *) - ;; -esac +VERSION=`python -c "import platform; print platform.python_version()"` +if [[ $VERSION == 2.7.* ]]; then + INSTALL_PATH="/usr/lib/python2.7/site-packages/pdagent" +else + INSTALL_PATH="/usr/lib/python2.6/site-packages/pdagent" +fi + +if [ $1 -gt 0 ]; then # this is an upgrade + : # no-op +else # this is a remove + if which systemctl >/dev/null; then + uninstall_systemd + else + uninstall_init + fi + + rm -rf $INSTALL_PATH +fi exit 0 diff --git a/pdagenttestinteg/util.sh b/pdagenttestinteg/util.sh index 407994c4..52a9f61d 100644 --- a/pdagenttestinteg/util.sh +++ b/pdagenttestinteg/util.sh @@ -38,7 +38,7 @@ OUTQUEUE_DIR=$DATA_DIR/outqueue AGENT_SVC_NAME=pdagent SEND_INTERVAL_SECS=5 # The service key to use for testing commands like pd-send etc. -SVC_KEY=CHANGEME +SVC_KEY=24124788d819478298bd55f0b8c3a19f # return OS type of current system. os_type() { diff --git a/scripts/rev_deb.sh b/scripts/rev_deb.sh new file mode 100755 index 00000000..34e1e725 --- /dev/null +++ b/scripts/rev_deb.sh @@ -0,0 +1,3 @@ +vagrant destroy -f agent-minimal-ubuntu1204 +vagrant up agent-minimal-ubuntu1204 +scons local-repo gpg-home=build-linux/gnupg virt=agent-minimal-ubuntu1204 diff --git a/scripts/rev_pkgs.sh b/scripts/rev_pkgs.sh index 7fbaf674..f2c884c3 100755 --- a/scripts/rev_pkgs.sh +++ b/scripts/rev_pkgs.sh @@ -1,4 +1,2 @@ -echo '!!!! REMOVING PACKAGES !!!!' -scripts/rm_pkgs.sh -echo '!!!! BUILDING PACKAGES !!!!' -scons local-repo gpg-home=build-linux/gnupg +scripts/rev_deb.sh +scripts/rev_rpm.sh diff --git a/scripts/rev_rpm.sh b/scripts/rev_rpm.sh new file mode 100755 index 00000000..8203fdb5 --- /dev/null +++ b/scripts/rev_rpm.sh @@ -0,0 +1,3 @@ +vagrant destroy -f agent-minimal-centos65 +vagrant up agent-minimal-centos65 +scons local-repo gpg-home=build-linux/gnupg virt=agent-minimal-centos65 diff --git a/scripts/rm_pkgs.sh b/scripts/rm_pkgs.sh deleted file mode 100755 index 1d268254..00000000 --- a/scripts/rm_pkgs.sh +++ /dev/null @@ -1,2 +0,0 @@ -vagrant ssh agent-minimal-ubuntu1204 -c 'sudo apt-get -y remove pdagent' -vagrant ssh agent-minimal-centos65 -c 'sudo yum -y remove pdagent' diff --git a/scripts/setup_upgrade_test_centos72.sh b/scripts/setup_upgrade_test_centos72.sh new file mode 100755 index 00000000..33f9b340 --- /dev/null +++ b/scripts/setup_upgrade_test_centos72.sh @@ -0,0 +1,3 @@ +vagrant destroy -f agent-minimal-centos72 +vagrant up agent-minimal-centos72 +vagrant ssh agent-minimal-centos72 -c 'bash /vagrant/scripts/install_pub_centos_pkg.sh' diff --git a/scripts/setup_upgrade_test_ubuntu1604.sh b/scripts/setup_upgrade_test_ubuntu1604.sh new file mode 100755 index 00000000..2f026900 --- /dev/null +++ b/scripts/setup_upgrade_test_ubuntu1604.sh @@ -0,0 +1,3 @@ +vagrant destroy -f agent-minimal-ubuntu1604 +vagrant up agent-minimal-ubuntu1604 +vagrant ssh agent-minimal-ubuntu1604 -c 'bash /vagrant/scripts/install_pub_ubuntu_pkg.sh' diff --git a/vagrant-setup.txt b/vagrant-setup.txt index c9bb5e3d..d033c60e 100644 --- a/vagrant-setup.txt +++ b/vagrant-setup.txt @@ -3,10 +3,11 @@ Vagrant setup notes for OS X 10.8 (Mountain Lion). -## Installation +## Installation/Upgrade 1. Install Vagrant. See instructions at http://www.vagrantup.com/ +NOTE: If you experience issues in the 'Configuring and enabling network interfaces...' phase when bringing up centos instances, upgrade your vagrant to the latest. My upgrade from v1.9.0 to v2.1.2 fixed this. ## Managing VMs @@ -20,6 +21,7 @@ For example: Current machine states: agent-minimal-centos65 not created (virtualbox) +agent-minimal-centos72 not created (virtualbox) agent-minimal-ubuntu1204 running (virtualbox) agent-minimal-ubuntu1404 running (virtualbox) agent-minimal-ubuntu1604 running (virtualbox) From 0d1c6f33b93c69434b10b22717d3d4e848b48398 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 13 Aug 2018 13:00:59 -0700 Subject: [PATCH 6/7] one-time rpm scriptlet tweaks for v1.4 -> v1.5 upgrade --- build-linux/rpm/posttrans | 3 ++- build-linux/rpm/preinst | 6 ++++++ scripts/setup_upgrade_test.sh | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build-linux/rpm/posttrans b/build-linux/rpm/posttrans index 5bec83a4..b986b389 100644 --- a/build-linux/rpm/posttrans +++ b/build-linux/rpm/posttrans @@ -36,10 +36,11 @@ reinstate_init () { } if [ -e "/tmp/pdagent_upgrade.txt" ]; then - # reinstate /etc/init.d/pdagent that was deleted by v1.4 pkg removal if which systemctl >/dev/null; then : else + # reinstate /etc/init.d/pdagent that was deleted by v1.4 pkg removal + # this is a one-time fix and can be removed on the next version rev (v1.6) reinstate_init fi diff --git a/build-linux/rpm/preinst b/build-linux/rpm/preinst index a5657c15..5c7fcc9c 100644 --- a/build-linux/rpm/preinst +++ b/build-linux/rpm/preinst @@ -33,6 +33,12 @@ set -e if [ $1 -gt 1 ]; then # this is an upgrade # drop a file so posttrans knows this is an upgrade touch /tmp/pdagent_upgrade.txt + + # try to shutdown v1.4 agent via sysV script on systemd enabled envs + # this is a one-time fix and can be removed on the next version rev (v1.6) + if which systemctl >/dev/null && [ -e /etc/init.d/pdagent ]; then + /etc/init.d/pdagent stop + fi else # this is a remove : # no-op fi diff --git a/scripts/setup_upgrade_test.sh b/scripts/setup_upgrade_test.sh index 4610a1ac..5ae96b57 100755 --- a/scripts/setup_upgrade_test.sh +++ b/scripts/setup_upgrade_test.sh @@ -1,3 +1,5 @@ scripts/setup_upgrade_test_centos65.sh +scripts/setup_upgrade_test_centos72.sh scripts/setup_upgrade_test_ubuntu1204.sh scripts/setup_upgrade_test_ubuntu1404.sh +scripts/setup_upgrade_test_ubuntu1604.sh From 6053b635b9885c875fd58dffb8b0283ceb23d58f Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 13 Aug 2018 13:03:07 -0700 Subject: [PATCH 7/7] setting util.sh service key back to CHANGEME --- pdagenttestinteg/util.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdagenttestinteg/util.sh b/pdagenttestinteg/util.sh index 52a9f61d..407994c4 100644 --- a/pdagenttestinteg/util.sh +++ b/pdagenttestinteg/util.sh @@ -38,7 +38,7 @@ OUTQUEUE_DIR=$DATA_DIR/outqueue AGENT_SVC_NAME=pdagent SEND_INTERVAL_SECS=5 # The service key to use for testing commands like pd-send etc. -SVC_KEY=24124788d819478298bd55f0b8c3a19f +SVC_KEY=CHANGEME # return OS type of current system. os_type() {