wiki/linux.systemd.transient-units.html
2022-07-29 15:41:17 +00:00

24 lines
6.7 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>systemd transient units</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>systemd transient units</h1><section class="post-metadata"><span>Date: <!-- -->2021-08-02 12:01:49 +08:00</span><span>Date modified: <!-- -->2022-04-16 20:01:51 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"></ol></nav><p>You can create units on-the-go with <code class="inline-verbatim">systemd-run</code>.
Very useful for quickly creating and scheduling one-off services.
This tool mainly involves <a href="/wiki/linux.systemd.services">systemd services</a> and <a href="/wiki/linux.systemd.timers">systemd timers</a>.
</p><p>Like most systemd-related binaries, this can be run at system- and user-level (see <a href="/wiki/linux.systemd#systemd-at-user-level">systemd at user-level</a>).
</p><pre class="src-block"><code class="language-shell"># This will create a user-level service file with the given command as the task.
systemd-run --user borgmatic --config emergency-config.yaml --verbose
# Create a transient timer for the service.
systemd-run --user borg-backup@external-drive.service --on-calendar=12:00
</code></pre><p>The result should give you the generated name of the unit.
Then, they can be managed like an ordinary unit.
Unit generated this way will persist until the next boot.
If you want to manage them on a permanent basis, create the appropriate unit files for them.
</p><section><h2>Backlinks</h2><ul><li><a href="/wiki/linux.systemd">systemd</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"2021-08-02 12:01:49 +08:00","date_modified":"2022-04-16 20:01:51 +08:00","language":"en","source":""},"title":"systemd transient units","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can create units on-the-go with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"systemd-run"}]},{"type":"text","value":".\nVery useful for quickly creating and scheduling one-off services.\nThis tool mainly involves "},{"type":"element","tagName":"a","properties":{"href":"/linux.systemd.services"},"children":[{"type":"text","value":"systemd services"}]},{"type":"text","value":" and "},{"type":"element","tagName":"a","properties":{"href":"/linux.systemd.timers"},"children":[{"type":"text","value":"systemd timers"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Like most systemd-related binaries, this can be run at system- and user-level (see "},{"type":"element","tagName":"a","properties":{"href":"/linux.systemd#systemd-at-user-level"},"children":[{"type":"text","value":"systemd at user-level"}]},{"type":"text","value":").\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"# This will create a user-level service file with the given command as the task.\nsystemd-run --user borgmatic --config emergency-config.yaml --verbose\n\n# Create a transient timer for the service.\nsystemd-run --user borg-backup@external-drive.service --on-calendar=12:00\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The result should give you the generated name of the unit.\nThen, they can be managed like an ordinary unit.\nUnit generated this way will persist until the next boot.\nIf you want to manage them on a permanent basis, create the appropriate unit files for them.\n"}]}]},"backlinks":[{"path":"/linux.systemd","title":"systemd"}]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["linux.systemd.transient-units"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>