pyinfra 0.11.dev3__py3-none-any.whl → 3.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyinfra/__init__.py +9 -12
- pyinfra/__main__.py +4 -0
- pyinfra/api/__init__.py +18 -3
- pyinfra/api/arguments.py +406 -0
- pyinfra/api/arguments_typed.py +79 -0
- pyinfra/api/command.py +274 -0
- pyinfra/api/config.py +222 -28
- pyinfra/api/connect.py +33 -13
- pyinfra/api/connectors.py +27 -0
- pyinfra/api/deploy.py +65 -66
- pyinfra/api/exceptions.py +67 -18
- pyinfra/api/facts.py +253 -202
- pyinfra/api/host.py +413 -50
- pyinfra/api/inventory.py +121 -160
- pyinfra/api/operation.py +432 -262
- pyinfra/api/operations.py +273 -260
- pyinfra/api/state.py +302 -248
- pyinfra/api/util.py +291 -368
- pyinfra/connectors/base.py +173 -0
- pyinfra/connectors/chroot.py +212 -0
- pyinfra/connectors/docker.py +381 -0
- pyinfra/connectors/dockerssh.py +297 -0
- pyinfra/connectors/local.py +238 -0
- pyinfra/connectors/scp/__init__.py +1 -0
- pyinfra/connectors/scp/client.py +204 -0
- pyinfra/connectors/ssh.py +670 -0
- pyinfra/connectors/ssh_util.py +114 -0
- pyinfra/connectors/sshuserclient/client.py +309 -0
- pyinfra/connectors/sshuserclient/config.py +102 -0
- pyinfra/connectors/terraform.py +135 -0
- pyinfra/connectors/util.py +410 -0
- pyinfra/connectors/vagrant.py +183 -0
- pyinfra/context.py +145 -0
- pyinfra/facts/__init__.py +7 -6
- pyinfra/facts/apk.py +22 -7
- pyinfra/facts/apt.py +117 -60
- pyinfra/facts/brew.py +100 -15
- pyinfra/facts/bsdinit.py +23 -0
- pyinfra/facts/cargo.py +37 -0
- pyinfra/facts/choco.py +47 -0
- pyinfra/facts/crontab.py +195 -0
- pyinfra/facts/deb.py +94 -0
- pyinfra/facts/dnf.py +48 -0
- pyinfra/facts/docker.py +96 -23
- pyinfra/facts/efibootmgr.py +113 -0
- pyinfra/facts/files.py +630 -58
- pyinfra/facts/flatpak.py +77 -0
- pyinfra/facts/freebsd.py +70 -0
- pyinfra/facts/gem.py +19 -6
- pyinfra/facts/git.py +59 -14
- pyinfra/facts/gpg.py +150 -0
- pyinfra/facts/hardware.py +313 -167
- pyinfra/facts/iptables.py +72 -62
- pyinfra/facts/launchd.py +44 -0
- pyinfra/facts/lxd.py +17 -4
- pyinfra/facts/mysql.py +122 -86
- pyinfra/facts/npm.py +17 -9
- pyinfra/facts/openrc.py +71 -0
- pyinfra/facts/opkg.py +246 -0
- pyinfra/facts/pacman.py +50 -7
- pyinfra/facts/pip.py +24 -7
- pyinfra/facts/pipx.py +82 -0
- pyinfra/facts/pkg.py +15 -6
- pyinfra/facts/pkgin.py +35 -0
- pyinfra/facts/podman.py +54 -0
- pyinfra/facts/postgres.py +178 -0
- pyinfra/facts/postgresql.py +6 -147
- pyinfra/facts/rpm.py +105 -0
- pyinfra/facts/runit.py +77 -0
- pyinfra/facts/selinux.py +161 -0
- pyinfra/facts/server.py +746 -285
- pyinfra/facts/snap.py +88 -0
- pyinfra/facts/systemd.py +139 -0
- pyinfra/facts/sysvinit.py +59 -0
- pyinfra/facts/upstart.py +35 -0
- pyinfra/facts/util/__init__.py +17 -0
- pyinfra/facts/util/databases.py +4 -6
- pyinfra/facts/util/packaging.py +37 -6
- pyinfra/facts/util/units.py +30 -0
- pyinfra/facts/util/win_files.py +99 -0
- pyinfra/facts/vzctl.py +20 -13
- pyinfra/facts/xbps.py +35 -0
- pyinfra/facts/yum.py +34 -40
- pyinfra/facts/zfs.py +77 -0
- pyinfra/facts/zypper.py +42 -0
- pyinfra/local.py +45 -83
- pyinfra/operations/__init__.py +12 -0
- pyinfra/operations/apk.py +98 -0
- pyinfra/operations/apt.py +488 -0
- pyinfra/operations/brew.py +231 -0
- pyinfra/operations/bsdinit.py +59 -0
- pyinfra/operations/cargo.py +45 -0
- pyinfra/operations/choco.py +61 -0
- pyinfra/operations/crontab.py +191 -0
- pyinfra/operations/dnf.py +210 -0
- pyinfra/operations/docker.py +446 -0
- pyinfra/operations/files.py +1939 -0
- pyinfra/operations/flatpak.py +94 -0
- pyinfra/operations/freebsd/__init__.py +12 -0
- pyinfra/operations/freebsd/freebsd_update.py +70 -0
- pyinfra/operations/freebsd/pkg.py +219 -0
- pyinfra/operations/freebsd/service.py +116 -0
- pyinfra/operations/freebsd/sysrc.py +92 -0
- pyinfra/operations/gem.py +47 -0
- pyinfra/operations/git.py +419 -0
- pyinfra/operations/iptables.py +311 -0
- pyinfra/operations/launchd.py +45 -0
- pyinfra/operations/lxd.py +68 -0
- pyinfra/operations/mysql.py +609 -0
- pyinfra/operations/npm.py +57 -0
- pyinfra/operations/openrc.py +63 -0
- pyinfra/operations/opkg.py +88 -0
- pyinfra/operations/pacman.py +81 -0
- pyinfra/operations/pip.py +205 -0
- pyinfra/operations/pipx.py +102 -0
- pyinfra/operations/pkg.py +70 -0
- pyinfra/operations/pkgin.py +91 -0
- pyinfra/operations/postgres.py +436 -0
- pyinfra/operations/postgresql.py +30 -0
- pyinfra/operations/puppet.py +40 -0
- pyinfra/operations/python.py +72 -0
- pyinfra/operations/runit.py +184 -0
- pyinfra/operations/selinux.py +189 -0
- pyinfra/operations/server.py +1099 -0
- pyinfra/operations/snap.py +117 -0
- pyinfra/operations/ssh.py +216 -0
- pyinfra/operations/systemd.py +149 -0
- pyinfra/operations/sysvinit.py +141 -0
- pyinfra/operations/upstart.py +68 -0
- pyinfra/operations/util/__init__.py +12 -0
- pyinfra/operations/util/docker.py +251 -0
- pyinfra/operations/util/files.py +247 -0
- pyinfra/operations/util/packaging.py +336 -0
- pyinfra/operations/util/service.py +46 -0
- pyinfra/operations/vzctl.py +137 -0
- pyinfra/operations/xbps.py +77 -0
- pyinfra/operations/yum.py +210 -0
- pyinfra/operations/zfs.py +175 -0
- pyinfra/operations/zypper.py +192 -0
- pyinfra/progress.py +44 -32
- pyinfra/py.typed +0 -0
- pyinfra/version.py +9 -1
- pyinfra-3.5.1.dist-info/METADATA +141 -0
- pyinfra-3.5.1.dist-info/RECORD +159 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info}/WHEEL +1 -2
- pyinfra-3.5.1.dist-info/entry_points.txt +12 -0
- {pyinfra-0.11.dev3.dist-info → pyinfra-3.5.1.dist-info/licenses}/LICENSE.md +1 -1
- pyinfra_cli/__init__.py +1 -0
- pyinfra_cli/cli.py +780 -0
- pyinfra_cli/commands.py +66 -0
- pyinfra_cli/exceptions.py +155 -65
- pyinfra_cli/inventory.py +233 -89
- pyinfra_cli/log.py +39 -43
- pyinfra_cli/main.py +26 -495
- pyinfra_cli/prints.py +215 -156
- pyinfra_cli/util.py +172 -105
- pyinfra_cli/virtualenv.py +25 -20
- pyinfra/api/connectors/__init__.py +0 -21
- pyinfra/api/connectors/ansible.py +0 -99
- pyinfra/api/connectors/docker.py +0 -178
- pyinfra/api/connectors/local.py +0 -169
- pyinfra/api/connectors/ssh.py +0 -402
- pyinfra/api/connectors/sshuserclient/client.py +0 -105
- pyinfra/api/connectors/sshuserclient/config.py +0 -90
- pyinfra/api/connectors/util.py +0 -63
- pyinfra/api/connectors/vagrant.py +0 -155
- pyinfra/facts/init.py +0 -176
- pyinfra/facts/util/files.py +0 -102
- pyinfra/hook.py +0 -41
- pyinfra/modules/__init__.py +0 -11
- pyinfra/modules/apk.py +0 -64
- pyinfra/modules/apt.py +0 -272
- pyinfra/modules/brew.py +0 -122
- pyinfra/modules/files.py +0 -711
- pyinfra/modules/gem.py +0 -30
- pyinfra/modules/git.py +0 -115
- pyinfra/modules/init.py +0 -344
- pyinfra/modules/iptables.py +0 -271
- pyinfra/modules/lxd.py +0 -45
- pyinfra/modules/mysql.py +0 -347
- pyinfra/modules/npm.py +0 -47
- pyinfra/modules/pacman.py +0 -60
- pyinfra/modules/pip.py +0 -99
- pyinfra/modules/pkg.py +0 -43
- pyinfra/modules/postgresql.py +0 -245
- pyinfra/modules/puppet.py +0 -20
- pyinfra/modules/python.py +0 -37
- pyinfra/modules/server.py +0 -524
- pyinfra/modules/ssh.py +0 -150
- pyinfra/modules/util/files.py +0 -52
- pyinfra/modules/util/packaging.py +0 -118
- pyinfra/modules/vzctl.py +0 -133
- pyinfra/modules/yum.py +0 -171
- pyinfra/pseudo_modules.py +0 -64
- pyinfra-0.11.dev3.dist-info/.DS_Store +0 -0
- pyinfra-0.11.dev3.dist-info/METADATA +0 -135
- pyinfra-0.11.dev3.dist-info/RECORD +0 -95
- pyinfra-0.11.dev3.dist-info/entry_points.txt +0 -3
- pyinfra-0.11.dev3.dist-info/top_level.txt +0 -2
- pyinfra_cli/__main__.py +0 -40
- pyinfra_cli/config.py +0 -92
- /pyinfra/{modules/util → connectors}/__init__.py +0 -0
- /pyinfra/{api/connectors → connectors}/sshuserclient/__init__.py +0 -0
pyinfra/modules/gem.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Mange gem packages.
|
|
3
|
-
'''
|
|
4
|
-
|
|
5
|
-
from pyinfra.api import operation
|
|
6
|
-
|
|
7
|
-
from .util.packaging import ensure_packages
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@operation
|
|
11
|
-
def packages(state, host, packages=None, present=True, latest=False):
|
|
12
|
-
'''
|
|
13
|
-
Add/remove/update gem packages.
|
|
14
|
-
|
|
15
|
-
+ packages: list of packages to ensure
|
|
16
|
-
+ present: whether the packages should be installed
|
|
17
|
-
+ latest: whether to upgrade packages without a specified version
|
|
18
|
-
|
|
19
|
-
Versions:
|
|
20
|
-
Package versions can be pinned like gem: ``<pkg>:<version>``.
|
|
21
|
-
'''
|
|
22
|
-
|
|
23
|
-
yield ensure_packages(
|
|
24
|
-
packages, host.fact.gem_packages, present,
|
|
25
|
-
install_command='gem install',
|
|
26
|
-
uninstall_command='gem uninstall',
|
|
27
|
-
upgrade_command='gem update',
|
|
28
|
-
version_join=':',
|
|
29
|
-
latest=latest,
|
|
30
|
-
)
|
pyinfra/modules/git.py
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Manage git repositories and configuration.
|
|
3
|
-
'''
|
|
4
|
-
|
|
5
|
-
import re
|
|
6
|
-
|
|
7
|
-
from pyinfra.api import operation, OperationError
|
|
8
|
-
|
|
9
|
-
from . import files, ssh
|
|
10
|
-
from .util.files import chown
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@operation(pipeline_facts={
|
|
14
|
-
'git_config': 'repo',
|
|
15
|
-
})
|
|
16
|
-
def config(
|
|
17
|
-
state, host, key, value,
|
|
18
|
-
repo=None,
|
|
19
|
-
):
|
|
20
|
-
'''
|
|
21
|
-
Manage git config for a repository or globally.
|
|
22
|
-
|
|
23
|
-
+ key: the key of the config to ensure
|
|
24
|
-
+ value: the value this key should have
|
|
25
|
-
+ repo: specify the git repo path to edit local config (defaults to global)
|
|
26
|
-
'''
|
|
27
|
-
|
|
28
|
-
existing_config = host.fact.git_config(repo)
|
|
29
|
-
|
|
30
|
-
if key not in existing_config or existing_config[key] != value:
|
|
31
|
-
if repo is None:
|
|
32
|
-
yield 'git config --global {0} "{1}"'.format(key, value)
|
|
33
|
-
else:
|
|
34
|
-
yield 'cd {0} && git config --local {1} "{2}"'.format(repo, key, value)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@operation(pipeline_facts={
|
|
38
|
-
'git_branch': 'target',
|
|
39
|
-
})
|
|
40
|
-
def repo(
|
|
41
|
-
state, host, source, target,
|
|
42
|
-
branch='master', pull=True, rebase=False,
|
|
43
|
-
user=None, group=None, ssh_keyscan=False,
|
|
44
|
-
update_submodules=False, recursive_submodules=False,
|
|
45
|
-
):
|
|
46
|
-
'''
|
|
47
|
-
Clone/pull git repositories.
|
|
48
|
-
|
|
49
|
-
+ source: the git source URL
|
|
50
|
-
+ target: target directory to clone to
|
|
51
|
-
+ branch: branch to pull/checkout
|
|
52
|
-
+ pull: pull any changes for the branch
|
|
53
|
-
+ rebase: when pulling, use ``--rebase``
|
|
54
|
-
+ user: chown files to this user after
|
|
55
|
-
+ group: chown files to this group after
|
|
56
|
-
+ ssh_keyscan: keyscan the remote host if not in known_hosts before clone/pull
|
|
57
|
-
+ update_submodules: update any git submodules
|
|
58
|
-
+ recursive_submodules: update git submodules recursively
|
|
59
|
-
'''
|
|
60
|
-
|
|
61
|
-
# Ensure our target directory exists
|
|
62
|
-
yield files.directory(state, host, target)
|
|
63
|
-
|
|
64
|
-
# Do we need to scan for the remote host key?
|
|
65
|
-
if ssh_keyscan:
|
|
66
|
-
# Attempt to parse the domain from the git repository
|
|
67
|
-
domain = re.match(r'^[a-zA-Z0-9]+@([0-9a-zA-Z\.\-]+)', source)
|
|
68
|
-
|
|
69
|
-
if domain:
|
|
70
|
-
yield ssh.keyscan(state, host, domain.group(1))
|
|
71
|
-
else:
|
|
72
|
-
raise OperationError(
|
|
73
|
-
'Could not parse domain (to SSH keyscan) from: {0}'.format(source),
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
# Store git commands for directory prefix
|
|
77
|
-
git_commands = []
|
|
78
|
-
is_repo = host.fact.directory('/'.join((target, '.git')))
|
|
79
|
-
|
|
80
|
-
# Cloning new repo?
|
|
81
|
-
if not is_repo:
|
|
82
|
-
git_commands.append('clone {0} --branch {1} .'.format(source, branch))
|
|
83
|
-
|
|
84
|
-
# Ensuring existing repo
|
|
85
|
-
else:
|
|
86
|
-
current_branch = host.fact.git_branch(target)
|
|
87
|
-
if current_branch != branch:
|
|
88
|
-
git_commands.append('fetch') # fetch to ensure we have the branch locally
|
|
89
|
-
git_commands.append('checkout {0}'.format(branch))
|
|
90
|
-
|
|
91
|
-
if pull:
|
|
92
|
-
if rebase:
|
|
93
|
-
git_commands.append('pull --rebase')
|
|
94
|
-
else:
|
|
95
|
-
git_commands.append('pull')
|
|
96
|
-
|
|
97
|
-
if update_submodules:
|
|
98
|
-
if recursive_submodules:
|
|
99
|
-
git_commands.append('submodule update --init --recursive')
|
|
100
|
-
else:
|
|
101
|
-
git_commands.append('submodule update --init')
|
|
102
|
-
|
|
103
|
-
# Attach prefixes for directory
|
|
104
|
-
command_prefix = 'cd {0} && git'.format(target)
|
|
105
|
-
git_commands = [
|
|
106
|
-
'{0} {1}'.format(command_prefix, command)
|
|
107
|
-
for command in git_commands
|
|
108
|
-
]
|
|
109
|
-
|
|
110
|
-
for cmd in git_commands:
|
|
111
|
-
yield cmd
|
|
112
|
-
|
|
113
|
-
# Apply any user or group
|
|
114
|
-
if user or group:
|
|
115
|
-
yield chown(target, user, group, recursive=True)
|
pyinfra/modules/init.py
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
Manages the state and configuration of init services. Support for:
|
|
3
|
-
|
|
4
|
-
+ SysVinit (/etc/init.d)
|
|
5
|
-
+ BSD init (/etc/rc.d)
|
|
6
|
-
+ Upstart
|
|
7
|
-
+ Systemctl
|
|
8
|
-
'''
|
|
9
|
-
|
|
10
|
-
from pyinfra.api import operation, OperationError
|
|
11
|
-
|
|
12
|
-
from . import files
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def _handle_service_control(
|
|
16
|
-
name, statuses, formatter, running, restarted, reloaded, command,
|
|
17
|
-
status_argument='status',
|
|
18
|
-
):
|
|
19
|
-
statuses = statuses or {}
|
|
20
|
-
status = statuses.get(name, None)
|
|
21
|
-
|
|
22
|
-
# If we don't know the status, we need to check if it's up before starting
|
|
23
|
-
# and/or restarting/reloading
|
|
24
|
-
if status is None:
|
|
25
|
-
yield '''
|
|
26
|
-
# If the service is running
|
|
27
|
-
if {status_command}; then
|
|
28
|
-
{stop_command}
|
|
29
|
-
{restart_command}
|
|
30
|
-
{reload_command}
|
|
31
|
-
|
|
32
|
-
# If the service is not running, we just start it (no re[start|load])
|
|
33
|
-
else
|
|
34
|
-
{start_command}
|
|
35
|
-
fi
|
|
36
|
-
'''.format(
|
|
37
|
-
status_command=formatter.format(name, status_argument),
|
|
38
|
-
start_command=(
|
|
39
|
-
formatter.format(name, 'start')
|
|
40
|
-
if running is True else 'true'
|
|
41
|
-
),
|
|
42
|
-
stop_command=(
|
|
43
|
-
formatter.format(name, 'stop')
|
|
44
|
-
if running is False else 'true'
|
|
45
|
-
),
|
|
46
|
-
restart_command=(
|
|
47
|
-
formatter.format(name, 'restart')
|
|
48
|
-
if restarted else 'true'
|
|
49
|
-
),
|
|
50
|
-
reload_command=(
|
|
51
|
-
formatter.format(name, 'reload')
|
|
52
|
-
if reloaded else 'true'
|
|
53
|
-
),
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
else:
|
|
57
|
-
# Need down but running
|
|
58
|
-
if running is False and status:
|
|
59
|
-
yield formatter.format(name, 'stop')
|
|
60
|
-
|
|
61
|
-
# Need running but down
|
|
62
|
-
if running is True and not status:
|
|
63
|
-
yield formatter.format(name, 'start')
|
|
64
|
-
|
|
65
|
-
# Only restart if the service is already running
|
|
66
|
-
if restarted and status:
|
|
67
|
-
yield formatter.format(name, 'restart')
|
|
68
|
-
|
|
69
|
-
# Only reload if the service is already reloaded
|
|
70
|
-
if reloaded and status:
|
|
71
|
-
yield formatter.format(name, 'reload')
|
|
72
|
-
|
|
73
|
-
# Always execute arbitrary commands as these may or may not rely on the service
|
|
74
|
-
# being up or down
|
|
75
|
-
if command:
|
|
76
|
-
yield formatter.format(name, command)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
@operation
|
|
80
|
-
def d(
|
|
81
|
-
state, host, name,
|
|
82
|
-
running=True, restarted=False, reloaded=False,
|
|
83
|
-
enabled=None, command=None,
|
|
84
|
-
):
|
|
85
|
-
'''
|
|
86
|
-
Manage the state of SysV Init (/etc/init.d) services.
|
|
87
|
-
|
|
88
|
-
+ name: name of the service to manage
|
|
89
|
-
+ running: whether the service should be running
|
|
90
|
-
+ restarted: whether the service should be restarted
|
|
91
|
-
+ reloaded: whether the service should be reloaded
|
|
92
|
-
+ enabled: whether this service should be enabled/disabled
|
|
93
|
-
+ command: command (eg. reload) to run like: ``/etc/init.d/<name> <command>``
|
|
94
|
-
|
|
95
|
-
Enabled:
|
|
96
|
-
Because managing /etc/rc.d/X files is a mess, only certain Linux distributions
|
|
97
|
-
support enabling/disabling services:
|
|
98
|
-
|
|
99
|
-
+ Ubuntu/Debian (``update-rc.d``)
|
|
100
|
-
+ CentOS/Fedora/RHEL (``chkconfig``)
|
|
101
|
-
+ Gentoo (``rc-update``)
|
|
102
|
-
|
|
103
|
-
For other distributions and more granular service control, see the
|
|
104
|
-
``init.d_enable`` operation.
|
|
105
|
-
'''
|
|
106
|
-
|
|
107
|
-
yield _handle_service_control(
|
|
108
|
-
name, host.fact.initd_status,
|
|
109
|
-
'/etc/init.d/{0} {1}',
|
|
110
|
-
running, restarted, reloaded, command,
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
if isinstance(enabled, bool):
|
|
114
|
-
start_links = host.fact.find_links('/etc/rc*.d/S*{0}'.format(name)) or []
|
|
115
|
-
|
|
116
|
-
# If no links exist, attempt to enable the service using distro-specific commands
|
|
117
|
-
if enabled is True and not start_links:
|
|
118
|
-
distro = host.fact.linux_distribution.get('name')
|
|
119
|
-
|
|
120
|
-
if distro in ('Ubuntu', 'Debian'):
|
|
121
|
-
yield 'update-rc.d {0} defaults'.format(name)
|
|
122
|
-
|
|
123
|
-
elif distro in ('CentOS', 'Fedora', 'Red Hat Enterprise Linux'):
|
|
124
|
-
yield 'chkconfig {0} --add'.format(name)
|
|
125
|
-
yield 'chkconfig {0} on'.format(name)
|
|
126
|
-
|
|
127
|
-
elif distro == 'Gentoo':
|
|
128
|
-
yield 'rc-update add {0} default'.format(name)
|
|
129
|
-
|
|
130
|
-
# Remove any /etc/rcX.d/<name> start links
|
|
131
|
-
elif enabled is False:
|
|
132
|
-
# No state checking, just blindly remove any that exist
|
|
133
|
-
for link in start_links:
|
|
134
|
-
yield 'rm -f {0}'.format(link)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
@operation
|
|
138
|
-
def d_enable(
|
|
139
|
-
state, host, name,
|
|
140
|
-
start_priority=20, stop_priority=80,
|
|
141
|
-
start_levels=(2, 3, 4, 5), stop_levels=(0, 1, 6),
|
|
142
|
-
):
|
|
143
|
-
'''
|
|
144
|
-
Manually enable /etc/init.d scripts by creating /etc/rcX.d/Y links.
|
|
145
|
-
|
|
146
|
-
+ name: name of the service to enable
|
|
147
|
-
+ start_priority: priority to start the service
|
|
148
|
-
+ stop_priority: priority to stop the service
|
|
149
|
-
+ start_levels: which runlevels should the service run when enabled
|
|
150
|
-
+ stop_levels: which runlevels should the service stop when enabled
|
|
151
|
-
'''
|
|
152
|
-
|
|
153
|
-
# Build link list
|
|
154
|
-
links = []
|
|
155
|
-
|
|
156
|
-
for level in start_levels:
|
|
157
|
-
links.append('/etc/rc{0}.d/S{1}{2}'.format(level, start_priority, name))
|
|
158
|
-
|
|
159
|
-
for level in stop_levels:
|
|
160
|
-
links.append('/etc/rc{0}.d/K{1}{2}'.format(level, stop_priority, name))
|
|
161
|
-
|
|
162
|
-
# Ensure all the new links exist
|
|
163
|
-
for link in links:
|
|
164
|
-
yield files.link(state, host, link, '/etc/init.d/{0}'.format(name))
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
@operation
|
|
168
|
-
def rc(
|
|
169
|
-
state, host, name,
|
|
170
|
-
running=True, restarted=False, reloaded=False,
|
|
171
|
-
command=None, enabled=None,
|
|
172
|
-
):
|
|
173
|
-
'''
|
|
174
|
-
Manage the state of BSD init (/etc/rc.d) services.
|
|
175
|
-
|
|
176
|
-
+ name: name of the service to manage
|
|
177
|
-
+ running: whether the service should be running
|
|
178
|
-
+ restarted: whether the service should be restarted
|
|
179
|
-
+ reloaded: whether the service should be reloaded
|
|
180
|
-
+ command: custom command to pass like: ``/etc/rc.d/<name> <command>``
|
|
181
|
-
+ enabled: whether this service should be enabled/disabled on boot
|
|
182
|
-
'''
|
|
183
|
-
|
|
184
|
-
yield _handle_service_control(
|
|
185
|
-
name, host.fact.rcd_status,
|
|
186
|
-
'/etc/rc.d/{0} {1}',
|
|
187
|
-
running, restarted, reloaded, command,
|
|
188
|
-
status_argument='check',
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
# BSD init is simple, just add/remove <name>_enabled="YES"
|
|
192
|
-
if isinstance(enabled, bool):
|
|
193
|
-
yield files.line(
|
|
194
|
-
state, host,
|
|
195
|
-
'/etc/rc.conf.local',
|
|
196
|
-
'^{0}_enable='.format(name),
|
|
197
|
-
replace='{0}_enable="YES"'.format(name),
|
|
198
|
-
present=enabled,
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
@operation
|
|
203
|
-
def upstart(
|
|
204
|
-
state, host, name,
|
|
205
|
-
running=True, restarted=False, reloaded=False,
|
|
206
|
-
command=None, enabled=None,
|
|
207
|
-
):
|
|
208
|
-
'''
|
|
209
|
-
Manage the state of upstart managed services.
|
|
210
|
-
|
|
211
|
-
+ name: name of the service to manage
|
|
212
|
-
+ running: whether the service should be running
|
|
213
|
-
+ restarted: whether the service should be restarted
|
|
214
|
-
+ reloaded: whether the service should be reloaded
|
|
215
|
-
+ command: custom command to pass like: ``/etc/rc.d/<name> <command>``
|
|
216
|
-
+ enabled: whether this service should be enabled/disabled on boot
|
|
217
|
-
|
|
218
|
-
Enabling/disabling services:
|
|
219
|
-
Upstart jobs define runlevels in their config files - as such there is no way to
|
|
220
|
-
edit/list these without fiddling with the config. So pyinfra simply manages the
|
|
221
|
-
existence of a ``/etc/init/<service>.override`` file, and sets its content to
|
|
222
|
-
"manual" to disable automatic start of services.
|
|
223
|
-
'''
|
|
224
|
-
|
|
225
|
-
yield _handle_service_control(
|
|
226
|
-
name, host.fact.upstart_status,
|
|
227
|
-
'initctl {1} {0}',
|
|
228
|
-
running, restarted, reloaded, command,
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
# Upstart jobs are setup w/runlevels etc in their config files, so here we just check
|
|
232
|
-
# there's no override file.
|
|
233
|
-
if enabled is True:
|
|
234
|
-
yield files.file(
|
|
235
|
-
state, host,
|
|
236
|
-
'/etc/init/{0}.override'.format(name),
|
|
237
|
-
present=False,
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
# Set the override file to "manual" to disable automatic start
|
|
241
|
-
elif enabled is False:
|
|
242
|
-
yield 'echo "manual" > /etc/init/{0}.override'.format(name)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
@operation
|
|
246
|
-
def systemd(
|
|
247
|
-
state, host, name,
|
|
248
|
-
running=True, restarted=False, reloaded=False,
|
|
249
|
-
command=None, enabled=None, daemon_reload=False,
|
|
250
|
-
):
|
|
251
|
-
'''
|
|
252
|
-
Manage the state of systemd managed services.
|
|
253
|
-
|
|
254
|
-
+ name: name of the service to manage
|
|
255
|
-
+ running: whether the service should be running
|
|
256
|
-
+ restarted: whether the service should be restarted
|
|
257
|
-
+ reloaded: whether the service should be reloaded
|
|
258
|
-
+ command: custom command to pass like: ``/etc/rc.d/<name> <command>``
|
|
259
|
-
+ enabled: whether this service should be enabled/disabled on boot
|
|
260
|
-
+ daemon_reload: reload the systemd daemon to read updated unit files
|
|
261
|
-
'''
|
|
262
|
-
|
|
263
|
-
if daemon_reload:
|
|
264
|
-
yield 'systemctl daemon-reload'
|
|
265
|
-
|
|
266
|
-
yield _handle_service_control(
|
|
267
|
-
name, host.fact.systemd_status,
|
|
268
|
-
'systemctl {1} {0}.service',
|
|
269
|
-
running, restarted, reloaded, command,
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
if isinstance(enabled, bool):
|
|
273
|
-
is_enabled = host.fact.systemd_enabled.get(name, False)
|
|
274
|
-
|
|
275
|
-
# Isn't enabled and want enabled?
|
|
276
|
-
if not is_enabled and enabled is True:
|
|
277
|
-
yield 'systemctl enable {0}.service'.format(name)
|
|
278
|
-
|
|
279
|
-
# Is enabled and want disabled?
|
|
280
|
-
elif is_enabled and enabled is False:
|
|
281
|
-
yield 'systemctl disable {0}.service'.format(name)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
@operation
|
|
285
|
-
def launchd(
|
|
286
|
-
state, host, name,
|
|
287
|
-
running=True, restarted=False, command=None,
|
|
288
|
-
):
|
|
289
|
-
'''
|
|
290
|
-
Manage the state of systemd managed services.
|
|
291
|
-
|
|
292
|
-
+ name: name of the service to manage
|
|
293
|
-
+ running: whether the service should be running
|
|
294
|
-
+ restarted: whether the service should be restarted
|
|
295
|
-
+ command: custom command to pass like: ``/etc/rc.d/<name> <command>``
|
|
296
|
-
+ enabled: whether this service should be enabled/disabled on boot
|
|
297
|
-
+ daemon_reload: reload the systemd daemon to read updated unit files
|
|
298
|
-
'''
|
|
299
|
-
|
|
300
|
-
yield _handle_service_control(
|
|
301
|
-
name, host.fact.launchd_status,
|
|
302
|
-
'launchctl {1} {0}',
|
|
303
|
-
# No support for restart/reload/command
|
|
304
|
-
running, None, None, None,
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
# No restart command, so just stop/start
|
|
308
|
-
is_running = host.fact.launchd_status.get(name, None)
|
|
309
|
-
if restarted and is_running:
|
|
310
|
-
yield 'launchctl stop {0}'.format(name)
|
|
311
|
-
yield 'launchctl start {0}'.format(name)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
@operation
|
|
315
|
-
def service(
|
|
316
|
-
state, host,
|
|
317
|
-
*args, **kwargs
|
|
318
|
-
):
|
|
319
|
-
'''
|
|
320
|
-
Manage the state of services. This command checks for the presence of all the
|
|
321
|
-
init systems pyinfra can handle and executes the relevant operation. See init
|
|
322
|
-
system sepcific operation for arguments.
|
|
323
|
-
'''
|
|
324
|
-
|
|
325
|
-
if host.fact.which('systemctl'):
|
|
326
|
-
yield systemd(state, host, *args, **kwargs)
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
if host.fact.which('initctl'):
|
|
330
|
-
yield upstart(state, host, *args, **kwargs)
|
|
331
|
-
return
|
|
332
|
-
|
|
333
|
-
if host.fact.directory('/etc/init.d'):
|
|
334
|
-
yield d(state, host, *args, **kwargs)
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
if host.fact.directory('/etc/rc.d'):
|
|
338
|
-
yield rc(state, host, *args, **kwargs)
|
|
339
|
-
return
|
|
340
|
-
|
|
341
|
-
raise OperationError((
|
|
342
|
-
'No init system found '
|
|
343
|
-
'(no systemctl, initctl, /etc/init.d or /etc/rc.d found)'
|
|
344
|
-
))
|