Calling external script on migration

We’re new to Axigen and trying to setup a custom migration script but whenever we enter anything into the “Other local application” box and hit save it doesn’t retain it. Also there’s no documentation i could find that references what it expects here? I thought it would just be a path to the binary, but not sure. Is there a pre-requisite for this field to retain the information given it?


Yes, you should give the full path of the executable to be called.

Checking your report I think this is a WebAdmin bug so please confirm if, in fact, the migrationCommand from doman-migrationdata context is actually set as you make the change from WebAdmin.

For this, assuming you have set an external application to be called when migrating users for domain.tld, let’s connect to CLI and execute the following commands:

config domain name domain.tld
config migrationdata

You should see the changes you’ve made in WebAdmin, like:

migrationCommand = "/opt/axigen/bin/scripts/sh {ACCOUNT_EMAIL} {ACCOUNT_PASSWORD}"

Please confirm if you managed to see the saved configuration from WebAdmin or in your case is not working.


Sorry for the delay, yep these commands worked thank you! But i can’t seem to find any evidence that the script runs when the usual migration task would run, i wrote a simple PHP script that writes to a log file, it runs fine when i call it locally but not when i login via webmail which presumably triggers migration as per usual but WITH the external script. I’ve set permissions to be executable/promiscuous but no changes detected to log file. Any idea where the migration management logs are that would reference the custom script call? so i can see if its having trouble executing the script or some other issue? Does the script get called with a particular owner in linux? does it have to be stored in a particular directory?


Not sure if you already mentioned but please pay attention that:
1/ the migration IMAP host should be configured (in my example from below I’ve used, port 143)
2/ the login credentials provided via WebMail should be validated by the IMAP host
3/ only after checking the credentials the migration script is called

2024-05-13 14:23:06.826163 +0300 16 test-xa2 MIGRATION:0000003F: >> axigen LOGIN a@m.tld *******
2024-05-13 14:23:06.826499 +0300 16 test-xa2 MIGRATION:0000003F: << axigen OK Done
2024-05-13 14:23:07.834619 +0300 08 test-xa2 MIGRATION:0000003F: closing session with [] (migration has finished successfully)

The execution log lines related to the external application looks like:

2024-05-13 14:23:07.885465 +0300 08 test-standalone MIGRATION:0000003F: Started migration command '/opt/axigen/scripts/' (pid=15214) for 'a@m.tld'
2024-05-13 14:23:08.090207 +0300 04 test-standalone MIGRATION:0000003F: Migration command '/opt/axigen/scripts/' (pid=15214) for 'a@m.tld' returned exit code 1

Note: above command (set into migrationCommand) returns code 1 because the referred script does not exist (by intention, just to see what is happening in this case).

You should assure that the referred command is placed into a location accessible by axigen user (please remember about full path rights and not only for the main file only).
Obviously, it should have execution rights for axigen user as well.

My advice is to create a sub-folder under /opt/axigen (the so called install folder) or under the Axigen working foder (usually /var/opt/axigen) and replay your test procedure.


Yeah this is how i had it set up:

root@amail:/var/opt/axigen/scripts# ls -la
total 12
drwxrwxrwx 2 axigen axigen 38 Apr 29 11:30 .
drwxr-xr-x 14 axigen axigen 4096 Apr 29 11:26 …
-rw-r–r-- 1 axigen axigen 136 Apr 29 11:30 test.log
-rwxr-xr-x 1 axigen axigen 152 Apr 29 11:30 test.php

general parameters for the migrationdata context:
createPremiumAccounts = no
defaultAccountClassName = “Standard”
enable = yes
enableContinuousMigration = yes
enableDebugLogging = yes
enableMigrationCommand = yes
migrationCommand = “/usr/bin/php /var/opt/axigen/scripts/test.php {ACCOUNT_EMAIL} {WORKING_DIRECTORY}”
remoteImapHost = “"
remoteImapPort = 143
remoteSmtpHost = "

remoteSmtpPort = 25

I’m not sure where this log is. I manually set the credentials of the test account on the remote server on each of these tests.

Switching to axigen user to test calling the script;

root@amail:/usr/local# su -s /bin/bash axigen
axigen@amail:/usr/local$ php -v
PHP 8.3.6 (cli) (built: Apr 24 2024 19:23:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
axigen@amail:/usr/local$ cd /var/opt/axigen/scripts/
axigen@amail:~/scripts$ ls -l
total 8
-rw-r–r-- 1 axigen axigen 136 Apr 29 11:30 test.log
-rwxr-xr-x 1 axigen axigen 152 Apr 29 11:30 test.php
axigen@amail:~/scripts$ php ./test.php

Now i can see the log has been updated.

So it works manually. Will try another test with a user.

ok same result, it logs in fine using the migration creds because no such user exists locally, then it fetches mail from the remote server fine, i check my custom script log and no execution has taken place. Where is the log you’ve referenced above, perhaps if i could see that i could solve all of this :slight_smile:

Thanks for your time Indreias!

Ah ha I found the script in a log, so the system is calling it but no idea what its doing, there’s no error though.

2024-05-16 13:25:56 +0800 08 amail MIGRATION:000028B1: closing session with [:143] (migration has finished successfully)
2024-05-16 13:25:56 +0800 08 amail MIGRATION:000028B1: Started migration command '/usr/bin/php /var/opt/axigen/scripts/test.php axigen1@
/var/opt/axigen/’ (pid=84897) for ‘axigen1@******’
2024-05-16 13:25:56 +0800 08 amail WEBMAIL:000028B1: TempMboxManager: attempting to clear inexistent tmp folder path (path: /~tmp)
2024-05-16 13:25:56 +0800 08 amail WEBMAIL:000028B1: ConvJob: update request for domainId 2 userId 16777258
2024-05-16 13:25:56 +0800 08 amail WEBMAIL:000028B1: ConvJob: queuing job for domainId 2 userId 16777258 delay 5

Hmm in case it’s got something to do with PHP I created a plain bash script;

testing SH with; /var/opt/axigen/scripts/ {ACCOUNT_EMAIL} {WORKING_DIRECTORY}

root@amail:/var/opt/axigen/scripts# ls -l /var/opt/axigen/scripts/
-rwxrwxrwx 1 axigen axigen 62 May 16 14:05 /var/opt/axigen/scripts/

2024-05-16 14:09:55 +0800 04 amail MIGRATION:000028D9: Migration command ‘/var/opt/axigen/scripts/’ (pid=85119) for ‘axigen1@******’ returned exit code 1

So i’m not sure whats going on. I can execute that script manually fine. Exit code 1 was the code for a missing script right? but obviously its right there. I must be losing my mind :slight_smile:

Thanks for your help again :slight_smile:


My assumption is that axigen user do not have all environment configuration to execute php scripts. So, maybe you could start with a simpler bash script (like the one below I have used in my tests = /opt/axigen/scripts/ and if all is fine, continue with a simpler php, etc.

#! /bin/bash

date >> /var/tmp/migration.log

Basically, when the command will be executed successfully you will have a log line like:

MIGRATION:0000011B: Successfully executed migration command '/opt/axigen/scripts/' ...


Yep that was my previous test above ^^ using a bash script

Is there any documentation for this process including error codes? It says the return code is 1, which you mentioned before is path to script being wrong, but the path when tested absolutely exists and when tested as the axigen user exists as well, could that error code be for anything other than path? Can i turn the error reporting up? there’s no actual error message logged at all in the server just the migration log line that says it returned a code. But we know the path exists so that doesn’t make sense, right?

Hello Brad,

There is no need for a special documentation as the execution is made via an OS call so the returned error code is provided by OS (if there is any issues to execute the command) or by the command itself. It is somehow similar to how the commands from the cron files are executed (and sometime it is a nightmare to understand why a specific cron job is not producing the expected result …)

Could you please confirm that your script has the so called shebang line so it is clear with which shell it will be executed by the OS?

Note: please double-check my example from my previous post - if I’m taking out the first line I’ll get exit code 1 as well :innocent:


root@amail:/var/opt/axigen/scripts# cat
date +“Year: %Y, Month: %m, Day: %d” >> file.txt

it runs fine if i just call it directly in shell, even as the user.

I’ll try your verbatim example cut and pasted, maybe the space makes a difference, maybe the path makes a difference in the calling scripts context or something.

Thanks for your help!

Ah ha! your direct example worked :slight_smile: ok so it must be the path i was using at the end there i noticed i used a local path which was fine when executed in that dir but of course when axigen calls it its nowhere near it duh :stuck_out_tongue: lol. ok i’m all good now i can design a custom migrator to make sure postfix nuances are transferred :slight_smile:

Thanks for all your help Indreias, you’re awesome!


1 Like