Multiple Instances of Services
Alpine makes it very easy to install and run a service, but what if you need to have multiple instances of the same service running on the same machine. For instance, what if you want to run split-DNS, where you respond to DNS requests differently for internal and external networks. The simple response is to run two instances of tinyDNS listening on two different Ethernet interfaces. Now, how do you do it? How do you manage the two instances once you have them running?
The following example is specifically for TinyDNS, but can be applied to other services as well. TinyDNS will work because the init.d script has been written in such a way as to allow multiple instances. The procedure is written for alpine 1.9, but similar steps will work for alpine 1.8 as well.
Install The Service
First, we'll install TinyDNS and the ACF
apk add acf-tinydns
This will install the TinyDNS service, as well as the ACF web interface used to manage the service. Having only one instance of TinyDNS, you can manage it from the console using /etc/init.d/tinydns, /etc/conf.d/tinydns, and /etc/tinydns/ or from ACF using the Networking > DNS pages.
Create a Second Instance of the Service
Now, we create a symlink to the TinyDNS init.d script for each new instance you want to run. (For alpine 1.8, you should not use the plain tinydns init.d script so that ACF can properly determine which instance is running, but create two new instances instead) We're going to create a second instance that will handle the internal network.
ln -s /etc/init.d/tinydns /etc/init.d/tinydns.internal
Create conf.d and domain files for each new script. You can copy the tinydns files to start.
cp /etc/conf.d/tinydns /etc/conf.d/tinydns.internal cp -r /etc/tinydns /etc/tinydns.internal
You now have a second instance of the TinyDNS service that you can manage from the console using /etc/init.d/tinydns.internal, /etc/conf.d/tinydns.internal, and /etc/tinydns.internal/. But, how do you manage it with ACF?
Create a Second Instance of the ACF
Set up an ACF controller for the new script. Controller names can only contain letters, numbers, and '_'.
Set up the modified ACF code for each new script. Only three files must be modified, the others may be copied or symlink'd. The name of the controller must be changed to allow the ACF permissions of the two TinyDNS instances to be managed separately.
cd /usr/share/acf/app/tinydns for a in tinydns*; do cp $a /usr/share/acf/app/tinydns_internal/$(echo $a | sed "s/tinydns/tinydns_internal/"); done
vim /usr/share/acf/app/tinydns_internal/tinydns_internal-model.lua 'local processname = "tinydns.internal"'
vim /usr/share/acf/app/tinydns_internal/tinydns_internal.roles replace each instance of 'tinydns' with 'tinydns_internal'
vim /usr/share/acf/app/tinydns_internal/tinydns_internal.menu modifiy the main menu entry, ie. replace each instance of '30DNS' with '31DNS_Internal'
Once you log out and log back into ACF, you should see the new ACF pages and menu options available. User and role management can be handled separately for the new instance. (In alpine 1.8, users should not be given access to the plain TinyDNS ACF)
Save Your Changes
The /usr/share directory is not automatically included in lbu commits, so the new ACF instance must be added manually.
lbu add /usr/share/acf/app/tinydns_internal
Then, commit the changes.