table of contents
| VARLINKCTL(1) | varlinkctl | VARLINKCTL(1) |
NAME¶
varlinkctl - Introspect with and invoke Varlink services
SYNOPSIS¶
varlinkctl [OPTIONS...] info ADDRESS
varlinkctl [OPTIONS...] list-interfaces ADDRESS
varlinkctl [OPTIONS...] list-methods ADDRESS [INTERFACE...]
varlinkctl [OPTIONS...] introspect ADDRESS [INTERFACE...]
varlinkctl [OPTIONS...] call ADDRESS METHOD [ARGUMENTS]
varlinkctl [OPTIONS...] --exec call ADDRESS METHOD ARGUMENTS -- CMDLINE
varlinkctl [OPTIONS...] serve METHOD {CMDLINE...}
varlinkctl [OPTIONS...] validate-idl [FILE]
DESCRIPTION¶
varlinkctl may be used to introspect and invoke Varlink[1] services.
Services are referenced by one of the following:
For convenience, these two simpler (redundant) service address syntaxes are also supported:
COMMANDS¶
The following commands are understood:
info ADDRESS
Added in version 255.
list-interfaces ADDRESS
Added in version 255.
list-methods ADDRESS [INTERFACE...]
Added in version 257.
introspect ADDRESS [INTERFACE...]
Added in version 255.
call ADDRESS METHOD [ARGUMENTS]
The reply parameters are written as JSON objects to STDOUT.
Added in version 255.
serve METHOD CMDLINE...
The listening socket must be passed via socket activation (i.e. the $LISTEN_FDS protocol), making this command suitable for use in socket-activated service units. When a client calls the specified method with the upgrade flag, the server sends a reply confirming the upgrade, then forks and executes the given command line with the upgraded connection on its standard input and output.
This effectively turns any command that speaks a protocol over standard input/output into a Varlink service, discoverable via the service registry and authenticated via socket credentials. Because each connection is handled by a forked child process, the service unit can apply systemd's sandboxing options (such as ProtectSystem=, etc.) and does not operate in the caller's environment.
Added in version 261.
list-registry
Added in version 260.
validate-idl [FILE]
Added in version 255.
help
Added in version 255.
OPTIONS¶
The following options are understood:
--more
If this mode is enabled, output is automatically switched to JSON-SEQ mode, so that individual reply objects can be easily discerned.
This switch has no effect on the method call timeout applied by default. Regardless of whether --more is specified or not, the default timeout will be 45s. Use --timeout= (see below) to change or disable the timeout. When invoking a method call that continuously returns updates, it is typically desirable to disable the timeout with --timeout=infinity. On the other hand, when invoking a --more method call for the purpose of enumerating objects (which likely will complete quickly), it is typically beneficial to leave the timeout logic enabled, for robustness reasons.
Added in version 255.
-E
Added in version 257.
--collect
Added in version 256.
--oneway
Added in version 255.
--upgrade
If --exec is not specified, varlinkctl acts as a bidirectional proxy: data read from standard input is forwarded to the upgraded connection, and data received from the connection is written to standard output.
If --exec is specified, the upgraded connection socket is placed on both standard input and standard output of the invoked process. This is similar to the regular --exec behavior (without --upgrade), which places the method call reply on standard input. The invoked process can thus simply read from and write to stdin/stdout to communicate over the upgraded protocol.
This option may not be combined with --more, --oneway, --collect, --graceful=, or --push-fd=.
Added in version 261.
--json=MODE
Added in version 255.
-j
Added in version 255.
--quiet, -q
Added in version 257.
--graceful=
Added in version 257.
--timeout=
Added in version 257.
--exec
Now that if --exec is specified the the third parameter to call is not optional (i.e. the method call parameters).
Added in version 258.
--push-fd=
Added in version 258.
--system, --user
Added in version 260.
--no-ask-password
--no-pager
-h, --help
--version
FILES & DIRECTORIES¶
/run/varlink/registry/
Use varlinkctl list-registry to show the contents of this directory.
(Inodes that neither qualify as socket inodes nor as symlinks to them shall be ignored. A future extension might introduce regular files and directories to enhance the registry functionality.)
Added in version 260.
EXAMPLES¶
Example 1. Investigating a Service
The following three commands inspect the "io.systemd.Resolve" service implemented by systemd-resolved.service(8), listing general service information and implemented interfaces, and then displaying the interface definition of its primary interface:
$ varlinkctl info /run/systemd/resolve/io.systemd.Resolve
Vendor: The systemd Project
Product: systemd (systemd-resolved)
Version: 254 (254-1522-g4790521^)
URL: https://systemd.io/ Interfaces: io.systemd
io.systemd.Resolve
org.varlink.service $ varlinkctl list-interfaces /run/systemd/resolve/io.systemd.Resolve io.systemd io.systemd.Resolve org.varlink.service $ varlinkctl introspect /run/systemd/resolve/io.systemd.Resolve io.systemd.Resolve interface io.systemd.Resolve type ResolvedAddress(
ifindex: ?int,
...
(Interface definition has been truncated in the example above, in the interest of brevity.)
Example 2. Invoking a Method
The following command resolves a hostname via systemd-resolved.service(8)'s ResolveHostname method call.
$ varlinkctl call /run/systemd/resolve/io.systemd.Resolve io.systemd.Resolve.ResolveHostname '{"name":"systemd.io","family":2}' -j
{
"addresses" : [
{
"ifindex" : 2,
"family" : 2,
"address" : [
185,
199,
111,
153
]
}
],
"name" : "systemd.io",
"flags" : 1048577
}
Example 3. Investigating a Service Executable
The following command inspects the /usr/lib/systemd/systemd-pcrextend executable and the IPC APIs it provides. It then invokes a method on it:
# varlinkctl info /usr/lib/systemd/systemd-pcrextend
Vendor: The systemd Project
Product: systemd (systemd-pcrextend)
Version: 254 (254-1536-g97734fb)
URL: https://systemd.io/ Interfaces: io.systemd
io.systemd.PCRExtend
org.varlink.service # varlinkctl introspect /usr/lib/systemd/systemd-pcrextend io.systemd.PCRExtend interface io.systemd.PCRExtend method Extend(
pcr: int,
text: ?string,
data: ?string ) -> () # varlinkctl call /usr/lib/systemd/systemd-pcrextend io.systemd.PCRExtend.Extend '{"pcr":15,"text":"foobar"}' {}
Example 4. Invoking a method remotely via SSH
The following command acquires a report about the identity of a remote host "somehost" from systemd-hostnamed.service(8) by connecting via SSH to the AF_UNIX socket the service listens on:
# varlinkctl call ssh-unix:somehost:/run/systemd/io.systemd.Hostname io.systemd.Hostname.Describe '{}'
To invoke a Varlink service binary directly on the remote host, rather than talking to a service via AF_UNIX can be done like this:
# varlinkctl call ssh-exec:somehost:systemd-creds org.varlink.service.GetInfo '{}'
Example 5. Serving a Sandboxed Decompressor via Protocol Upgrade
The following socket and service units expose xz decompression as a Varlink service. Clients connect and send compressed data over the upgraded connection, receiving decompressed output in return.
# /etc/systemd/system/varlink-decompress-xz.socket [Socket] ListenStream=/run/varlink/registry/com.example.Decompress.XZ [Install] WantedBy=sockets.target # /etc/systemd/system/varlink-decompress-xz.service [Service] ExecStart=varlinkctl serve com.example.Decompress.XZ xz -d DynamicUser=yes PrivateNetwork=yes ProtectSystem=strict ProtectHome=yes NoNewPrivileges=yes SystemCallFilter=~@privileged @resources MemoryMax=256M
A client can then decompress data through this service:
$ echo "hello" | xz | varlinkctl call --upgrade \
unix:/run/varlink/registry/com.example.Decompress.XZ \
com.example.Decompress.XZ '{}' hello
For quick testing without unit files, systemd-socket-activate can be used to provide the listening socket:
$ systemd-socket-activate -l /tmp/decompress.sock -- varlinkctl serve com.example.Decompress.XZ xz -d &
$ echo "hello" | xz | varlinkctl call --upgrade unix:/tmp/decompress.sock com.example.Decompress.XZ '{}'
hello
SEE ALSO¶
busctl(1), Varlink[1]
NOTES¶
- 1.
- Varlink
| systemd 261~rc2 |