<?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=6670&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / sysv-init: Looking for example/run a script permanently, like service?]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=6670</link>
		<description><![CDATA[The most recent posts in sysv-init: Looking for example/run a script permanently, like service?.]]></description>
		<lastBuildDate>Mon, 24 Jun 2024 03:28:07 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: sysv-init: Looking for example/run a script permanently, like service?]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=50662#p50662</link>
			<description><![CDATA[<p>I also need an init script so that I can launch the x11vnc server without a user logging in. I broke up the task into two subtasks:</p><p>&#160; - Figure out how to set up the init script, how it launches, what args it receives.<br />&#160; - Write the logic for starting and shutting down the x11vnc server.</p><p>Today, I figured out some of the basics for writing an init script, starting it etc. Next time I have free time, I&#039;ll figure out how to start and stop the vnc server from the init script.</p><p>These steps were tested in Devuan Daedalus, with the MATE desktop environment.</p><h5>* Create the script file</h5><p>The init scripts are located in /etc/init.d. In this example, we&#039;ll create a script that will log all of the script args into a log file.</p><div class="codebox"><pre><code>sudo pluma /etc/init.d/yourinitscript.sh</code></pre></div><p>Put these contents in the file.</p><div class="codebox"><pre><code>#!/bin/sh

#If you modify the INIT INFO section, update the rc.d links with these commands (as root):
#  update-rc.d yourinitscript.sh remove
#  update-rc.d yourinitscript.sh defaults
### BEGIN INIT INFO
# Provides: yourinitscript.sh
# Required-Start:
# Required-Stop:
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
### END INIT INFO

#Write the current date/time, previous and current run levels, and the args passed into this script into the log file.
echo &quot;`date` | runlevel `runlevel` | script args received: $*&quot; &gt;&gt; /var/tmp/yourinitscript.log</code></pre></div><p>Sysvinit uses the INIT INFO section to figure out the dependencies and what order each init script should be launched. These five appear to be the minimum required params that an init script needs to define.<br />&#160; - Provides : I think sysvinit uses this to identify your script when it figures out the dependencies.<br />&#160; - Required-Start: This defines what other init scripts must be run before telling yourinitscript.sh to start its service. In this example, we don&#039;t have any dependencies, so we leave it blank.<br />&#160; - Required-Stop: Other init scripts that must be stopped before telling yourinitscript.sh to stop its service.<br />&#160; - Default-Start: When sysvinit is running at these run levels, yourinitscript.sh will be started if it&#039;s not started.<br />&#160; - Default-Stop: When sysvinit is running at these run levels, yourinitscript.sh will be stopped if it&#039;s started.</p><h5>* Set up the symlinks</h5><p>First, the script must be executable.</p><div class="codebox"><pre><code>sudo chmod +x /etc/init.d/yourinitscript.sh</code></pre></div><p>Next, we tell sysvinit to set up the symlinks that will run yourinitscript.sh whenever the services needs to be started or stopped.</p><div class="codebox"><pre><code>sudo update-rc.d yourinitscript.sh remove
sudo update-rc.d yourinitscript.sh defaults</code></pre></div><p>The symlinks are created in the subdirectores for each run level: /etc/rc0.d, /etc/rc1.d, /etc/rc2.d, etc.</p><p>I haven&#039;t figuured out why, but if you modify the script&#039;s INIT INFO section and then run &quot;update-rc.d defaults&quot;, the command will give warnings. The workaround is to always &quot;remove&quot; any previously setups of yourinitscript.sh, then set up it with &quot;defaults&quot;.</p><h5>* Test the init script</h5><p>To test that the script is working correctly, use the &quot;service&quot; command. You can pass in any args into your init script.</p><div class="codebox"><pre><code>sudo service yourinitscript.sh aaa bbb ccc</code></pre></div><p>Read the log file.</p><div class="codebox"><pre><code>cat /var/tmp/yourinitscript.log</code></pre></div><p>You should see this line in the log file.</p><div class="codebox"><pre><code>Sun Jun 23 07:32:18 PM PDT 2024 | runlevel N 2 | script args received: aaa bbb ccc</code></pre></div><p>Notice that the previous run level is &quot;N&quot;, which means there&#039;s no previous run level. The current run level is &quot;2&quot;, which is defined in /etc/inittab.</p><div class="codebox"><pre><code># The default runlevel.
id:2:initdefault:</code></pre></div><p>Also notice that the script received the 3 dummy args &quot;aaa&quot;, &quot;bbb&quot;, and &quot;ccc&quot;. This means that if necessary, your init script can receive all sorts of args. That is, it&#039;s not restricted to a specific set of keywords.</p><h5>* Reboot the PC</h5><p>Reboot the PC, then check the log file.</p><div class="codebox"><pre><code>cat /var/tmp/yourinitscript.log</code></pre></div><p>There should be two new lines.</p><div class="codebox"><pre><code>Sun Jun 23 19:33:58 PDT 2024 | runlevel 2 6 | script args received: stop
Sun Jun 23 19:34:26 PDT 2024 | runlevel N 2 | script args received: start</code></pre></div><p>Notice that on the first line, the previous run level is &quot;2&quot; and the current runlevel is &quot;6&quot;. &quot;6&quot; is the runlevel that means the PC is rebooting.</p><p>Also notice that the script received the &quot;stop&quot; arg when the PC was shutting down for a reboot, and the &quot;start&quot; arg during the next boot. So your init script should at least handle these two args.</p><h5>* Shutdown, then manually power up again</h5><p>Shut down the PC. Then turn it back on.</p><div class="codebox"><pre><code>cat /var/tmp/yourinitscript.log</code></pre></div><p>There should be two new lines.</p><div class="codebox"><pre><code>Sun Jun 23 19:45:27 PDT 2024 | runlevel 2 0 | script args received: stop
Sun Jun 23 19:46:04 PDT 2024 | runlevel N 2 | script args received: start</code></pre></div><p>Notice that during the shutdown, the current runlevel is &quot;0&quot;. &quot;0&quot; is the runlevel that means the PC is shutting down (halting).</p><h5>* Uninstall</h5><p>To uninstall the init script, first remove the symlinks.</p><div class="codebox"><pre><code>sudo update-rc.d yourinitscript.sh remove</code></pre></div><p>Optionally, delete the script. <strong><span class="bbu">Make sure you have a backup copy of this script so you can install it again if needed!</span></strong></p><div class="codebox"><pre><code>sudo rm /etc/init.d/yourinitscript.sh</code></pre></div><p>Hopefully, these steps are helpful to someone.</p>]]></description>
			<author><![CDATA[dummy@example.com (Eeqmcsq)]]></author>
			<pubDate>Mon, 24 Jun 2024 03:28:07 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=50662#p50662</guid>
		</item>
		<item>
			<title><![CDATA[Re: sysv-init: Looking for example/run a script permanently, like service?]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=50598#p50598</link>
			<description><![CDATA[<p>Thank you very much!<br />--br,<br />Manfred</p>]]></description>
			<author><![CDATA[dummy@example.com (webman)]]></author>
			<pubDate>Wed, 19 Jun 2024 21:52:00 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=50598#p50598</guid>
		</item>
		<item>
			<title><![CDATA[Re: sysv-init: Looking for example/run a script permanently, like service?]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=50557#p50557</link>
			<description><![CDATA[<p>take a look at <a href="https://github.com/eylles/afreq.sh" rel="nofollow">https://github.com/eylles/afreq.sh</a> it is just a shell script (posxi shell, not even bash) along the initscript to run it as a daemon.</p>]]></description>
			<author><![CDATA[dummy@example.com (EDX-0)]]></author>
			<pubDate>Sun, 16 Jun 2024 03:12:40 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=50557#p50557</guid>
		</item>
		<item>
			<title><![CDATA[sysv-init: Looking for example/run a script permanently, like service?]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=50512#p50512</link>
			<description><![CDATA[<p>Hello All!<br />Just a very simple script and where and how to install it would help<br />me getting started!</p><p>Thanks,<br />Manfred</p>]]></description>
			<author><![CDATA[dummy@example.com (webman)]]></author>
			<pubDate>Thu, 13 Jun 2024 19:26:01 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=50512#p50512</guid>
		</item>
	</channel>
</rss>
