<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=7990&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / some runit scripts]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=7990</link>
		<description><![CDATA[The most recent posts in some runit scripts.]]></description>
		<lastBuildDate>Wed, 20 May 2026 15:59:14 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[some runit scripts]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=63922#p63922</link>
			<description><![CDATA[<p>Hi.<br />I went on IRC #devuan today, as I had issues with the cursed udevd daemon starting outside of runit&#039;s supervision, which was new and I suspected it caused me some issues. There, along the discussion, I got asked to shared my old scripts with a person named Lorenzo, so here I am.</p><p>I do not which ones of my runit scripts could be of use, since let&#039;s be honest, most of them are a dead simple. The process is dead simple: read the daemon&#039;s manual, search for the word: &quot;PID&quot;, &quot;fork&quot;, &quot;background&quot;, &quot;syslog&quot;... this kind of stuff. Note the option that allows to disable those &quot;features&quot;. Usually, it means running in what the author call &quot;debug mode&quot;, and write your one-liner...</p><p>There are few exceptions, though, the most notable one being the cursed udevd. This is technically NOT my script, at least the ugly trick is something I&#039;ve found like 10 years ago on some random blog post. I do not want to claim I did it, but this really helped me back then and I am unable to find anew the original author. I have integrated it along my system, as well, so I modified it a tiny bit.</p><p>DISCLAIMER: my computers are a mess, and I have several variants of some of those scripts, for random and idiotic reasons. Some are cleaner than others... I&#039;ve been carrying those things since a decade, after all.</p><p>Here is the /etc/sv/udev cursed script, adapted to devuan (because debian ofc can&#039;t refrain shuffling files randomly every major version they do, and devuan fixed that toward the sane way... /complains):</p><div class="codebox"><pre class="vscroll"><code>#!/bin/sh

. /etc/runit/common

need()
{
	i=0
	while ! test -e &quot;$1&quot;
	do
		sleep &quot;0.$i&quot;
		test &quot;$i&quot; = 9 || i=$((i+1))
	done
}

mkdir -p /run/udev
rm -f /run/udev/control #just in case
rm -f /run/udevd_ready #just in case
(
	need /run/udev/control # not sure we really need to wait for it
	echo &quot;Trigger+settle:&quot;
	udevadm --debug trigger --type=subsystems --action=add
	udevadm --debug trigger --type=devices --action=add
	udevadm --debug settle
	&gt;/run/udevd_ready
	echo &quot;Done: trigger+settle&quot;
) &amp;

echo &quot;Starting $SVNAME&quot;
exec env - PATH=&quot;$PATH&quot; /usr/sbin/udevd -N late</code></pre></div><p>It starts, like all my runit scripts, by sourcing a single, trivial script I name /etc/runit/common:</p><div class="codebox"><pre class="vscroll"><code>#!/bin/sh

#this file provides some automatic features for runit daemons
#notably it:
#* provides the variable SVNAME, which is the name of the daemon dir
#* provides the die() function
#* sources an existing ./conf file
#* automatically rotates logs on startup if there are logs and AUTO_ROTATE=yes
#* redirects stderr to stdout
#* enables some shell verbosity and safeties (-xe)

die()
{
  printf &quot;%s\n&quot; &quot;$@&quot; | tee ./down
  exit 1
}

SVNAME=&quot;$(basename $(pwd))&quot;
HAS_LOG=&quot;$(test -d &quot;$(pwd)/log&quot; &amp;&amp; printf &quot;yes&quot;)&quot;
exec 0&lt;&amp;-
exec 2&gt;&amp;1
set -xe
test -f conf &amp;&amp; . ./conf

if test &quot;$0&quot; = &quot;run&quot;
then
  if test &quot;$SVNAME&quot; = &quot;log&quot;
  then
    SVLOG=&quot;$(basename $(dirname $(pwd)))&quot;
    SVNAME=&quot;${SVLOG}/${SVNAME}&quot;
    AUTO_ROTATE=&quot;${AUTO_ROTATE:=&quot;no&quot;}&quot;
  fi  
  test &quot;yes&quot; = &quot;${AUTO_ROTATE}&quot; -a &quot;yes&quot; = &quot;$HAS_LOG&quot; &amp;&amp; \
    sv alarm &quot;$(pwd)/log&quot;
fi</code></pre></div><p>I also have a generic logger, so when I create a new service, I only create the log dir, and symlink it as &quot;run&quot;, so it&#039;s named /etc/runit/log.run:</p><div class="codebox"><pre><code>#!/bin/sh

SVLOG=&quot;$(basename $(dirname $(pwd)))&quot;
LOG_PATH=&quot;/var/log/$SVLOG&quot;
test -e &quot;$LOG_PATH&quot; || install -d -m 0750 -o root -g adm &quot;$LOG_PATH&quot;
exec svlogd -tt &quot;$LOG_PATH&quot;</code></pre></div><p>I also have /etc/runit/global.finish which does not do much:</p><div class="codebox"><pre><code>#!/bin/sh

. /etc/runit/common

echo &quot;Stopped $SVNAME&quot;</code></pre></div><p>Maybe my networking stuff may be of interest, as I do not use ifupdown, networkd or whatever...</p><div class="codebox"><pre><code>#!/bin/sh

. /etc/runit/common

ip l set $IFACE up
if test -e /sbin/ethtool
then
	while $(/sbin/ethtool $IFACE | grep -q &#039;Link detected: no&#039;)
	do
		test &quot;$VERBOSE&quot; = &quot;yes&quot; &amp;&amp; echo &quot;$IFACE unplugged, sleep ${SLEEP:=60}&quot;
		sleep ${SLEEP:=60}
	done
fi

echo &quot;Starting $SVNAME on $IFACE&quot;
exec udhcpc -i $IFACE -f -R -n</code></pre></div><p>This stuff is not worth much, but apparently nothing does that kind of things in devuan? Or I could not find it, which seems more likely. I&#039;ve been using those (or slight modifications, I do that for my own user, too, and similarly adjust the stuff on my toy server, and used to have a 250+ fleet of street equipments at work) since more than 10 years, as said, and this requires zero maintenance. I&#039;m a lazy person, and thus runit have kept me happy for long. I&#039;m expecting this happiness to last, because it&#039;s a sane program, which can handle whatever I want with just few lines of shell.</p><p>The logic behind the finish and even the starting is that it makes it dead simple, when reading your logs, to know when the daemon actually started and ended. Which I have found to be extremely useful, but YMMV. I would never remove those from system, clearly, but it&#039;s not really orthodox, I suppose.</p><p>That&#039;s it. I have a lot more runit stuff, on my systems, the only stuff which are not migrated are the services which do not spawn a daemon, mostly out of lazyness.</p>]]></description>
			<author><![CDATA[dummy@example.com (freem)]]></author>
			<pubDate>Wed, 20 May 2026 15:59:14 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=63922#p63922</guid>
		</item>
	</channel>
</rss>
