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

[WIP] Add the ability to specify --root. #58017

Open
wants to merge 2 commits into
base: devel
from

Conversation

Projects
None yet
5 participants
@bcoca
Copy link
Member

commented Jun 18, 2019

When systemd is not running but changes has to be made such as enabling or disabling services,
using --root allows us to run systemctl without it.
This PR adds the ability to do just that.

(cherry picked from commit 5932c05)
rebase and fix for #44690

Also fix how scope is added, it should ony be needed with commands that use a 'unit'

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

systemd

thedrow and others added some commits Aug 26, 2018

Add the ability to specify --root.
When systemd is not running but changes has to be made such as enabling or disabling services,
using `--root` allows us to run systemctl without it.
This PR adds the ability to do just that.

(cherry picked from commit 5932c05)

Also fix how scope is added, it should ony be needed with commands that use a 'unit'
if module.params['no_block']:
systemctl += " --no-block"

if module.params['force']:
systemctl += " --force"

unit = module.params['name']

This comment has been minimized.

Copy link
@mkrizek

mkrizek Jul 1, 2019

Contributor

This can be removed since the same line has been added recently: https://github.com/ansible/ansible/blob/83bf90e/lib/ansible/modules/system/systemd.py#L343

@mkrizek
Copy link
Contributor

left a comment

One minor 'issue', looks good otherwise.

@tchernomax
Copy link
Contributor

left a comment

Also (but not related to this PR):

Line 481→485:

                if module.params['scope'] in (None, 'system') and \
                        not module.params['user'] and \
                        is_initd and \
                        not out.strip().endswith('disabled') and \
                        sysv_is_enabled(unit):

This code "fail" on the following configuration ; it detect the service as enabled, even the init.d service is supersede by the systemd service… and disabled:

root@test ~ # l /etc/init.d/toto /etc/rc5.d/S99toto /etc/systemd/system/toto.service
-rwxr-xr-x 1 root root 24 Jul  6 13:38 /etc/init.d/toto
lrwxrwxrwx 1 root root 16 Jul  6 13:42 /etc/rc5.d/S99toto -> /etc/init.d/toto
-rw-r--r-- 1 root root 74 Jul  6 13:41 /etc/systemd/system/toto.service
root@test ~ # systemctl is-enabled toto
disabled

Line 442:

module.warn('The service (%s) is actually an init script but the system is managed by systemd' % unit)

This warning is only triggered when you add an /etc/init.d/… file and don't daemon-reload.
It isn't throw every time/configuration when the service is "an init script but the system is managed by systemd".

Line 447:

masked = ('LoadState' in result['status'] and result['status']['LoadState'] == 'masked')

Just use is_masked (be sure to initialize it).
Also it doesn't work on chroot environment (when list-unit-files is used)

# The other choices match the corresponding switch
if module.params['scope'] not in (None, 'system'):
systemctl += " --%s" % module.params['scope']

This comment has been minimized.

Copy link
@tchernomax

tchernomax Jul 6, 2019

Contributor

if scope=user or scope=global, and daemon_reload=true or daemon_rexec=true → ansible will try to daemon-reload or daemon-rexec the system daemon (instead of the user one).

found = False
is_initd = sysv_exists(unit)
is_systemd = False

if module.params['root']:
systemctl_unit += " --root=%s" % module.params['root']

This comment has been minimized.

Copy link
@tchernomax

tchernomax Jul 6, 2019

Contributor

fail if scope=user.
(root and scope=user are incompatible)

# check service data, cannot error out on rc as it changes across versions, assume not found
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl_unit, unit))

This comment has been minimized.

Copy link
@tchernomax

tchernomax Jul 6, 2019

Contributor

fail if root is used:
show seams not to take into account the --root parameter, so we are "showing" the wrong unit.

max@mde-oxalide % sudo systemctl --root /var/lib/machines/arch-64-tmp/ show org.cups.cupsd.service | grep LoadState
LoadState=loaded
max@mde-oxalide % sudo find /var/lib/machines/arch-64-tmp/ -name org.cups.cupsd.service
max@mde-oxalide %
@@ -510,7 +524,7 @@ def main():
if action:
result['changed'] = True
if not module.check_mode:
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl_unit, action, unit))

This comment has been minimized.

Copy link
@tchernomax

tchernomax Jul 6, 2019

Contributor

fail if root is used.

@ansibot ansibot added needs_revision and removed core_review labels Jul 6, 2019

@bcoca bcoca changed the title Add the ability to specify --root. [WIP] Add the ability to specify --root. Jul 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.