Failoverscripts in Linux

Status
Not open for further replies.

jl@rag

Joined
Dec 4, 2017
Messages
12
Reaction score
1
Hi,
I just wanted to ask if anyone is using failover scripts under Linux?
We want to use them, but I do not have any chance to get them working. When a failover script is uploaded and active, the failover will not work.

The passive server checks the active server continously. When I stop services that are being monitored, the passive server recognizes that, but does nothing.

When I do not use a failover script, the failover will work just like it is supposed to work.

Can someone give me an example of a linux script that works in a failover situation?

Thank you!
 
Hi,
1. make sure that PBX slave and make session to the PBX master without password. In order to do this you have to create SSH key.

Important The PBX Phone system is not running as Root but as PhoneSystem user, therefore when command is triggered from the management console is not as root but as phonesystem user.

ssh-keygen
cat /var/lib/3cxpbx/.ssh/id_rsa.pub | ssh root@MASTER IP PBX"mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2


2. make a simple script PBX slave to connect to the server and stop the services.

scripts:
script 1 (remotestop.sh):
#!/bin/bash
ssh root@MASTER IP PBX "bash -s" < /var/lib/3cxpbx/Instance1/Scripts/stopall.sh

script 2 (stopall.sh):
#!/bin/bash
systemctl stop 3CXQueueManager01 3CXQueueManager01 3CXMediaServer 3CXSystemService01 3CXHotelModule01 3CXEventNotificationManager 3CXPhoneSystem01 3CXAudioProvider01 3CXIVR01 3CXTunnel01

Finish
 
  • Like
Reactions: OlegR_3CX
Hi,

thank you for your answer.

I know that the user is not root that is running the script:

-rwxr-xr-x 1 phonesystem phonesystem 111 Jul 4 08:07 /var/lib/3cxpbx/Instance1/Scripts/before_script

This is my script:

Code:
#!/bin/bash
sudo ssh -t ACTIVE_SERVER /usr/sbin/3CXStopServices
sudo ssh -t ACTIVE_SERVER ip l s eth1 down
sudo ip l s eno2 up

The user phonesystem is in my soders list and can use the command 'ssh' and 'ip'.
I can sudo-login as phonesystem user and can run the commands and the script.
There are ssh-keys exchanged between the two servers.

Is this setup mentioned by you working in your installation?
 
Yes my setup is working in my installation
 
I did install your scripts, and it is not working. No Failover and no script is being executed.
 
Hi kenzoo

Seems like you have that running. I will give you a update, how far i am:

I have my simple Script to change the ip. Meanwhile I am so far that this script can be executed from the user "phonesystem". I have tested this via putty, logged in as root with the following command:
runuser -l phonesystem -c "/var/lib/3cxpbx/Instance1/Scripts/NAME-OF-SCRIPT.sh"

So far so good. But now I have the same issue as jl@rag. If the script should be executed before Services should start they never start. If the script schould be executed AFTER the services, then the services start but the Script never will be excecuted.

As my Script don't have to ssh to the Main-PC, I can ignore the ssh-keygen, right?
 
Hi Marcel,
I am not expert Linux but That exactly what I got before means from putty all the scripts worked well but not from 3cx console. Once using ssh-keys exchanged both my scripts:
Before: to change the dns and the After :script to stop services in the master server both works as expected..
 
Run

Code:
sed -i -e 's/\r$//' NAME_OF_SCRIPT

over your script, and test again.
 
  • Like
Reactions: OlegR_3CX
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
111,889
Messages
589,571
Members
164,753
Latest member
GemmaC