WALinuxAgent/setup.py

175 строки
6.8 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
2015-07-20 09:54:00 +03:00
from azurelinuxagent.metadata import AGENT_NAME, AGENT_VERSION, \
2015-07-23 06:33:19 +03:00
AGENT_DESCRIPTION, \
2015-07-20 09:54:00 +03:00
DISTRO_NAME, DISTRO_VERSION, DISTRO_FULL_NAME
2015-06-16 10:00:24 +03:00
2015-12-24 15:53:48 +03:00
from azurelinuxagent.agent import Agent
2015-06-16 10:00:24 +03:00
import setuptools
2015-06-04 09:19:12 +03:00
from setuptools import find_packages
2015-06-29 12:26:32 +03:00
from setuptools.command.install import install as _install
2014-09-24 16:31:47 +04:00
2015-06-09 12:04:18 +03:00
root_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(root_dir)
2015-08-05 11:42:06 +03:00
def set_files(data_files, dest=None, src=None):
data_files.append((dest, src))
def set_bin_files(data_files, dest="/usr/sbin",
src=["bin/waagent", "bin/waagent2.0"]):
data_files.append((dest, src))
def set_conf_files(data_files, dest="/etc", src=["config/waagent.conf"]):
data_files.append((dest, src))
def set_logrotate_files(data_files, dest="/etc/logrotate.d",
src=["config/waagent.logrotate"]):
data_files.append((dest, src))
def set_sysv_files(data_files, dest="/etc/rc.d/init.d", src=["init/waagent"]):
data_files.append((dest, src))
def set_systemd_files(data_files, dest="/lib/systemd/system",
src=["init/waagent.service"]):
data_files.append((dest, src))
2016-01-29 12:16:00 +03:00
def set_rc_files(data_files, dest="/etc/rc.d/", src=["init/freebsd/waagent"]):
data_files.append((dest, src))
2015-06-29 14:02:22 +03:00
def get_data_files(name, version, fullname):
2015-06-16 10:00:24 +03:00
"""
Determine data_files according to distro name, version and init system type
"""
2015-06-04 09:19:12 +03:00
data_files=[]
2015-06-16 10:00:24 +03:00
if name == 'redhat' or name == 'centos':
2015-08-05 11:42:06 +03:00
set_bin_files(data_files)
set_conf_files(data_files)
set_logrotate_files(data_files)
if version.startswith("6"):
2015-08-05 11:42:06 +03:00
set_sysv_files(data_files)
else:
#redhat7.0+ use systemd
set_systemd_files(data_files, dest="/usr/lib/systemd/system")
if version.startswith("7.1"):
#TODO this is a mitigation to systemctl bug on 7.1
set_sysv_files(data_files)
2015-08-05 11:42:06 +03:00
2015-06-16 10:00:24 +03:00
elif name == 'coreos':
2015-08-05 11:42:06 +03:00
set_bin_files(data_files, dest="/usr/share/oem/bin")
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_files(data_files, dest="/usr/share/oem",
src="init/coreos/cloud-config.yml")
2015-06-18 08:50:46 +03:00
elif name == 'ubuntu':
2015-08-05 11:42:06 +03:00
set_bin_files(data_files)
set_conf_files(data_files, src=["config/ubuntu/waagent.conf"])
set_logrotate_files(data_files)
if version.startswith("12") or version.startswith("14"):
#Ubuntu12.04/14.04 - uses upstart
2015-08-05 11:42:06 +03:00
set_files(data_files, dest="/etc/init",
src=["init/ubuntu/walinuxagent.conf"])
set_files(data_files, dest='/etc/default',
src=['init/ubuntu/walinuxagent'])
elif fullname == 'Snappy Ubuntu Core':
set_files(data_files, dest="<TODO>",
src=["init/ubuntu/snappy/walinuxagent.yml"])
2015-08-06 20:59:59 +03:00
else:
#Ubuntu15.04+ uses systemd
2015-08-06 20:59:59 +03:00
set_systemd_files(data_files,
src=["init/ubuntu/walinuxagent.service"])
2015-06-29 14:02:22 +03:00
elif name == 'suse':
2015-08-05 11:42:06 +03:00
set_bin_files(data_files)
set_conf_files(data_files, src=["config/suse/waagent.conf"])
set_logrotate_files(data_files)
if fullname == 'SUSE Linux Enterprise Server' and \
version.startswith('11') or \
fullname == 'openSUSE' and version.startswith('13.1'):
set_sysv_files(data_files, dest='/etc/init.d',
src=["init/suse/waagent"])
2015-06-29 14:02:22 +03:00
else:
#sles 12+ and openSUSE 13.2+ use systemd
set_systemd_files(data_files, dest='/usr/lib/systemd/system')
2016-01-15 12:13:15 +03:00
elif name == 'freebsd':
2016-01-29 12:16:00 +03:00
set_bin_files(data_files, dest="/usr/local/sbin")
2016-01-15 12:13:15 +03:00
set_conf_files(data_files, src=["config/freebsd/waagent.conf"])
2016-01-29 12:16:00 +03:00
set_rc_files(data_files)
2015-08-05 11:42:06 +03:00
else:
#Use default setting
set_bin_files(data_files)
set_conf_files(data_files)
set_logrotate_files(data_files)
set_sysv_files(data_files)
2015-06-04 09:19:12 +03:00
return data_files
2015-06-29 12:26:32 +03:00
class install(_install):
user_options = _install.user_options + [
2015-06-16 10:00:24 +03:00
# This will magically show up in member variable 'init_system'
2015-08-05 11:42:06 +03:00
('init-system=', None, 'deprecated, use --lnx-distro* instead'),
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'),
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)
self.init_system=None
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
2015-08-05 11:42:06 +03:00
self.skip_data_files = False
2015-06-29 12:26:32 +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
if self.init_system is not None:
print("WARNING: --init-system is deprecated,"
"use --lnx-distro* instead")
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:
2015-12-24 15:53:48 +03:00
Agent(False).register_service()
2015-06-16 10:00:24 +03:00
2015-07-20 09:54:00 +03:00
setuptools.setup(name=AGENT_NAME,
version=AGENT_VERSION,
2015-07-23 06:33:19 +03:00
long_description=AGENT_DESCRIPTION,
2015-06-16 10:00:24 +03:00
author= 'Yue Zhang, Stephen Zarkos, Eric Gable',
author_email = 'walinuxagent@microsoft.com',
platforms = 'Linux',
url='https://github.com/Azure/WALinuxAgent',
license = 'Apache License Version 2.0',
packages=find_packages(exclude=["tests"]),
cmdclass = {
2015-06-29 14:02:22 +03:00
'install': install
2015-06-16 10:00:24 +03:00
})