<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Systemd on Natenoms Blog</title><link>https://natenom.de/tags/systemd/</link><description>Recent content in Systemd on Natenoms Blog</description><generator>Hugo -- gohugo.io</generator><language>de</language><copyright/><lastBuildDate>Tue, 13 Sep 2016 17:39:41 +0000</lastBuildDate><atom:link href="https://natenom.de/tags/systemd/index.xml" rel="self" type="application/rss+xml"/><item><title>Prevent your laptop from sleep/suspend while something important is running…</title><link>https://natenom.de/2016/09/prevent-your-laptop-from-sleepsuspend-while-something-important-is-running/</link><pubDate>Tue, 13 Sep 2016 17:39:41 +0000</pubDate><guid>https://natenom.de/2016/09/prevent-your-laptop-from-sleepsuspend-while-something-important-is-running/</guid><description><![CDATA[<h2 id="the-problem" data-numberify>The problem<a class="anchor ms-1" href="#the-problem"></a></h2>
<p>My laptop is configured to go to sleep after two minutes of being idle.</p>
<p>But it also suspends while a backup to an external disk is running :(</p>

<h2 id="the-solution" data-numberify>The solution<a class="anchor ms-1" href="#the-solution"></a></h2>
<p>The solution is to tell your system that something important is running and that it should not go to sleep/suspend or to shut down.</p>
<p>With systemd you can use the command „systemd-inhibit“. Read the man page… (man systemd-inhibit).</p>]]></description><content:encoded><![CDATA[<h2 id="the-problem" data-numberify>The problem<a class="anchor ms-1" href="#the-problem"></a></h2>
<p>My laptop is configured to go to sleep after two minutes of being idle.</p>
<p>But it also suspends while a backup to an external disk is running :(</p>

<h2 id="the-solution" data-numberify>The solution<a class="anchor ms-1" href="#the-solution"></a></h2>
<p>The solution is to tell your system that something important is running and that it should not go to sleep/suspend or to shut down.</p>
<p>With systemd you can use the command „systemd-inhibit“. Read the man page… (man systemd-inhibit).</p>
<p>Instead of starting your backup script directly you start it with:</p>
<blockquote>
<pre><code>systemd-inhibit \
--what=&quot;shutdown:sleep:idle:handle-lid-switch&quot; \
--who=&quot;My backup script&quot; \
--why=&quot;Finish the backup.&quot; \
/path/to/my/backup-script.sh
</code></pre>
</blockquote>
<p>Please note that this is a single line but I split it for better reading. Copy and paste all 5 lines.</p>
<p>You may also modify your backup script to run the backup command with systemd-inhibit.</p>

<h2 id="optional-create-an-alias" data-numberify>Optional: Create an alias<a class="anchor ms-1" href="#optional-create-an-alias"></a></h2>
<p>I created the following alias in the global shell rc to be able to use systemd-inhibit for my backup or other important stuff without the need to remember the options:</p>
<blockquote>
<pre><code>alias nosuspend='systemd-inhibit --what=&quot;shutdown:sleep:idle:handle-lid-switch&quot;'
</code></pre>
</blockquote>
<p>Usage:</p>
<blockquote>
<pre><code>user@host $ nosuspend /path/to/your/script.sh
</code></pre>
</blockquote>

<h2 id="list-inhibitions" data-numberify>List inhibitions<a class="anchor ms-1" href="#list-inhibitions"></a></h2>
<p>To get a list of inhibitions on your system use:</p>
<blockquote>
<pre>systemd-inhibit --list</pre>
</blockquote>

<h2 id="almost-perfect8230" data-numberify>Almost perfect&#8230;<a class="anchor ms-1" href="#almost-perfect8230"></a></h2>
<p>…the systemd-inhibit does only work if a command is running as root, while KDE/Plasma is running as a unprivileged user. But thats sufficient for what I want because my backup script does need root privileges. So I don’t need to „fix“ that issue for my case. Maybe later…</p>
<p>So now KDE/Plasma asks for a legitimation to go to sleep/standby and thats it.<br>
<a  href="/wp-content/uploads/2016/09/legimation_asked_to_override_blocking.png"><img loading="lazy" class="alignnone size-full wp-image-35254" src="/wp-content/uploads/2016/09/legimation_asked_to_override_blocking.png" alt="legimation_asked_to_override_blocking" srcset="/wp-content/uploads/2016/09/legimation_asked_to_override_blocking.png 503w, /wp-content/uploads/2016/09/legimation_asked_to_override_blocking-150x137.png 150w, /wp-content/uploads/2016/09/legimation_asked_to_override_blocking-300x275.png 300w" sizes="(max-width: 503px) 100vw, 503px" /></a></p>

<h2 id="read-the-docs-" data-numberify>Read the docs :)<a class="anchor ms-1" href="#read-the-docs-"></a></h2>
<p>See <a  class='urlextern'  href="https://www.freedesktop.org/wiki/Software/systemd/inhibit/">https://www.freedesktop.org/wiki/Software/systemd/inhibit/</a> if you need more information.</p>]]></content:encoded></item><item><title>Raspberry Pi automatisch herunterfahren durch Spielen einer bestimmten Datei in MPD :)</title><link>https://natenom.de/2015/09/raspberry-pi-automatisch-herunterfahren-durch-spielen-einer-bestimmten-datei-in-mpd/</link><pubDate>Sun, 20 Sep 2015 15:00:15 +0000</pubDate><guid>https://natenom.de/2015/09/raspberry-pi-automatisch-herunterfahren-durch-spielen-einer-bestimmten-datei-in-mpd/</guid><description>&lt;p>Habe kürzlich meinen alten Raspberry aufgesetzt hauptsächlich für MPD. Da an dem Gerät keine Tastatur angeschlossen ist, suchte ich nach einer Möglichkeit, den Shutdown über MPD zu veranlassen und fand diese coole Idee, siehe &lt;a class='urlextern' href="http://hannes.enjoys.it/blog/2014/07/shutting-down-the-operating-system-by-playing-a-kill-song-in-mpd/">hier.&lt;/a>&lt;/p></description><content:encoded><![CDATA[<p>Habe kürzlich meinen alten Raspberry aufgesetzt hauptsächlich für MPD. Da an dem Gerät keine Tastatur angeschlossen ist, suchte ich nach einer Möglichkeit, den Shutdown über MPD zu veranlassen und fand diese coole Idee, siehe <a  class='urlextern'  href="http://hannes.enjoys.it/blog/2014/07/shutting-down-the-operating-system-by-playing-a-kill-song-in-mpd/">hier.</a></p>
<p>Mittels inotifywait wird gewartet, bis die einzustellende Datei geöffnet wird. Dann wird das System sauber heruntergefahren.</p>
<p>In Debian ist das Programm im Paket inotify-tools enthalten.</p>
<p>Wenn man auf dem System kein Systemd hat, dann kann man den Einzeiler auch alternativ mit einem &amp;-Zeichen am Ende in die Datei /etc/rc.local eintragen, wie z. B. in Debian Wheezy:</p>
<blockquote>
<p><code>sleep 10 &amp;&amp; /usr/bin/inotifywait -e open /home/data/music/shutdown.mp3 &amp;&amp; shutdown -h now &amp;&lt;br /&gt; </code></p>
</blockquote>
<p>Im verlinkten Artikel wird sleep verwendet, damit sichergestellt ist, dass alle Dateisysteme eingebunden sind. In meinem Fall ist es dafür, dass der Server nicht direkt wieder heruntergefahren wird, weil ja die shutdown.mp3 direkt angespielt wird, sobald MPD startet. Somit muss ich die Playqueue nicht löschen lassen.</p>
<p>Es reicht übrigens nicht aus, eine beliebige Datei umzubennen, man muss auch die ID3-Tags bzw. Metadaten entfernen, da MPD sonst nur diese anzeigt.</p>
<p>Danke dafür :)</p>
<p><a  href="/wp-content/uploads/2015/09/mpd_shutdown.jpg"><img loading="lazy" class="alignnone size-large wp-image-33201" src="/wp-content/uploads/2015/09/mpd_shutdown-576x1024.jpg" alt="mpd_shutdown" srcset="/wp-content/uploads/2015/09/mpd_shutdown-576x1024.jpg 576w, /wp-content/uploads/2015/09/mpd_shutdown-84x150.jpg 84w, /wp-content/uploads/2015/09/mpd_shutdown-169x300.jpg 169w, /wp-content/uploads/2015/09/mpd_shutdown.jpg 720w" sizes="(max-width: 474px) 100vw, 474px" /></a></p>]]></content:encoded></item></channel></rss>