Page 1 of 1

Running a LANSA background Function as a Windows Service

Posted: Fri Apr 28, 2023 1:46 pm
by PatrickF
There was an article posted on a private blog 10 years ago covering the topic - https://lansablog.wordpress.com/2012/03 ... s-service/ and a C# project. Unfortunately the code attachment link links to a dead site.
In the last decade nssm - https://nssm.cc/usage has been used as the poor man's method of setting up services, although some virus scanners don't like it, and I have used it outside of LANSA.
The scenario I have is a WIndows application deployment that starts a function from .BAT files which continuously runs and processes streams of data into SQL Server and updating an IBMi backend. The current issue with manually running the function using .BAT files containing X_RUN switches is that the Function may start running more than once, and a service will improve memory management and ensure the LANSA batch function runs only once at application startup.

What techniques are folks using to run LANSA batch functions as windows services in 2023 with LANSA V14SP2 or V15 ?

Re: Running a LANSA background Function as a Windows Service

Posted: Fri Apr 28, 2023 3:31 pm
by BrendanB
Patrick,

Portalize does something like:

Code: Select all

powershell -command "Start-Process -filepath 'cmd.exe' -ArgumentList '/C schtasks /Create /ru pcxuser /rp pcxuser /tn StartPortalBackgroundProcesses /xml C:\Progra~2\Visual~1\Internal\X_WIN95\X_LANSA\x_BPF\portal\plugins\StartPortalProcesses_installed.xml /F' -WindowStyle Maximized -Verb RunAs"
during its installation...

this actually creates a 'scheduled task' that runs on startup.

you can check out the xml file for additional settings....

the *initial* function just does a SUBMIT function which uses #XPRIM_OSUtil.ThreadSleep Milliseconds(#LoopDelay)
to control its loop....

B.

Re: Running a LANSA background Function as a Windows Service

Posted: Mon May 01, 2023 1:02 am
by LansaHelp
Perhaps this will help:
https://stackoverflow.com/questions/358 ... executable

Create the Windows service and run the X_RUN.EXE with appropriate parameter settings?

Re: Running a LANSA background Function as a Windows Service

Posted: Mon May 01, 2023 11:53 pm
by René Houba
As an example.....

For a customer that creates a lot of LANSA reports in Windows, I created a task in the Windows job scheduler that activates a powerscript that deletes reports older than xx days.
Delete LANSA Reports (1).PNG
Delete LANSA Reports (1).PNG (41.43 KiB) Viewed 19347 times
Delete LANSA Reports (2).PNG
Delete LANSA Reports (2).PNG (36.37 KiB) Viewed 19347 times
The complete argument:
-File C:\LANSA_Scripts\delete_Lansa_reports.ps1 -partition PRD

The script:
Delete LANSA Reports (3).PNG
Delete LANSA Reports (3).PNG (18.73 KiB) Viewed 19347 times

Re: Running a LANSA background Function as a Windows Service

Posted: Tue May 02, 2023 12:13 am
by René Houba
Another example where a Windows scheduled task activates a LANSA program, doing a REST-API call to an iSeries database.....
Scheduled task (1).PNG
Scheduled task (1).PNG (13.17 KiB) Viewed 19346 times
Activates LANSA's x_start.exe:
Scheduled task (2).PNG
Scheduled task (2).PNG (50.61 KiB) Viewed 19346 times
The content of APICALL.lvp:
Scheduled task (3).PNG
Scheduled task (3).PNG (16.54 KiB) Viewed 19346 times