<?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=8010&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / [HowTo] Create a Service Script for sysvinit]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=8010</link>
		<description><![CDATA[The most recent posts in [HowTo] Create a Service Script for sysvinit.]]></description>
		<lastBuildDate>Sat, 30 May 2026 04:26:32 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: [HowTo] Create a Service Script for sysvinit]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=64043#p64043</link>
			<description><![CDATA[<p>You could also refer to the &quot;man page&quot; <span class="bbc">init-d-script</span>.</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Sat, 30 May 2026 04:26:32 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=64043#p64043</guid>
		</item>
		<item>
			<title><![CDATA[[HowTo] Create a Service Script for sysvinit]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=64042#p64042</link>
			<description><![CDATA[<p><em>A very common issue with server applications made for systemd is that when are ported to sysvinit they lack the service script file, I will cover the easiest way to create it, this example can be used as a template for any daemon.</em></p><p># Create init file, in this case I will use ntfy as example to show how to create the service file with real binary name, run by specific user, arguments, pid and log paths.</p><div class="codebox"><pre><code>sudo nano /etc/init.d/ntfy</code></pre></div><p><span class="bbc">#!/bin/sh<br />### BEGIN INIT INFO<br /># Provides:&#160; &#160; &#160; &#160; &#160; ntfy<br /># Required-Start:&#160; &#160; $network $syslog<br /># Required-Stop:&#160; &#160; &#160;$network $syslog<br /># Default-Start:&#160; &#160; &#160;2 3 4 5<br /># Default-Stop:&#160; &#160; &#160; 0 1 6<br /># Short-Description: ntfy notification server<br /># Description:&#160; &#160; &#160; &#160;Start/Stop/Restart ntfy notification server<br />### END INIT INFO</span></p><p><span class="bbc">NAME=&quot;ntfy&quot;<br />DESC=&quot;ntfy notification server instance&quot;<br />DAEMON=&quot;/usr/bin/ntfy&quot;<br />DAEMON_ARGS=&quot;serve --config /etc/ntfy/server.yml&quot; <br />PIDFILE=&quot;/var/run/$NAME.pid&quot;<br />LOGFILE=&quot;/var/log/$NAME.log&quot;<br />USER=&quot;ntfy&quot;</span></p><p><span class="bbc">#DEBUG:<br />exec 1&gt;&gt;$LOGFILE 2&gt;&amp;1<br />set -x</span></p><p><span class="bbc"># Ensure daemon binary exists or exits with error code 2 (No such file or directory)<br />[ -x &quot;$DAEMON&quot; ] || exit 2</span></p><p><span class="bbc">do_start() {<br />&#160; &#160; echo &quot;Starting $DESC...&quot;<br />&#160; &#160; # Use start-stop-daemon to run as specified user<br />&#160; &#160; start-stop-daemon --start --quiet --background --make-pidfile \<br />&#160; &#160; &#160; &#160; --pidfile &quot;$PIDFILE&quot; --chuid &quot;$USER&quot; \<br />&#160; &#160; &#160; &#160; --exec &quot;$DAEMON&quot; -- $DAEMON_ARGS<br />}</span></p><p><span class="bbc">do_stop() {<br />&#160; &#160; echo &quot;Stopping $DESC...&quot;<br />&#160; &#160; start-stop-daemon --stop --quiet --pidfile &quot;$PIDFILE&quot; --retry=TERM/30/KILL/5<br />&#160; &#160; rm -f &quot;$PIDFILE&quot;<br />}</span></p><p><span class="bbc">do_status() {<br />&#160; &#160; if [ -f &quot;$PIDFILE&quot; ]; then<br />&#160; &#160; &#160; &#160; PID=$(cat &quot;$PIDFILE&quot;)<br />&#160; &#160; &#160; &#160; if kill -0 &quot;$PID&quot; 2&gt;/dev/null; then<br />&#160; &#160; &#160; &#160; &#160; &#160; echo &quot;$DESC is running (PID $PID).&quot;<br />&#160; &#160; &#160; &#160; else<br />&#160; &#160; &#160; &#160; &#160; &#160; echo &quot;$DESC is dead but pid file exists.&quot;<br />&#160; &#160; &#160; &#160; fi<br />&#160; &#160; else<br />&#160; &#160; &#160; &#160; echo &quot;$DESC is not running.&quot;<br />&#160; &#160; fi<br />}</span></p><p><span class="bbc">do_reload() {<br />&#160; &#160; echo &quot;Reloading $DESC...&quot;<br />&#160; &#160; if [ -f &quot;$PIDFILE&quot; ]; then<br />&#160; &#160; &#160; &#160; kill -HUP $(cat &quot;$PIDFILE&quot;)<br />&#160; &#160; else<br />&#160; &#160; &#160; &#160; echo &quot;No pid file found, cannot reload.&quot;<br />&#160; &#160; fi<br />}</span></p><p><span class="bbc">case &quot;$1&quot; in<br />&#160; &#160; start)<br />&#160; &#160; &#160; &#160; do_start<br />&#160; &#160; &#160; &#160; ;;<br />&#160; &#160; stop)<br />&#160; &#160; &#160; &#160; do_stop<br />&#160; &#160; &#160; &#160; ;;<br />&#160; &#160; restart|force-reload)<br />&#160; &#160; &#160; &#160; do_stop<br />&#160; &#160; &#160; &#160; sleep 1<br />&#160; &#160; &#160; &#160; do_start<br />&#160; &#160; &#160; &#160; ;;<br />&#160; &#160; status)<br />&#160; &#160; &#160; &#160; do_status<br />&#160; &#160; &#160; &#160; ;;<br />&#160; &#160; reload)<br />&#160; &#160; &#160; &#160; do_reload<br />&#160; &#160; &#160; &#160; ;;<br />&#160; &#160; *)<br />&#160; &#160; &#160; &#160; echo &quot;Usage: $0 {start|stop|restart|force-reload|status|reload}&quot; &gt;&amp;2<br />&#160; &#160; &#160; &#160; exit 1<br />&#160; &#160; &#160; &#160; ;;<br />esac</span></p><p><span class="bbc">exit 0</span></p><p># Some daemons automatically create a logfile following the same path and name that we specify with the LOGFILE variable, <br /># if so then this setting can be redundant, but in this case we need to specify that value to be able to debug and know where to look for.</p><p># Make it executable</p><div class="codebox"><pre><code>sudo chmox +x /etc/init.d/ntfy</code></pre></div><p># Activate the service auto start</p><div class="codebox"><pre><code>sudo update-rc.d ntfy defaults</code></pre></div><p># Test the service file</p><div class="codebox"><pre><code>sudo service ntfy</code></pre></div><p># Remember you wont see anything on the screen because the #DEBUG: lines all outputs are send to the log file, instead use cat:</p><div class="codebox"><pre><code>cat /var/log/ntfy.log</code></pre></div><p># Since is the first ever output then you will see the content as:</p><div class="codebox"><pre><code>Usage: /etc/init.d/ntfy {start|stop|restart|force-reload|status|reload}</code></pre></div><p># That means the service is ready to work, now test the status: </p><div class="codebox"><pre><code>sudo service ntfy status</code></pre></div><p># Again, you wont see anything on the screen because the output went to the log file, so again use cat:</p><div class="codebox"><pre><code>cat /var/log/ntfy.log</code></pre></div><p># You should see the last/second line as:</p><div class="codebox"><pre><code>ntfy push notification server is not running.</code></pre></div><p># Now it&#039;s time to start it:</p><div class="codebox"><pre><code>sudo service ntfy start</code></pre></div><p># To verify it&#039;s status again then enter:</p><div class="codebox"><pre><code>sudo service ntfy status</code></pre></div><p># Use cat to see the actual output:</p><div class="codebox"><pre><code>cat /var/log/ntfy.log</code></pre></div><p># Now you should get the output as:</p><div class="codebox"><pre><code>ntfy push notification server is running (PID 1758).</code></pre></div><p># In that case the ntfy service it&#039;s running perfectly fine so you can edit the service file to comment the 2 lines after #DEBUG: to get the service script outputs on the terminal.</p><p># Please remember this is just an example how to easily create a service script, and in the case of ntfy, the success or fail to start depends on <br /># the settings from:&#160; &quot;/etc/ntfy/server.yml&quot;<br /># What I&#039;m trying to emphasise is that if the script works with the &quot;status&quot; argument then the &quot;start&quot; argument also works. <br /># But the success or fail for the start argument will depend only on any required/missing setting that must be passed to the deamon when starts.<br /># So this is not a copy &amp; paste solution but a very solid start point to create and test any missing service script until you make it work.</p>]]></description>
			<author><![CDATA[dummy@example.com (joser)]]></author>
			<pubDate>Sat, 30 May 2026 03:14:01 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=64042#p64042</guid>
		</item>
	</channel>
</rss>
