summaryrefslogtreecommitdiffstats
path: root/test/units/testsuite-74.busctl.sh
blob: aaf96d08c1230ae90bbf72d33c472e22090c6ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail

# Unset $PAGER so we don't have to use --no-pager everywhere
export PAGER=

busctl --help
busctl help
busctl --version
busctl
busctl list --no-pager --allow-interactive-authorization=no
busctl list
busctl list --unique --show-machine --full
# Pass the JSON output (-j) through jq to check if it's valid
busctl list --acquired --activatable --no-legend -j | jq
busctl status
busctl status --machine=.host --augment-creds=no
busctl status --user --machine=testuser@.host
busctl status org.freedesktop.systemd1
# Ignore the exit code here, since this runs during machine bootup, so busctl
# might attempt to introspect a job that already finished and fail, i.e.:
# Failed to introspect object /org/freedesktop/systemd1/job/335 of service org.freedesktop.systemd1: Unknown object '/org/freedesktop/systemd1/job/335'.
busctl tree || :
busctl tree org.freedesktop.login1
busctl tree --list org.freedesktop.login1
busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd1
busctl introspect --watch-bind=yes --xml-interface org.freedesktop.systemd1 /org/freedesktop/LogControl1
busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager

busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
            GetDefaultTarget
# Pass both JSON outputs through jq to check if the response JSON is valid
busctl call --json=pretty \
            org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
            ListUnitsByNames as 2 "systemd-journald.service" "systemd-logind.service" | jq
busctl call --json=short \
            org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
            ListUnitsByNames as 2 "systemd-journald.service" "systemd-logind.service" | jq
# Get all properties on the org.freedesktop.systemd1.Manager interface and dump
# them as JSON to exercise the internal JSON transformations
busctl call -j \
            org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.DBus.Properties \
            GetAll s "org.freedesktop.systemd1.Manager" | jq -c
busctl call --verbose --timeout=60 --expect-reply=yes \
            org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
            ListUnitsByPatterns asas 1 "active" 2 "systemd-*.socket" "*.mount"

busctl emit /org/freedesktop/login1 org.freedesktop.login1.Manager \
            PrepareForSleep b false
busctl emit --auto-start=no --destination=systemd-logind.service \
            /org/freedesktop/login1 org.freedesktop.login1.Manager \
            PrepareForShutdown b false

busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    Version
busctl get-property --verbose \
                    org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    LogLevel LogTarget SystemState Version
# Pass both JSON outputs through jq to check if the response JSON is valid
busctl get-property --json=pretty \
                    org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    LogLevel LogTarget SystemState Version | jq
busctl get-property --json=short \
                    org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    LogLevel LogTarget SystemState Version | jq

# Set a property and check if it was indeed set
busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    KExecWatchdogUSec t 666
busctl get-property -j \
                    org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                    KExecWatchdogUSec | jq -e '.data == 666'

(! busctl status org.freedesktop.systemd2)
(! busctl tree org.freedesktop.systemd2)
(! busctl introspect org.freedesktop.systemd1)
(! busctl introspect org.freedesktop.systemd1 /org/freedesktop/systemd2)
(! busctl introspect org.freedesktop.systemd2 /org/freedesktop/systemd1)

# Invalid method
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
               ThisMethodDoesntExist)
# Invalid signature
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
               ListUnitsByNames ab 1 false)
# Invalid arguments
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
               GetUnitByPID u "hello")
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
               -- ListUnitsByNames as -1 "systemd-journald.service")
# Not enough arguments
(! busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
               ListUnitsByNames as 99 "systemd-journald.service")

(! busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                       NonexistentProperty)
(! busctl get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                       Version NonexistentProperty Version)

# Invalid property
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                       NonexistentProperty t 666)
# Invalid signature
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                       KExecWatchdogUSec s 666)
# Invalid argument
(! busctl set-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager \
                       KExecWatchdogUSec t "foo")