WALinuxAgent/setup.py

351 строка
14 KiB
Python
Исходник Обычный вид История

2014-09-24 16:31:47 +04:00
#!/usr/bin/env python
#
# Microsoft Azure Linux Agent setup.py
#
# Copyright 2013 Microsoft Corporation
#
# 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.
#
2015-06-09 12:04:18 +03:00
import os
import subprocess
import sys
import setuptools
from setuptools import find_packages
from setuptools.command.install import install as _install
from azurelinuxagent.common.osutil import get_osutil
from azurelinuxagent.common.version import AGENT_NAME, AGENT_VERSION, \
2016-08-18 20:36:39 +03:00
AGENT_DESCRIPTION, \
DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME
2015-06-16 10:00:24 +03:00
root_dir = os.path.dirname(os.path.abspath(__file__)) # pylint: disable=invalid-name
2015-06-09 12:04:18 +03:00
os.chdir(root_dir)
2016-08-18 20:36:39 +03:00
2015-08-05 11:42:06 +03:00
def set_files(data_files, dest=None, src=None):
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_bin_files(data_files, dest, src=None):
if src is None:
src = ["bin/waagent", "bin/waagent2.0"]
2015-08-05 11:42:06 +03:00
data_files.append((dest, src))
def set_conf_files(data_files, dest="/etc", src=None):
if src is None:
src = ["config/waagent.conf"]
2015-08-05 11:42:06 +03:00
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_logrotate_files(data_files, dest="/etc/logrotate.d", src=None):
if src is None:
src = ["config/waagent.logrotate"]
2015-08-05 11:42:06 +03:00
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_sysv_files(data_files, dest="/etc/rc.d/init.d", src=None):
if src is None:
src = ["init/waagent"]
2015-08-05 11:42:06 +03:00
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_systemd_files(data_files, dest, src=None):
if src is None:
src = ["init/waagent.service"]
2015-08-05 11:42:06 +03:00
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_freebsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
if src is None:
src = ["init/freebsd/waagent"]
Add initial support for the OpenBSD operating system (#712) * Add initial support for the OpenBSD operating system There are some differences between FreeBSD, OpenBSD, and Linux. Notes: - OpenBSD ships LibreSSL, but WALinuxAgent needs OpenSSL for CMS, so use the openssl port and the "eopenssl" binary instead. - Don't run the custom DHCP client but parse /var/db/dhclient.leases.hvn0. OpenBSD's lease file uses a modified syntax. - OpenBSD does not have /proc. WALinuxAgent should never assume that the /proc filesystem is available. - OpenBSD does not have sudo, but its replacement doas. The OpenBSD class implements support for modifying the doas.conf file. - Unlike FreeBSD, OpenBSD supports and mounts UDF DVDs just fine. - Create a swap partition instead of a swap file on the resource disk. - Many other minor changes for OpenBSD TODO: - The /proc checks needs to be replaced with pgrep/ps etc. checks for OpenBSD. For now it just checks if /proc is available or returns without error. Make sure to install waagent with --register-service as setuptools will not set the permissions of /etc/rc.d/waagent correctly (the file has to be executable to be used by OpenBSD's rc system). * Remove debug statement that was use to fix mount_dvd on OpenBSD. * I accidentally replaced the FreeBSD resource disk handler. The OpenBSD disk handler is an addition, not a replacement. Found by jonathangray * pylint pylint found one bug in setting the password; other changes are just for the style. * strip newline from generated password hash. Issue reported by Lili Deng. * Keep AutoUpdate enabled, it was disabled for initial porting. Pointed out by @hglkrijger * Use a wildcard and delete all DHCP lease files on *BSD. Requested by @hglkrijger
2017-05-31 01:27:22 +03:00
data_files.append((dest, src))
def set_openbsd_rc_files(data_files, dest="/etc/rc.d/", src=None):
if src is None:
src = ["init/openbsd/waagent"]
2016-01-29 12:16:00 +03:00
data_files.append((dest, src))
2016-08-18 20:36:39 +03:00
def set_udev_files(data_files, dest="/etc/udev/rules.d/", src=None):
if src is None:
src = ["config/66-azure-storage.rules",
"config/99-azure-product-uuid.rules"]
data_files.append((dest, src))
2016-01-29 12:16:00 +03:00
def get_data_files(name, version, fullname): # pylint: disable=R0912
2015-06-16 10:00:24 +03:00
"""
Determine data_files according to distro name, version and init system type
"""
2016-08-18 20:36:39 +03:00
data_files = []
osutil = get_osutil()
systemd_dir_path = osutil.get_systemd_unit_file_install_path()
agent_bin_path = osutil.get_agent_bin_path()
2015-06-16 10:00:24 +03:00
2022-06-29 21:58:47 +03:00
if name in ('redhat', 'rhel', 'centos', 'almalinux', 'cloudlinux', 'rocky'):
2022-05-27 03:07:17 +03:00
if version.startswith("8") or version.startswith("9"):
2021-07-06 23:39:20 +03:00
# redhat8+ default to py3
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
else:
set_bin_files(data_files, dest=agent_bin_path)
2015-08-05 11:42:06 +03:00
set_conf_files(data_files)
set_logrotate_files(data_files)
set_udev_files(data_files)
2022-05-27 03:07:17 +03:00
if version.startswith("8") or version.startswith("9"):
2021-07-06 23:39:20 +03:00
# redhat 8+ uses systemd and python3
set_systemd_files(data_files, dest=systemd_dir_path,
src=["init/redhat/waagent.service",
"init/azure.slice",
"init/azure-vmextensions.slice"
])
2021-07-06 23:39:20 +03:00
elif version.startswith("6"):
2015-08-05 11:42:06 +03:00
set_sysv_files(data_files)
else:
2016-08-18 20:36:39 +03:00
# redhat7.0+ use systemd
set_systemd_files(data_files, dest=systemd_dir_path,
src=[
"init/redhat/py2/waagent.service",
"init/azure.slice",
"init/azure-vmextensions.slice"
])
if version.startswith("7.1"):
# TODO this is a mitigation to systemctl bug on 7.1
set_sysv_files(data_files)
elif name == 'arch':
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files, src=["config/arch/waagent.conf"])
set_udev_files(data_files)
set_systemd_files(data_files, dest=systemd_dir_path,
src=["init/arch/waagent.service"])
elif name in ('coreos', 'flatcar'):
set_bin_files(data_files, dest=agent_bin_path)
2016-08-18 20:36:39 +03:00
set_conf_files(data_files, dest="/usr/share/oem",
src=["config/coreos/waagent.conf"])
2015-08-05 11:42:06 +03:00
set_logrotate_files(data_files)
set_udev_files(data_files)
2016-08-18 20:36:39 +03:00
set_files(data_files, dest="/usr/share/oem",
2016-04-06 08:26:16 +03:00
src=["init/coreos/cloud-config.yml"])
elif "Clear Linux" in fullname:
set_bin_files(data_files, dest=agent_bin_path)
2016-10-20 20:03:33 +03:00
set_conf_files(data_files, dest="/usr/share/defaults/waagent",
src=["config/clearlinux/waagent.conf"])
set_systemd_files(data_files, dest=systemd_dir_path,
2016-10-20 20:03:33 +03:00
src=["init/clearlinux/waagent.service"])
elif name in ["mariner", "azurelinux"]:
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files, dest="/etc",
src=["config/mariner/waagent.conf"])
set_systemd_files(data_files, dest=systemd_dir_path,
src=["init/mariner/waagent.service"])
set_logrotate_files(data_files)
set_udev_files(data_files)
2015-06-18 08:50:46 +03:00
elif name == 'ubuntu':
2015-08-05 11:42:06 +03:00
set_conf_files(data_files, src=["config/ubuntu/waagent.conf"])
set_logrotate_files(data_files)
2017-05-03 22:30:05 +03:00
set_udev_files(data_files)
if version.startswith("12") or version.startswith("14"):
2016-08-18 20:36:39 +03:00
# Ubuntu12.04/14.04 - uses upstart
2021-07-01 04:12:02 +03:00
if version.startswith("12"):
set_bin_files(data_files, dest=agent_bin_path)
else:
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
2015-08-05 11:42:06 +03:00
set_files(data_files, dest="/etc/init",
src=["init/ubuntu/walinuxagent.conf"])
2016-08-18 20:36:39 +03:00
set_files(data_files, dest='/etc/default',
2015-08-05 11:42:06 +03:00
src=['init/ubuntu/walinuxagent'])
2015-08-06 20:59:59 +03:00
else:
2021-07-01 04:12:02 +03:00
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
2016-08-18 20:36:39 +03:00
# Ubuntu15.04+ uses systemd
set_systemd_files(data_files, dest=systemd_dir_path,
src=[
"init/ubuntu/walinuxagent.service",
"init/azure.slice",
"init/azure-vmextensions.slice"
])
elif name == 'suse' or name == 'opensuse': # pylint: disable=R1714
set_bin_files(data_files, dest=agent_bin_path)
2015-08-05 11:42:06 +03:00
set_conf_files(data_files, src=["config/suse/waagent.conf"])
set_logrotate_files(data_files)
set_udev_files(data_files)
if fullname == 'SUSE Linux Enterprise Server' and \
version.startswith('11') or \
fullname == 'openSUSE' and version.startswith(
'13.1'):
2016-08-18 20:36:39 +03:00
set_sysv_files(data_files, dest='/etc/init.d',
src=["init/suse/waagent"])
2015-06-29 14:02:22 +03:00
else:
2016-08-18 20:36:39 +03:00
# sles 12+ and openSUSE 13.2+ use systemd
set_systemd_files(data_files, dest=systemd_dir_path)
elif name == 'sles': # sles 15+ distro named as sles
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
set_conf_files(data_files, src=["config/suse/waagent.conf"])
set_logrotate_files(data_files)
set_udev_files(data_files)
# sles 15+ uses systemd and python3
set_systemd_files(data_files, dest=systemd_dir_path,
src=["init/sles/waagent.service"])
2016-01-15 12:13:15 +03:00
elif name == 'freebsd':
set_bin_files(data_files, dest=agent_bin_path)
2016-01-15 12:13:15 +03:00
set_conf_files(data_files, src=["config/freebsd/waagent.conf"])
Add initial support for the OpenBSD operating system (#712) * Add initial support for the OpenBSD operating system There are some differences between FreeBSD, OpenBSD, and Linux. Notes: - OpenBSD ships LibreSSL, but WALinuxAgent needs OpenSSL for CMS, so use the openssl port and the "eopenssl" binary instead. - Don't run the custom DHCP client but parse /var/db/dhclient.leases.hvn0. OpenBSD's lease file uses a modified syntax. - OpenBSD does not have /proc. WALinuxAgent should never assume that the /proc filesystem is available. - OpenBSD does not have sudo, but its replacement doas. The OpenBSD class implements support for modifying the doas.conf file. - Unlike FreeBSD, OpenBSD supports and mounts UDF DVDs just fine. - Create a swap partition instead of a swap file on the resource disk. - Many other minor changes for OpenBSD TODO: - The /proc checks needs to be replaced with pgrep/ps etc. checks for OpenBSD. For now it just checks if /proc is available or returns without error. Make sure to install waagent with --register-service as setuptools will not set the permissions of /etc/rc.d/waagent correctly (the file has to be executable to be used by OpenBSD's rc system). * Remove debug statement that was use to fix mount_dvd on OpenBSD. * I accidentally replaced the FreeBSD resource disk handler. The OpenBSD disk handler is an addition, not a replacement. Found by jonathangray * pylint pylint found one bug in setting the password; other changes are just for the style. * strip newline from generated password hash. Issue reported by Lili Deng. * Keep AutoUpdate enabled, it was disabled for initial porting. Pointed out by @hglkrijger * Use a wildcard and delete all DHCP lease files on *BSD. Requested by @hglkrijger
2017-05-31 01:27:22 +03:00
set_freebsd_rc_files(data_files)
elif name == 'openbsd':
set_bin_files(data_files, dest=agent_bin_path)
Add initial support for the OpenBSD operating system (#712) * Add initial support for the OpenBSD operating system There are some differences between FreeBSD, OpenBSD, and Linux. Notes: - OpenBSD ships LibreSSL, but WALinuxAgent needs OpenSSL for CMS, so use the openssl port and the "eopenssl" binary instead. - Don't run the custom DHCP client but parse /var/db/dhclient.leases.hvn0. OpenBSD's lease file uses a modified syntax. - OpenBSD does not have /proc. WALinuxAgent should never assume that the /proc filesystem is available. - OpenBSD does not have sudo, but its replacement doas. The OpenBSD class implements support for modifying the doas.conf file. - Unlike FreeBSD, OpenBSD supports and mounts UDF DVDs just fine. - Create a swap partition instead of a swap file on the resource disk. - Many other minor changes for OpenBSD TODO: - The /proc checks needs to be replaced with pgrep/ps etc. checks for OpenBSD. For now it just checks if /proc is available or returns without error. Make sure to install waagent with --register-service as setuptools will not set the permissions of /etc/rc.d/waagent correctly (the file has to be executable to be used by OpenBSD's rc system). * Remove debug statement that was use to fix mount_dvd on OpenBSD. * I accidentally replaced the FreeBSD resource disk handler. The OpenBSD disk handler is an addition, not a replacement. Found by jonathangray * pylint pylint found one bug in setting the password; other changes are just for the style. * strip newline from generated password hash. Issue reported by Lili Deng. * Keep AutoUpdate enabled, it was disabled for initial porting. Pointed out by @hglkrijger * Use a wildcard and delete all DHCP lease files on *BSD. Requested by @hglkrijger
2017-05-31 01:27:22 +03:00
set_conf_files(data_files, src=["config/openbsd/waagent.conf"])
set_openbsd_rc_files(data_files)
2017-12-05 11:10:48 +03:00
elif name == 'debian':
2021-07-01 04:12:02 +03:00
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
2017-12-05 11:13:00 +03:00
set_conf_files(data_files, src=["config/debian/waagent.conf"])
2017-12-05 11:10:48 +03:00
set_logrotate_files(data_files)
set_udev_files(data_files, dest="/lib/udev/rules.d")
if debian_has_systemd():
set_systemd_files(data_files, dest=systemd_dir_path)
elif name == 'devuan':
set_bin_files(data_files, dest=agent_bin_path,
src=["bin/py3/waagent", "bin/waagent2.0"])
set_files(data_files, dest="/etc/init.d",
src=['init/devuan/walinuxagent'])
set_files(data_files, dest="/etc/default",
src=['init/devuan/default/walinuxagent'])
set_conf_files(data_files, src=['config/devuan/waagent.conf'])
set_logrotate_files(data_files)
set_udev_files(data_files, dest="/lib/udev/rules.d")
elif name == 'iosxe':
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files, src=["config/iosxe/waagent.conf"])
set_logrotate_files(data_files)
set_udev_files(data_files)
set_systemd_files(data_files, dest=systemd_dir_path)
if version.startswith("7.1"):
# TODO this is a mitigation to systemctl bug on 7.1
set_sysv_files(data_files)
elif name == 'openwrt':
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files)
set_logrotate_files(data_files)
set_sysv_files(data_files, dest='/etc/init.d', src=["init/openwrt/waagent"])
elif name == 'photonos':
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files, src=["config/photonos/waagent.conf"])
set_systemd_files(data_files, dest=systemd_dir_path,
src=["init/photonos/waagent.service"])
elif name == 'fedora':
set_bin_files(data_files, dest=agent_bin_path)
set_conf_files(data_files)
set_logrotate_files(data_files)
set_udev_files(data_files)
set_systemd_files(data_files, dest=systemd_dir_path)
2015-08-05 11:42:06 +03:00
else:
2016-08-18 20:36:39 +03:00
# Use default setting
set_bin_files(data_files, dest=agent_bin_path)
2015-08-05 11:42:06 +03:00
set_conf_files(data_files)
set_logrotate_files(data_files)
set_udev_files(data_files)
2015-08-05 11:42:06 +03:00
set_sysv_files(data_files)
2015-06-04 09:19:12 +03:00
return data_files
2016-08-18 20:36:39 +03:00
def debian_has_systemd():
try:
return subprocess.check_output(
['cat', '/proc/1/comm']).strip().decode() == 'systemd'
except subprocess.CalledProcessError:
return False
class install(_install): # pylint: disable=C0103
2015-06-29 12:26:32 +03:00
user_options = _install.user_options + [
2015-06-16 10:00:24 +03:00
('lnx-distro=', None, 'target Linux distribution'),
('lnx-distro-version=', None, 'target Linux distribution version'),
2015-06-29 14:02:22 +03:00
('lnx-distro-fullname=', None, 'target Linux distribution full name'),
('register-service', None, 'register as startup service and start'),
2015-08-05 11:42:06 +03:00
('skip-data-files', None, 'skip data files installation'),
2015-06-16 10:00:24 +03:00
]
def initialize_options(self):
2015-06-29 12:26:32 +03:00
_install.initialize_options(self)
# pylint: disable=attribute-defined-outside-init
2015-07-20 09:54:00 +03:00
self.lnx_distro = DISTRO_NAME
self.lnx_distro_version = DISTRO_VERSION
self.lnx_distro_fullname = DISTRO_FULL_NAME
self.register_service = False
2022-12-16 02:18:43 +03:00
# All our data files are system-wide files that are not included in the egg; skip them when
# creating an egg.
self.skip_data_files = "bdist_egg" in sys.argv
# pylint: enable=attribute-defined-outside-init
2016-08-18 20:36:39 +03:00
2015-06-16 10:00:24 +03:00
def finalize_options(self):
2015-06-29 12:26:32 +03:00
_install.finalize_options(self)
2015-08-05 11:42:06 +03:00
if self.skip_data_files:
return
2015-06-16 10:00:24 +03:00
data_files = get_data_files(self.lnx_distro, self.lnx_distro_version,
2015-06-29 14:02:22 +03:00
self.lnx_distro_fullname)
2015-06-16 10:00:24 +03:00
self.distribution.data_files = data_files
self.distribution.reinitialize_command('install_data', True)
def run(self):
2015-06-29 12:26:32 +03:00
_install.run(self)
if self.register_service:
osutil = get_osutil()
osutil.register_agent_service()
2016-09-07 18:33:09 +03:00
osutil.stop_agent_service()
osutil.start_agent_service()
2015-06-16 10:00:24 +03:00
# Note to packagers and users from source.
# * In version 3.5 of Python distribution information handling in the platform
# module was deprecated. Depending on the Linux distribution the
# implementation may be broken prior to Python 3.8 where the functionality
# will be removed from Python 3.
# * In version 3.13 of Python, the crypt module was removed and legacycrypt is
# required instead.
requires = []
if sys.version_info[0] >= 3 and sys.version_info[1] >= 8:
requires.append('distro')
if sys.version_info[0] >= 3 and sys.version_info[1] >= 13:
requires.append('legacycrypt')
2016-08-18 20:36:39 +03:00
modules = [] # pylint: disable=invalid-name
if "bdist_egg" in sys.argv:
modules.append("__main__")
setuptools.setup(
name=AGENT_NAME,
version=AGENT_VERSION,
long_description=AGENT_DESCRIPTION,
author='Microsoft Corporation',
2016-08-18 20:36:39 +03:00
author_email='walinuxagent@microsoft.com',
platforms='Linux',
url='https://github.com/Azure/WALinuxAgent',
2016-08-18 20:36:39 +03:00
license='Apache License Version 2.0',
2021-11-09 12:16:17 +03:00
packages=find_packages(exclude=["tests*", "dcr*"]),
py_modules=modules,
install_requires=requires,
2016-08-18 20:36:39 +03:00
cmdclass={
'install': install
}
)