MX-23 - SysVinit manual init script creation HOWTO (program/script autostart)

Here is where you can post tips and tricks to share with other users of MX. Do not ask for help in this Forum.
Message
Author
User avatar
AbzUA
Posts: 3
Joined: Fri Jan 24, 2025 12:21 pm

MX-23 - SysVinit manual init script creation HOWTO (program/script autostart)

#1 Post by AbzUA »

When I was faced with situation, when adding my program/script to /etc/rc.local doesn't make it running after reboot - I've dug deeper and found the solution.

Hope my approach will be useful.

Preamble:
I need "dnscrypt-proxy" application to be automatically started after reboot.
Solution with adding it to /etc/rc.local (adding command above "Exit 0") does not work.

Well, when I run it in terminal in XFCE GUI session it works as expected:

Code: Select all

sudo /usr/sbin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml &
I can see it's really running (process exist) using command:

Code: Select all

ps -A | grep dnscrypt  
Output:

Code: Select all

$ ps -A | grep dnscrypt
   1790 ?        00:00:33 dnscrypt-proxy
How to make it be running automatically after reboot?

First we should determine - are we really in SysVinit mode by command:

Code: Select all

stat /sbin/init
Output like:

Code: Select all

$ stat /sbin/init
  File: /sbin/init
  Size: 52240     	Blocks: 104        IO Block: 4096   regular file
Device: 804h/2052d	Inode: 1965873     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2025-01-23 15:10:33.723200116 +0200
Modify: 2021-12-16 20:12:09.000000000 +0200
Change: 2022-04-12 13:51:29.849484615 +0300
 Birth: 2022-04-12 13:51:29.825482807 +0300 
When we have in "File: /sbin/init" - this is SysVinit
When we have in "File: /usr/bin/openrc-init" - this is OpenRC

Otherwise you will see systemd - this HOWTO is NOT for you.

With help of this dude https://gist.github.com/drmalex07/298ab26c06ecf401f66c my custom init script was created...

But in my case I didn't make start-stop scripts, just run application and "kill" all it's instances in "stop" section

Please take into account that section in green is mandatory and you should adjust values in orange
to your application/needs (check other scripts in /etc/init.d regarding "Required-Start:" section

My init file "dns-load" for DNScrypt-proxy attached as image and below as code:

Code: Select all

#!/bin/bash

### BEGIN INIT INFO
# Provides:          dnscrypt-proxy
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: dnscrypt-Load Manager
# Description:       start DNSCrypt-loader manager
### END INIT INFO

start() {
     /usr/sbin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml &
}

stop() {
     killall dnscrypt-proxy 2>/dev/null
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    *)
       echo "Usage: $0 {start|stop|restart}"
esac

exit 0
Next steps:
1. Create file with text above as "dns-load" (or how you named it) elsewhere and copy to /etc/init.d
2. Go to to /etc/init.d and change user/group permissions to file, e.g.

Code: Select all

cd /etc/init.d
sudo chown root:root dns-load
sudo chmod 755 dns-load 
3. Update the runlevel directories under /etc/rc*:

Code: Select all

update-rc.d dns-load defaults 
4. Reboot, after reboot check that program is autostarted:

Code: Select all

ps -A | grep dnscrypt
Exactly with "dnscrypt-proxy" you can check that it works:

Code: Select all

nslookup valcarce.fr
Output should be like:

Code: Select all

Server:		127.0.0.1
Address:	127.0.0.1#53

Non-authoritative answer:
Name:	valcarce.fr
Address: 51.15.121.4
Name:	valcarce.fr
Address: 2001:bc8:1824:e4e::1
With this approach I have added other applications (replace execution path and name in places marked with red color on screenshot)

To manually start or stop use command, e.g.:

Code: Select all

sudo service dns-load start

Code: Select all

sudo service dns-load stop

Code: Select all

sudo service dns-load restart
Image

User avatar
CharlesV
Administrator
Posts: 8146
Joined: Sun Jul 07, 2019 5:11 pm

Re: MX-23 - SysVinit manual init script creation HOWTO (program/script autostart)

#2 Post by CharlesV »

@AbzUA Welcome in!

Please post your QSI. ( MX Menu, Quick System Info, Copy for Forum, Paste here ) - not only required for help, but that will help others know what setup you are on for this.
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

User avatar
AbzUA
Posts: 3
Joined: Fri Jan 24, 2025 12:21 pm

Re: MX-23 - SysVinit manual init script creation HOWTO (program/script autostart)

#3 Post by AbzUA »

BTW, I realized that posted in wrong thread, admins move it to Software Configuration please

Code: Select all

System:    Kernel: 5.10.0-33-amd64 [5.10.226-1] x86_64 bits: 64 compiler: gcc v: 10.2.1 
           parameters: BOOT_IMAGE=/boot/vmlinuz-5.10.0-33-amd64 root=UUID=<filter> ro quiet splash 
           acpi=force irqpoll 
           Desktop: Xfce 4.18.1 tk: Gtk 3.24.24 info: xfce4-panel wm: xfwm 4.18.0 vt: 7 
           dm: LightDM 1.26.0 Distro: MX-21.3_x64 Wildflower April 9  2022 
           base: Debian GNU/Linux 11 (bullseye) 

User avatar
CharlesV
Administrator
Posts: 8146
Joined: Sun Jul 07, 2019 5:11 pm

Re: MX-23 - SysVinit manual init script creation HOWTO (program/script autostart)

#4 Post by CharlesV »

@AbzUA Topic moved to Tips and Tricks .. I think this is the appropriate location - and thank you !
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

Post Reply

Return to “Tips & Tricks by users (not for help)”