Comarch Optima — installation
The integration runs on the Windows host where Comarch ERP Optima is installed. It connects to the Optima MS SQL database (read), to Optima’s COM API (write), and reaches Sancho WMS over the cloud message bus (TLS RabbitMQ).
The component ships as a single zip published per DEPLOY_ENV:
| Channel | Zip | Installer |
|---|---|---|
| dev | https://download.sancho-wms.pl/dev/latest/comarch-optima.zip |
https://download.sancho-wms.pl/dev/latest/comarch-optima-install.ps1 |
| prod | https://download.sancho-wms.pl/prod/latest/comarch-optima.zip |
https://download.sancho-wms.pl/prod/latest/comarch-optima-install.ps1 |
Builds are also pinned per commit under <channel>/<short-sha>/... (immutable).
Prerequisites
Section titled “Prerequisites”- 64-bit Windows 10 1607 or Windows Server 2016+ with TLS 1.2.
- PowerShell 5.1 or newer, running as Administrator.
- Comarch ERP Optima installed on the same host (the integration uses the local COM API).
- Outbound access to
download.sancho-wms.pl(image download) and to Sancho’s RabbitMQ host on the TLS port.
What to prepare before running the installer
Section titled “What to prepare before running the installer”-
SQL Server login (read Optima database). In SQL Server Management Studio, enable mixed-mode authentication (SQL Server and Windows Authentication mode), create a SQL login (e.g.
sancho), and grant thedb_datareaderrole on bothCDN_KNF_Konfiguracjaand the company database. Restart the SQL Server service after switching auth modes. -
Optima operator. An operator account with rights to create documents and product cards — used by the COM API for writes. Note the operator login and password.
-
AMQP credentials. Host, user, password, and virtual host for RabbitMQ — issued by Sancho when the integration is activated. Without these the installer cannot finish configuration.
Installation
Section titled “Installation”Run from an elevated PowerShell prompt on the Windows host where Comarch Optima is installed:
irm https://download.sancho-wms.pl/prod/latest/comarch-optima-install.ps1 | iexirm https://download.sancho-wms.pl/dev/latest/comarch-optima-install.ps1 | iexWhat the installer does
Section titled “What the installer does”-
Verifies prerequisites: Administrator, PowerShell 5.1+, 64-bit Windows 10 1607 / Server 2016 or newer, TLS 1.2.
-
Downloads the channel’s
comarch-optima.zipto%TEMP%and logs the SHA-256 fingerprint. -
Prompts for MSSQL / Optima operator / AMQP credentials (secrets via
Read-Host -AsSecureString). -
Installs binaries to
C:\Program Files\SanchoWMS\ComarchOptima\bin\. -
Writes the
.envtoC:\ProgramData\SanchoWMS\ComarchOptima\.env. -
Registers two Windows services via NSSM (auto-start):
SanchoWMSComarchOptima(the integration) andSanchoWMSComarchOptimaUpdater(auto-upgrade poller). -
Starts both services.
Auto-update
Section titled “Auto-update”SanchoWMSComarchOptimaUpdater polls <channel>/latest/comarch-optima.zip hourly via a HEAD request. When the response ETag changes, it downloads the new zip, stops SanchoWMSComarchOptima, swaps SanchoWMSComarchOptima.exe + SanchoWMSComarchOptimaCOM.exe + duckdb.dll (keeping .previous copies for rollback), and restarts the service. If the new build doesn’t reach Running within 30 s, the updater restores the previous binaries and records the failing build’s ETag in state\last-failed-etag.txt — that build is skipped until a new one is published.
The updater does not swap nssm.exe, itself (SanchoWMSComarchOptimaUpdater.exe), or the .env schema — those self-lock or require interactive input, and are only refreshed by a manual re-run of the installer (which stops both services before swapping).
Auto-update state:
| Purpose | Path |
|---|---|
| Last-seen ETag (deletion forces re-check) | C:\ProgramData\SanchoWMS\ComarchOptima\state\last-etag.txt |
| ETag of the last failed upgrade (deletion allows retrying the same build) | C:\ProgramData\SanchoWMS\ComarchOptima\state\last-failed-etag.txt |
| Updater logs (NSSM-captured service log rotated at 10 MB) | C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-updater.log (the updater’s own log), comarch-optima-updater-service.log (merged NSSM stdout + stderr) |
Opt out of auto-updates:
Set-Service SanchoWMSComarchOptimaUpdater -StartupType DisabledStop-Service SanchoWMSComarchOptimaUpdaterManual upgrade
Section titled “Manual upgrade”Re-run the same one-liner. The installer detects the existing services, stops both, swaps all binaries (including nssm.exe and SanchoWMSComarchOptimaUpdater.exe), preserves .env, and restarts both. Any new key added to .env.example is prompted interactively and appended to the existing .env.
Uninstall
Section titled “Uninstall”irm https://download.sancho-wms.pl/prod/latest/comarch-optima-install.ps1 -OutFile $env:TEMP\install.ps1& $env:TEMP\install.ps1 -UninstallRemoves both services and deletes C:\Program Files\SanchoWMS\ComarchOptima\ and C:\ProgramData\SanchoWMS\ComarchOptima\ (.env, logs, state). No partial uninstall — back up .env first if you plan to reinstall later.
Configuration (.env)
Section titled “Configuration (.env)”The .env file lives at C:\ProgramData\SanchoWMS\ComarchOptima\.env. Edits require a restart of the main service:
Restart-Service SanchoWMSComarchOptimaLogging
Section titled “Logging”| Key | Required | Default | Purpose |
|---|---|---|---|
LOG_PRETTY |
no | false |
true enables Pino pretty output (interactive use only) |
LOG_LEVEL |
no | info |
Pino log level (trace, debug, info, warn, error, fatal, silent) |
LOG_FILE |
no | logs\comarch-optima-integration.log |
Integration log path (relative to working directory, i.e. ProgramData). Rotated daily; 14 most recent days kept. |
MSSQL (Optima database)
Section titled “MSSQL (Optima database)”| Key | Required | Default | Purpose |
|---|---|---|---|
MSSQL_SERVER |
yes | localhost |
Optima SQL Server host |
MSSQL_INSTANCE |
no | OPTIMA (installer prompt default) |
Named instance; blank = default instance |
MSSQL_DATABASE |
no | (default) | Database name; blank uses the SQL login’s default |
MSSQL_USER |
yes | sancho |
SQL login |
MSSQL_PASSWORD |
yes | — | SQL password |
Optima (COM writes)
Section titled “Optima (COM writes)”| Key | Required | Default | Purpose |
|---|---|---|---|
OPTIMA_OPERATOR_NAME |
no | — | Optima operator used for COM-API writes |
OPTIMA_OPERATOR_PASSWORD |
no | — | Operator password (blank to skip) |
OPTIMA_FIRM_INDEX |
no | 0 (written by the installer) |
0-based position of the company in Optima’s firm list (first/only company = 0). Look it up in CDN_KNF_Konfiguracja.CDN.Bazy (ROW_NUMBER() OVER (ORDER BY Baz_BazID) - 1) |
OPTIMA_LICENSE_MODEL |
no | auto |
Licence model of the installed Optima key: classic (HASP / Key Manager key), subscription (service model), or auto (tries classic, then subscription). A classic Handel key must use classic — the subscription fallback fails with “Nie masz uprawnień do korzystania z modułu [Podstawowy]” |
OPTIMA_SERVE |
no | true |
Persistent COM session (“serve mode”): true starts the COM CLI once and holds one Optima login with auto-reconnect; false spawns the CLI per request |
AMQP (Sancho message bus)
Section titled “AMQP (Sancho message bus)”| Key | Required | Default | Purpose |
|---|---|---|---|
AMQP_HOST |
yes | — | Sancho-side RabbitMQ host |
AMQP_PORT |
yes | 5671 |
RabbitMQ port (TLS) |
AMQP_VHOST |
yes | / |
Virtual host |
AMQP_USER |
yes | — | RabbitMQ user (per-customer) |
AMQP_PASSWORD |
yes | — | RabbitMQ password |
Host paths
Section titled “Host paths”| Purpose | Path |
|---|---|
Binaries (SanchoWMSComarchOptima.exe, SanchoWMSComarchOptimaCOM.exe, SanchoWMSComarchOptimaUpdater.exe, duckdb.dll, nssm.exe) |
C:\Program Files\SanchoWMS\ComarchOptima\bin\ |
Configuration (.env) |
C:\ProgramData\SanchoWMS\ComarchOptima\.env |
| Integration log (Pino, rotated daily, 14 days) | C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-integration.log (+ .1 … .14 for rolled days) |
| Main service merged stdout + stderr (NSSM, rotated at 10 MB) | C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-integration-service.log |
| Updater logs + NSSM stdout | C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-updater.log, comarch-optima-updater-service.log |
| Auto-update state | C:\ProgramData\SanchoWMS\ComarchOptima\state\last-etag.txt, last-failed-etag.txt |
| Install transcript | C:\Program Files\SanchoWMS\ComarchOptima\install.log |
Operations
Section titled “Operations”Get-Service Sancho*Restart-Service SanchoWMSComarchOptimaGet-Content -Wait 'C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-integration.log'Get-Content -Wait 'C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-integration-service.log'Get-Content -Wait 'C:\ProgramData\SanchoWMS\ComarchOptima\logs\comarch-optima-updater.log'After editing .env, run Restart-Service SanchoWMSComarchOptima to apply changes.