Running a LANSA background Function as a Windows Service

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
PatrickF
Posts: 30
Joined: Thu Nov 26, 2015 1:31 pm

Running a LANSA background Function as a Windows Service

Post 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 ?
BrendanB
Posts: 134
Joined: Tue Nov 24, 2015 10:29 am

Re: Running a LANSA background Function as a Windows Service

Post 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.
LansaHelp
Posts: 9
Joined: Fri May 20, 2022 11:23 pm

Re: Running a LANSA background Function as a Windows Service

Post 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?
René Houba
Posts: 220
Joined: Thu Nov 26, 2015 7:03 am

Re: Running a LANSA background Function as a Windows Service

Post 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 19350 times
Delete LANSA Reports (2).PNG
Delete LANSA Reports (2).PNG (36.37 KiB) Viewed 19350 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 19350 times
René Houba
Posts: 220
Joined: Thu Nov 26, 2015 7:03 am

Re: Running a LANSA background Function as a Windows Service

Post 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 19349 times
Activates LANSA's x_start.exe:
Scheduled task (2).PNG
Scheduled task (2).PNG (50.61 KiB) Viewed 19349 times
The content of APICALL.lvp:
Scheduled task (3).PNG
Scheduled task (3).PNG (16.54 KiB) Viewed 19349 times
Post Reply