Multiple Instances of Services: Difference between revisions

From Alpine Linux
(Created page with '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...')
 
(use relative symlink)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
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?
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.
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 should work for other versions as well.


== Install The Service ==
== Install The Service ==
First, we'll install TinyDNS and the ACF
First, we'll install TinyDNS and the ACF


    apk add acf-tinydns
{{Cmd|# 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.
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 {{path|/etc/init.d/tinydns}}, {{path|/etc/conf.d/tinydns}}, and {{path|/etc/tinydns/}} or from ACF using the Networking > DNS pages.


== Create a Second Instance of the Service ==
== 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.
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 {{path|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
{{Cmd|# ln -s tinydns /etc/init.d/tinydns.internal}}


Create conf.d and domain files for each new script. You can copy the tinydns files to start.
Create {{path|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
{{Cmd|<nowiki># cp /etc/conf.d/tinydns /etc/conf.d/tinydns.internal
    cp -r /etc/tinydns /etc/tinydns.internal
# cp -r /etc/tinydns /etc/tinydns.internal</nowiki>}}


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?
You now have a second instance of the TinyDNS service that you can manage from the console using {{path|/etc/init.d/tinydns.internal}}, {{path|/etc/conf.d/tinydns.internal}}, and {{path|/etc/tinydns.internal/}}. But, how do you manage it with ACF?


== Create a Second Instance of the 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 an ACF controller for the new script. Controller names can only contain letters, numbers, and '_'.


    mkdir /usr/share/acf/app/tinydns_internal
{{Cmd|# mkdir /usr/share/acf/app/tinydns_internal}}


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.
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
{{Cmd|<nowiki># 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
# for a in tinydns*; do cp $a /usr/share/acf/app/tinydns_internal/$(echo $a {{!}} sed "s/tinydns/tinydns_internal/"); done</nowiki>}}


    vim /usr/share/acf/app/tinydns_internal/tinydns_internal-model.lua
{{Cmd|# vim /usr/share/acf/app/tinydns_internal/tinydns_internal-model.lua}}
        'local processname = "tinydns.internal"'
Change 'local processname = "tinydns.internal"'


    vim /usr/share/acf/app/tinydns_internal/tinydns_internal.roles
{{Cmd|# vim /usr/share/acf/app/tinydns_internal/tinydns_internal.roles}}
        replace each instance of 'tinydns' with 'tinydns_internal'
Replace each instance of 'tinydns' with 'tinydns_internal'


    vim /usr/share/acf/app/tinydns_internal/tinydns_internal.menu
{{Cmd|# vim /usr/share/acf/app/tinydns_internal/tinydns_internal.menu}}
        modifiy the main menu entry, ie. replace each instance of '30DNS' with '31DNS_Internal'
 
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)
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 ==
== Save Your Changes ==
The /usr/share directory is not automatically included in lbu commits, so the new ACF instance must be added manually.
The {{path|/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
{{Cmd|# lbu add /usr/share/acf/app/tinydns_internal}}


Then, commit the changes.
Then, commit the changes.


    lbu commit
{{Cmd|# lbu commit}}
 
[[Category:Booting]]
[[Category:ACF]]

Latest revision as of 10:53, 17 November 2023

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 should work for other versions 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 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 '_'.

# mkdir /usr/share/acf/app/tinydns_internal

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

Change '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.

# lbu commit