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 &
Code: Select all
ps -A | grep dnscrypt
Code: Select all
$ ps -A | grep dnscrypt
1790 ? 00:00:33 dnscrypt-proxy
First we should determine - are we really in SysVinit mode by command:
Code: Select all
stat /sbin/init
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: /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
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
Code: Select all
update-rc.d dns-load defaults
Code: Select all
ps -A | grep dnscrypt
Code: Select all
nslookup valcarce.fr
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
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
