systemd/man/systemd-run.html
2015-02-17 11:22:16 +01:00

173 lines
19 KiB
HTML

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>systemd-run</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
visibility: hidden;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
visibility: visible;
}
</style><a href="index.html">Index </a>·
<a href="systemd.directives.html">Directives </a>·
<a href="../python-systemd/index.html">Python </a>·
<a href="../libudev/index.html">libudev </a>·
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 219</span><hr><div class="refentry"><a name="systemd-run"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>systemd-run — Run programs in transient scope or service or timer units</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">systemd-run</code> [OPTIONS...] <em class="replaceable"><code>COMMAND</code></em>
[ARGS...]
</p></div><div class="cmdsynopsis"><p><code class="command">systemd-run</code> [OPTIONS...] [TIMER OPTIONS...] {<em class="replaceable"><code>COMMAND</code></em>} [ARGS...]</p></div></div><div class="refsect1"><a name="idm140590085173824"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><span class="command"><strong>systemd-run</strong></span> may be used to create and
start a transient <code class="filename">.service</code> or a transient
<code class="filename">.timer</code> or a <code class="filename">.scope</code> unit
and run the specified <em class="replaceable"><code>COMMAND</code></em> in
it.</p><p>If a command is run as transient service unit, it will be
started and managed by the service manager like any other service,
and thus show up in the output of <span class="command"><strong>systemctl
list-units</strong></span> like any other unit. It will run in a clean
and detached execution environment. <span class="command"><strong>systemd-run</strong></span>
will start the service asynchronously in the background and
immediately return.</p><p>If a command is run with timer options, transient timer unit
also be created with transient service unit. But the transient
timer unit is only started immediately. The transient service unit
will be started when the transient timer is elapsed. If
<code class="option">--unit=</code> is specified with timer options, the
<em class="replaceable"><code>COMMAND</code></em> can be omitted. In this case,
<span class="command"><strong>systemd-run</strong></span> assumes service unit is already
loaded and creates transient timer unit only. To successfully
create timer unit, already loaded service unit should be specified
with <code class="option">--unit=</code>. This transient timer unit can
activate the existing service unit like any other timer.</p><p>If a command is run as transient scope unit, it will be
started directly by <span class="command"><strong>systemd-run</strong></span> and thus
inherit the execution environment of the caller. It is however
managed by the service manager similar to normal services, and
will also show up in the output of <span class="command"><strong>systemctl
list-units</strong></span>. Execution in this case is synchronous, and
execution will return only when the command finishes.</p></div><div class="refsect1"><a name="idm140590089065120"></a><h2 id="Options">Options<a class="headerlink" title="Permalink to this headline" href="#Options"></a></h2><p>The following options are understood:</p><div class="variablelist"><dl class="variablelist"><dt id="--scope"><span class="term"><code class="option">--scope</code></span><a class="headerlink" title="Permalink to this term" href="#--scope"></a></dt><dd><p>Create a transient <code class="filename">.scope</code> unit instead of
the default transient <code class="filename">.service</code> unit.
</p></dd><dt id="--unit="><span class="term"><code class="option">--unit=</code></span><a class="headerlink" title="Permalink to this term" href="#--unit="></a></dt><dd><p>Use this unit name instead of an automatically
generated one.</p></dd><dt id="--property="><span class="term"><code class="option">--property=</code>, </span><span class="term"><code class="option">-p</code></span><a class="headerlink" title="Permalink to this term" href="#--property="></a></dt><dd><p>Sets a unit property for the scope or service
unit that is created. This takes an assignment in the same
format as
<a href="systemctl.html"><span class="citerefentry"><span class="refentrytitle">systemctl</span>(1)</span></a>'s
<span class="command"><strong>set-property</strong></span> command.</p></dd><dt id="--description="><span class="term"><code class="option">--description=</code></span><a class="headerlink" title="Permalink to this term" href="#--description="></a></dt><dd><p>Provide a description for the service or scope
unit. If not specified, the command itself will be used as a
description. See <code class="varname">Description=</code> in
<a href="systemd.unit.html"><span class="citerefentry"><span class="refentrytitle">systemd.unit</span>(5)</span></a>.
</p></dd><dt id="--slice="><span class="term"><code class="option">--slice=</code></span><a class="headerlink" title="Permalink to this term" href="#--slice="></a></dt><dd><p>Make the new <code class="filename">.service</code> or
<code class="filename">.scope</code> unit part of the specified slice,
instead of the <code class="filename">system.slice</code>.</p></dd><dt id="--remain-after-exit"><span class="term"><code class="option">--remain-after-exit</code></span><a class="headerlink" title="Permalink to this term" href="#--remain-after-exit"></a></dt><dd><p>After the service or scope process has
terminated, keep the service around until it is explicitly
stopped. This is useful to collect runtime information about
the service after it finished running. Also see
<code class="varname">RemainAfterExit=</code> in
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>.
</p></dd><dt id="--send-sighup"><span class="term"><code class="option">--send-sighup</code></span><a class="headerlink" title="Permalink to this term" href="#--send-sighup"></a></dt><dd><p>When terminating the scope or service unit,
send a SIGHUP immediately after SIGTERM. This is useful to
indicate to shells and shell-like processes that the
connection has been severed. Also see
<code class="varname">SendSIGHUP=</code> in
<a href="systemd.kill.html"><span class="citerefentry"><span class="refentrytitle">systemd.kill</span>(5)</span></a>.
</p></dd><dt id="--service-type="><span class="term"><code class="option">--service-type=</code></span><a class="headerlink" title="Permalink to this term" href="#--service-type="></a></dt><dd><p>Sets the service type. Also see
<code class="varname">Type=</code> in
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>. This
option has no effect in conjunction with
<code class="option">--scope</code>. Defaults to
<code class="constant">simple</code>.</p></dd><dt id="--uid="><span class="term"><code class="option">--uid=</code>, </span><span class="term"><code class="option">--gid=</code></span><a class="headerlink" title="Permalink to this term" href="#--uid="></a></dt><dd><p>Runs the service process under the UNIX user
and group. Also see <code class="varname">User=</code> and
<code class="varname">Group=</code> in
<a href="systemd.exec.html"><span class="citerefentry"><span class="refentrytitle">systemd.exec</span>(5)</span></a>.</p></dd><dt id="--nice="><span class="term"><code class="option">--nice=</code></span><a class="headerlink" title="Permalink to this term" href="#--nice="></a></dt><dd><p>Runs the service process with the specified
nice level. Also see <code class="varname">Nice=</code> in
<a href="systemd.exec.html"><span class="citerefentry"><span class="refentrytitle">systemd.exec</span>(5)</span></a>.</p></dd><dt id="--setenv="><span class="term"><code class="option">--setenv=</code></span><a class="headerlink" title="Permalink to this term" href="#--setenv="></a></dt><dd><p>Runs the service process with the specified
environment variables set. Also see
<code class="varname">Environment=</code> in
<a href="systemd.exec.html"><span class="citerefentry"><span class="refentrytitle">systemd.exec</span>(5)</span></a>.</p></dd><dt id="--pty"><span class="term"><code class="option">--pty</code>, </span><span class="term"><code class="option">-t</code></span><a class="headerlink" title="Permalink to this term" href="#--pty"></a></dt><dd><p>When invoking a command as service connects
its standard input and output to the invoking tty via a
pseudo TTY device. This allows invoking binaries as services
that expect interactive user input, such as interactive
command shells.</p></dd><dt id="--quiet"><span class="term"><code class="option">--quiet</code>, </span><span class="term"><code class="option">-q</code></span><a class="headerlink" title="Permalink to this term" href="#--quiet"></a></dt><dd><p>Suppresses additional informational output
while running. This is particularly useful in combination with
<code class="option">--pty</code> when it will suppress the initial
message explaining how to terminate the TTY connection.</p></dd><dt id="--on-active="><span class="term"><code class="option">--on-active=</code>, </span><span class="term"><code class="option">--on-boot=</code>, </span><span class="term"><code class="option">--on-startup=</code>, </span><span class="term"><code class="option">--on-unit-active=</code>, </span><span class="term"><code class="option">--on-unit-inactive=</code></span><a class="headerlink" title="Permalink to this term" href="#--on-active="></a></dt><dd><p>Defines monotonic timers relative to different
starting points. Also see <code class="varname">OnActiveSec=</code>,
<code class="varname">OnBootSec=</code>,
<code class="varname">OnStartupSec=</code>,
<code class="varname">OnUnitActiveSec=</code> and
<code class="varname">OnUnitInactiveSec=</code> in
<a href="systemd.timer.html"><span class="citerefentry"><span class="refentrytitle">systemd.timer</span>(5)</span></a>. This
options have no effect in conjunction with
<code class="option">--scope</code>.</p></dd><dt id="--on-calendar="><span class="term"><code class="option">--on-calendar=</code></span><a class="headerlink" title="Permalink to this term" href="#--on-calendar="></a></dt><dd><p>Defines realtime (i.e. wallclock) timers with
calendar event expressions. Also see
<code class="varname">OnCalendar=</code> in
<a href="systemd.timer.html"><span class="citerefentry"><span class="refentrytitle">systemd.timer</span>(5)</span></a>. This
option has no effect in conjunction with
<code class="option">--scope</code>.</p></dd><dt id="--timer-property="><span class="term"><code class="option">--timer-property=</code></span><a class="headerlink" title="Permalink to this term" href="#--timer-property="></a></dt><dd><p>Sets a timer unit property for the timer unit
that is created. It is similar with
<code class="option">--property</code> but only for created timer
unit. This option only has effect in conjunction with
<code class="option">--on-active=</code>, <code class="option">--on-boot=</code>,
<code class="option">--on-startup=</code>,
<code class="option">--on-unit-active=</code>,
<code class="option">--on-unit-inactive=</code>,
<code class="option">--on-calendar=</code>. This takes an assignment in
the same format as
<a href="systemctl.html"><span class="citerefentry"><span class="refentrytitle">systemctl</span>(1)</span></a>'s
<span class="command"><strong>set-property</strong></span> command.</p></dd><dt id="--user"><span class="term"><code class="option">--user</code></span><a class="headerlink" title="Permalink to this term" href="#--user"></a></dt><dd><p><a name="user-text"></a>Talk to the service manager of the calling user,
rather than the service manager of the system.</p></dd><dt id="--system"><span class="term"><code class="option">--system</code></span><a class="headerlink" title="Permalink to this term" href="#--system"></a></dt><dd><p><a name="system-text"></a>Talk to the service manager of the system. This is the
implied default.</p></dd><dt id="-H"><span class="term"><code class="option">-H</code>, </span><span class="term"><code class="option">--host=</code></span><a class="headerlink" title="Permalink to this term" href="#-H"></a></dt><dd><p><a name="host-text"></a>Execute the operation remotely. Specify a hostname, or a
username and hostname separated by "<code class="literal">@</code>", to
connect to. The hostname may optionally be suffixed by a
container name, separated by "<code class="literal">:</code>", which
connects directly to a specific container on the specified
host. This will use SSH to talk to the remote machine manager
instance. Container names may be enumerated with
<span class="command"><strong>machinectl -H
<em class="replaceable"><code>HOST</code></em></strong></span>.</p></dd><dt id="-M"><span class="term"><code class="option">-M</code>, </span><span class="term"><code class="option">--machine=</code></span><a class="headerlink" title="Permalink to this term" href="#-M"></a></dt><dd><p><a name="machine-text"></a>Execute operation on a local container. Specify a
container name to connect to.</p></dd><dt id="-h"><span class="term"><code class="option">-h</code>, </span><span class="term"><code class="option">--help</code></span><a class="headerlink" title="Permalink to this term" href="#-h"></a></dt><dd><p><a name="help-text"></a>Print a short help text and exit.
</p></dd><dt id="--version"><span class="term"><code class="option">--version</code></span><a class="headerlink" title="Permalink to this term" href="#--version"></a></dt><dd><p><a name="version-text"></a>Print a short version string and exit.</p></dd></dl></div><p>All command line arguments after the first non-option
argument become part of the command line of the launched
process. If a command is run as service unit, its first argument
needs to be an absolute binary path.</p></div><div class="refsect1"><a name="idm140590084082416"></a><h2 id="Exit status">Exit status<a class="headerlink" title="Permalink to this headline" href="#Exit%20status"></a></h2><p>On success, 0 is returned, a non-zero failure
code otherwise.</p></div><div class="refsect1"><a name="idm140590084081264"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples"></a></h2><p>The following command will log the environment variables
provided by systemd to services:</p><pre class="programlisting"># systemd-run env
Running as unit run-19945.service.
# journalctl -u run-19945.service
Sep 08 07:37:21 bupkis systemd[1]: Starting /usr/bin/env...
Sep 08 07:37:21 bupkis systemd[1]: Started /usr/bin/env.
Sep 08 07:37:21 bupkis env[19948]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Sep 08 07:37:21 bupkis env[19948]: LANG=en_US.UTF-8
Sep 08 07:37:21 bupkis env[19948]: BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.x86_64</pre><p>The following command invokes the
<a href="http://man7.org/linux/man-pages/man8/updatedb.8.html"><span class="citerefentry"><span class="refentrytitle">updatedb</span>(8)</span></a>
tool, but lowers the block IO weight for it to 10. See
<a href="systemd.resource-control.html"><span class="citerefentry"><span class="refentrytitle">systemd.resource-control</span>(5)</span></a>
for more information on the <code class="varname">BlockIOWeight=</code>
property.</p><pre class="programlisting"># systemd-run -p BlockIOWeight=10 updatedb</pre><p>The following command will touch a file after 30 seconds.</p><pre class="programlisting"># date; systemd-run --on-active=30 --timer-property=AccuracySec=100ms /bin/touch /tmp/foo
Mon Dec 8 20:44:24 KST 2014
Running as unit run-71.timer.
Will run as unit run-71.service.
# journalctl -b -u run-73.timer
-- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
Dec 08 20:44:38 container systemd[1]: Starting /bin/touch /tmp/foo.
Dec 08 20:44:38 container systemd[1]: Started /bin/touch /tmp/foo.
# journalctl -b -u run-73.service
-- Logs begin at Fri 2014-12-05 19:09:21 KST, end at Mon 2014-12-08 20:44:54 KST. --
Dec 08 20:44:48 container systemd[1]: Starting /bin/touch /tmp/foo...
Dec 08 20:44:48 container systemd[1]: Started /bin/touch /tmp/foo.</pre><p>The following command invokes <code class="filename">/bin/bash</code>
as a service passing its standard input, output and error to
the calling TTY.</p><pre class="programlisting"># systemd-run -t /bin/bash</pre></div><div class="refsect1"><a name="idm140590084072320"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
<a href="systemctl.html"><span class="citerefentry"><span class="refentrytitle">systemctl</span>(1)</span></a>,
<a href="systemd.unit.html"><span class="citerefentry"><span class="refentrytitle">systemd.unit</span>(5)</span></a>,
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>,
<a href="systemd.scope.html"><span class="citerefentry"><span class="refentrytitle">systemd.scope</span>(5)</span></a>,
<a href="systemd.slice.html"><span class="citerefentry"><span class="refentrytitle">systemd.slice</span>(5)</span></a>,
<a href="systemd.exec.html"><span class="citerefentry"><span class="refentrytitle">systemd.exec</span>(5)</span></a>,
<a href="systemd.resource-control.html"><span class="citerefentry"><span class="refentrytitle">systemd.resource-control</span>(5)</span></a>,
<a href="systemd.timer.html"><span class="citerefentry"><span class="refentrytitle">systemd.timer</span>(5)</span></a>,
<a href="machinectl.html"><span class="citerefentry"><span class="refentrytitle">machinectl</span>(1)</span></a>
</p></div></div></body></html>