Help with broken install

My MAIB server may be irretrievably broken. None of the python scripts will run… at all. Web System Status Checks consistently return the message “Error: Something went wrong. Sorry.” PHP is also somehow corrupted. I got to the point where I simply tried the full install script: curl -s https://mailinabox.email/setup.sh | sudo -E bash but the install broke at the point of installing RoundCube with the following:

PHP Warning:  PHP Startup: Unable to load dynamic library 'apcu.so' (tried: /usr/lib/php/20170718/apcu.so (/usr/lib/php/20170718/apcu.so: undefined symbol: zend_string_init_interned), /usr/lib/php/20170718/apcu.so.so (/usr/lib/php/20170718/apcu.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'apc.so' (tried: /usr/lib/php/20170718/apc.so (/usr/lib/php/20170718/apc.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/apc.so.so (/usr/lib/php/20170718/apc.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/lib/php/20170718/imagick.so (/usr/lib/php/20170718/imagick.so: undefined symbol: zend_string_init_interned), /usr/lib/php/20170718/imagick.so.so (/usr/lib/php/20170718/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
ERROR: could not find driver
ERROR: Failed to connect to database

So I have decided that the only solution at this point is to set up a new box get everything working there then move it back to the old box. I use DigitalOcean cloud servers and I need to keep the current server/IP because I paid to have it whitelisted (an issue with DO’s IP addresses and dsbl blocking). I’m thinking that once I have the new box properly configured and all the data transferred over, I can do a simple snapshot to restore the existing server. Does any of that make sense?

My only problem is if I can’t manually run any of the python scripts, how do I get the existing data off the existing box to be able to transfer it all to the new box? What I’m most concerned with is whatever the database holds. I know I can do an rsync of the user-data directory. Will that be sufficient – especially if I run the python scripts on the new box to update?

Could someone please help walk me through the easiest way to do what I need? Thanks!!

Are you able to access the emails through an IMAP client?

Yes, IMAP, POP and SMTP clients work fine. But I have clients who need access to Roundcube to set up forwarders. In any case, that’s just the straw that broke the proverbial camel’s back. As I stated, NONE of the python scripts will run manually. I use MAIB for DNS and I’m just grateful that those functions still work and custom DNS is accessible via the web interface and I can make changes there. And I’m concerned about why I’m getting PHP errors…

Have you made any changes to the server?

My concern with simply doing rsync of /home/user-data/ is that if you don’t know where the cause of the problem is, then you don’t know if that will just result in a broken server same as it is now.

A decidedly not-fun restore would be to use install MiaB to a second server, use imapsync to transfer all of the emails. Save an image of the current server, then install a fresh Ubuntu 18.04 and fresh install of MiaB. Then re-create the user accounts and imapsync the mail to the new install and if that works then re-create the rest of the MiaB configuration settings.

Geez, that is a real PITA but you would know you have a clean install.

Maybe someone can chime in with a better idea.

My biggest problem at the moment is with python. If I could figure out why the python scripts won’t run, I could just follow the instructions to transfer to a new box and once that is set up, do a snapshot and restore to the existing box. (Thus keeping my whitelisted IP.) However, I’ve not been able to get anyone to successfully help me figure out why python won’t work.

I just did a quick check on the new box and I have the same problem with python THERE!!! If I run sudo python status_checks.py on the new box I STILL get the following error message:

    mail_aliases = dict([(address, receivers) for address, receivers, *_ in get_mail_aliases(env)])
                                                                      ^
SyntaxError: invalid syntax

This is getting BEYOND frustrating!!! I am seriously ready to find another solution!

Please list all steps performed on the install.

Python SyntaxError errors are always a sign you’re using the wrong installed version of Python. Some systems come with Python 2 and Python 3, and you have to use Python 3.

However, using python on the command line is the wrong way to start the Mail-in-a-Box scripts. The correct way is:

cd /root/mailinabox
management/status_checks.py

Okay. I started over from scratch with a new DO server and a whole new domain name (as if setting up for the first time instead of moving an existing install to a new box). At the moment, everything on the web interface is working. If I SSH into the new server and try to run status_checks.py maually, I get the following message:

SyntaxError: Non-ASCII character '\xe2' in file status_checks.py on line 420, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

My new mailserver is emmons.uniquelyyoursmail.us. My current (still live) mailserver is emmons.uniquelyyoursmail.com. The only difference is the TLD. Since I can’t get the python scripts to run manually, am I to understand there is no easy way to transfer existing domains/email accounts? I will have to set up each domain manually?

If status checks are working in the MiaB dashboard, then the CLI issue is related to the command syntax, because if Python were not working, then the dashboard would not work.

What is the exact command you are running to get that output?

sudo python status_checks.py

Running from the mailinabox/management directory.

Try these steps (I don’t know where your mailinabox directory is):

$ cd .../mailinabox
$ sudo management/status_checks.py

Note that if /mailinabox/ is in /root/ then you will need to be in a root session to perform the steps.

Forgive me if this is a dumb question. Is your new install definitely on Ubuntu 18.04 LTS? DO offers to set up 20.04 by default now I think.

The reported output from the commands is the expected output for 18.04.

When I do:

sudo python management/status_checks.py 
  File "management/status_checks.py", line 420
SyntaxError: Non-ASCII character '\xe2' in file management/status_checks.py on line 420, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

when I do

sudo management/status_checks.py 

System
======
✓  All system services are running.
✓  SSH disallows password-based login.

Which means, the python command is not required

In the first lines of status_check.py is a reference to the required python library

#!/usr/local/lib/mailinabox/env/bin/python
#

So I assume the problem will not be with your python.

In that case, the only problem left is with php

running the php version, will provide an output, something like:

php -v
PHP 7.2.24-0ubuntu0.18.04.9 (cli) (built: Aug 16 2021 05:46:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.9, Copyright (c) 1999-2018, by Zend Technologies

So it seems the real problem is probably in your php

when you run

php -i

you probably get a php output of the settings, which also includes image magic

with

dpkg --list | grep php

you 'll get a complete list of php packages. Can you put this list as a reply?

By the way, in /etc/apt/sources.list there is a reference from which the packages are installed. Are these repositories “up to date”?

As update on my previous post, maybe this helps

Herein lies your problem. Run the command EXACTLY as follows:

again from the mailinabox/management directory …

./status_checks.py

DO NOT prefix it with python.

Hmm, I just read further … you already figured this out.

So what is the status now???

Even if you don’t prefix the script with python, the OS will still use the python command (symlink) since the shebang in the file (at least the file system_check.py as sander-schippers described it) tells the OS to use python.

  1. Try typing python --version
  2. If step 1 says that the version is 2 (point something), try sudo apt-get install python-is-python3 package (which should be installed by default on Ubuntu; and which sets the python symlink to point to your system’s python3) then try python --version again and ensure it says 3 (point something).

Since this is rarely an issue on Ubuntu, some other program may have messed with the python symlink. Ensure that that there are no errors with the install command above, and if there are any (such as warnings about files modified etc), post them.

I have spent the last several days trying to get everything to work. I have had a lot of off-forum help from @alento and @openletter, which I really appreciate. I think I know now how I am going to repair my mail server. Tonight I am going to follow the instructions for resetting UFW and then doing a current backup. Then I am going to rebuild the server, install MIAB, and then do a restore from the backup.

I will say that one of the issues I was having trying to do a restore to a different box was that my secret key apparently got corrupted and wouldn’t be recognized. @alento showed me how to regenerate a new secret key using openssl rand -base64 2048 > /home/ubuntu/new_secret_key.txt, I was able to rename the file and replace the corrupted key file. Backup then worked. I am posting this here in case this happens to anyone else.