Weird issue with v-update-user-counters and update_user_value

I have a weird error I just noticed. Not sure if its since the last update or not. So if I run:

v-update-user-counters athertons

I get:

 v-update-user-counters athertons
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'
sed: -e expression #1, char 3: unknown command: `
'

If I add some debug, I see weird output with newlines:

sed -i "54
55 i\U_CRON_JOBS='0'" /usr/local/hestia/data/users/athertons/user.conf

I’m not too sure why its doing that? Looking at /usr/local/hestia/data/users/athertons/user.conf , it all looks ok (one entry per line) … so I’m not too sure whats causing it?

Oh actually - there is something wrong! They seem to be duplicated:

U_WEB_DOMAINS='1'
U_WEB_DOMAINS='1'
U_DNS_RECORDS='0'
U_DNS_RECORDS='0'
U_DNS_DOMAINS='0'
U_DNS_DOMAINS='0'
U_MAIL_DOMAINS='0'
U_MAIL_DKIM='0'
U_DATABASES='0'
U_DATABASES='0'
U_CRON_JOBS='0'
U_CRON_JOBS='0'
THEME=''
U_BACKUPS='3'
U_BACKUPS='3'

Not sure what would cause that? Manually removing the duplicated lines fixes it, but it seems to be all the user accounts that have the issue - and I have quite a few! Is there a better fix?

I wrote a little Perl script that would find all the user.conf files, and remove any duplicated lines. Its not perfect, but at least cleans them all up without manually doing it:

#!/usr/bin/perl

use strict;
use warnings;

my @list = split /\n/ , `find /usr/local/hestia/data/users/ -type f -name user.conf`;

foreach (@list) {

    # Define the configuration file path
    my $config_file = $_;

    # Create a backup of the original file
    my $backup_file = "$config_file.bak";
    system("cp $config_file $backup_file");

    # Read the original configuration file
    open my $input_fh, '<', $config_file or die "Unable to open $config_file: $!";
    my @lines = <$input_fh>;
    close $input_fh;

    # Remove duplicate lines
    my %seen;
    my @unique_lines;
    foreach my $line (@lines) {
        # Remove leading and trailing whitespaces from each line before checking for duplicates
        my $trimmed_line = trim($line);

        # Skip empty lines
        next if $trimmed_line eq '';

        # Check if the line has been seen before, if not, add it to the list of unique lines
        push @unique_lines, $line unless $seen{$trimmed_line};

        # Mark the line as seen
        $seen{$trimmed_line} = 1;
    }

    # Write the unique lines back to the configuration file
    open my $output_fh, '>', $config_file or die "Unable to open $config_file for writing: $!";
    print $output_fh @unique_lines;
    close $output_fh;

    sub trim {
        my $str = shift;
        $str =~ s/^\s+|\s+$//g;
        return $str;
    }

    print "Duplicate lines removed from $_, and a backup of the original file has been created.\n";
}

I need to try and see what happened though, in terms of the lines being duplicated. I’ve checked other servers with the same version of Hestia, and they seem ok - so its a bit of a weird one!

Would be interested why it happens instead…

Ditto. I’m going to run through my other servers and see if any of them have the same issue. Its weird its only one server so far (and I only happened to notice it as our webmail stopped working)

I have seen it happen it also on our testing server… But also not always…

I’ve just run through all my servers, and none of them seem to have the issue. The others have gone through the update to 1.8.10, so I don’t think it was that. Very odd. I’ll keep an eye out and see if it happens again

FYI, this happened on another server that I look after as well. So I’m assuming it happened during the last update (I’ve never seen it before this)

Do you have the original user.conf file before the duplication and also the file after duplication?

It would be great to have them to try to debug the issue.

Hi,

Yes, my scripts backed them up. Here are some (redacted of private info :)) versions:

The original server:

server1 user1-fixed

server1 user1-broken

And the other server I found this morning:

server2 user1-fixed

server2 user1-broken

The problem entries seem to be:

SUSPENDED_USERS
SUSPENDED_DNS
SUSPENDED_MAIL
IP_AVAIL
IP_OWNED
U_USERS
U_DISK_DIRS
U_DISK_DB
U_BANDWIDTH
U_WEB_ALIASES
U_WEB_SSL
U_MAIL_DOMAINS
U_BACKUPS
U_CRON_JOBS]

I’m not sure if that helps or not though!

1 Like

Thank you @andrewnewby

If you run now v-update-user-counter USER, it duplicates entries again?

Sorry, I was away for the weekend. It seems to run fine now and not duplicate. All of it seemed to come out of the last update for some reason. Not sure if that’s just random, or something that happened which caused it during the update process

I have been testing and have not been able to simulate the problem. The first error you posted is because of duplicated variables but as I said, I have not been able to duplicate the problem and I have no idea why it happened to you. I am still looking at it

1 Like

Yeah. I’m not sure how often it will happen. I wonder if some better error handling would be good in main.sh - update_user_value() { }

	lnr=$(grep -n "^$key='" $HESTIA/data/users/$1/user.conf | cut -f 1 -d ':')

	# if lnr has a newline in, show error and email!
	if [[ "$lnr" =~ $'\n' ]]; then
		echo "Error: update_user_value for $key has a newline in it!"
		echo "Error: update_user_value for $key has a newline in it!" | mail -s "Error: update_user_value for $key has a newline in it!" $CONTACT
	fi

So that it emails us when it happens, so we are at least aware it has happened? (and hopefully pin down the last thing that happened, before it caused an issue)