Welcome! Log In Create A New Profile

Advanced

[WD26] Windows Service problem

Posted by marcov 
[WD26] Windows Service problem
September 30, 2021 06:34PM
hi,
I have a service with a timer, every minute it executes a query and if it finds records it executes an httpsend call,
everything works correctly as soon as I start the service but then it stops working after a few minutes, can anyone give me some indication?
thanks
Re: [WD26] Windows Service problem
September 30, 2021 09:27PM
Hi Marco,

does the service STOP or does it FREEZE?
Is there anything in the window event log?

A service is not allowed to do any gui interactions, so I would check first wheather there is a info() or trace() or something like that.
If you use printing functions you need to change the user context, as the standard user used for services (in german NT Authorität) is not allowed to print.

Do you have an internal logging?
I would try to write procedure names into a textfile. So you could see if it stops at the same piece of code everytime or randomly.


Regards

Stefan.
Argus
Re: [WD26] Windows Service problem
October 01, 2021 03:29AM
One idea...

check that you do not have any instructions trying to access the UI (by example, an info(ErrorMessage) when you have an error somewhere/anywhere, as a service is not allowed to access the UI

Alternatively, to verify that it's the problem, you can go into the service settings and specifically allow it to access the UI... If the service doesn't stop anymore, you know why
Re: [WD26] Windows Service problem
October 01, 2021 08:02AM
Hi marcov,

In the running section (main loop) you can add an exception like this:

CASE EXCEPTION:
ServiceWriteEventLog("Exception:" + CR + ExceptionInfo(), elError)
EndService(esFailure)

Regards

Vassilis Boutsikas
Re: [WD26] Windows Service problem
October 01, 2021 11:15AM
Hi Marcov

A service normally doesn't use a timer.
You need to use the service blocks in project code for the "service" configuration of your project (not a windows executable).

In there you will see the following blocks:
    [*] Initializing YourProjectName
    [*] Running the Service of YourProjectName (Called in a loop)
    [*] Stopping YourProjectName
    [*] Stopping the Service of YourProjectName
    [*] Automatic Test of YourProjectName

It is in the second section (Running the Service of YourProjectName (Called in a loop)) that you manage your service execution (shoot of processes in threads e.g.). And please don't use a timer variable over there between the executions but use the ServiceWait() command in this section to gracefully sleep between service loop executions...

I also have the impression that you're missing Exception Handling and Logging in your project.
Surround your code with a WHEN EXCEPTION IN ... DO ... END block and log or communicate the info from ExceptionInfo() somewhere.
It'll ease your life and should do the trick.

Next install your service using simple Command Line SC commands (i.e. sc create) and don't use the WD installer...
I have services who have been running for years on servers without a single issue...

Just my 2 cents

Peter Holemans
Re: [WD26] Windows Service problem
October 01, 2021 08:47PM
Hi,
the timer is present in the example that I found in windev I did nothing but change that ... however I changed the user it runs on the server and now it seems to work fine.
Thanks
Re: [WD26] Windows Service problem
October 03, 2021 03:51PM
Hi Marco,

just because im curious:
are there printing features in the service?
what kind of user do you use: admin ?

regards


Stefan.
Re: [WD26] Windows Service problem
October 04, 2021 10:44AM
hi Stefan,

I don't print but have only two httpsend calls.
after the weekend the service still stopped working.
I really don't know what to change.
the service does not trace or print .. nothing just a query and two httpsend calls.
Re: [WD26] Windows Service problem
October 04, 2021 11:17AM
Hi Marcov

Do you have an exception handler in your code?
Without it will be hard to identify the source of any fatal issue at runtime in a service...

Peter
Re: [WD26] Windows Service problem
October 04, 2021 12:25PM
Hi peter,

CASE EXCEPTION:
// In case of exception, adds an error into the log of events
ServiceWriteEventLog(ExceptionInfo, elError)
//Gestione LOG
nFileNum is int
sLineToWrite is string

nFileNum = fOpen(fExeDir()+"\log.txt", foCreateIfNotExist)


IF nFileNum <> -1 THEN
nResPosition is int = fSeek(nFileNum , 0, fpEnd)
sLineToWrite = DateSys+" "+Now() +":"+ExceptionInfo

// Write the line
fWriteLine(nFileNum, sLineToWrite)
fClose(nFileNum)
END


// Stops the service
EndService(esFailure)

but nothing is written
Re: [WD26] Windows Service problem
October 04, 2021 12:28PM
hi,

another information,
I added a log write every time it performs an action, on my pc it writes the log file, but nothing on the server.
Re: [WD26] Windows Service problem
October 05, 2021 10:04PM
Hi Marco,

I've got several services that have been running for many years non-stop with the exception of reboots for OS updates.

You may want to add in some debug and processing logic that checks to see if something is still being processed and it is continually stepping on itself and eventually failing.

One of the services I have is an SMS processor. So it gathers all the unprocessed messages to be sent via sms and then attempts to send them via an API to a provider and if any fail, they fall back to email.

Let me know if you have any more questions.

cheers!
Ken

PS. Also check the system event viewer for any errors or signals of the problem.
Re: [WD26] Windows Service problem
October 06, 2021 10:22AM
hi,
I added the log to file for see if the service is FREEZE.
I also replaced the Wait with ServiceWait


// Run the service CALLED IN LOOP
sPaht is string
sPaht = fExeDir()
nTimer is int
nTimer =INIRead("Comandi", "timer", "", sPaht+"\XXXXX.ini")

chiamahttp()

//Gestione LOG
nFileNum is int
sLineToWrite is string
nFileNum = fOpen("c:\XXXX\XXXX.log", foCreateIfNotExist)

IF nFileNum <> -1 THEN
nResPosition is int = fSeek(nFileNum , 0, fpEnd)
sLineToWrite = DateSys+" "+Now() +": Procedura attiva"

// Write the line
fWriteLine(nFileNum, sLineToWrite)

fClose(nFileNum)
ELSE
ServiceWriteEventLog("Errore aprendo il file", elInformation)
END

// Pause during 120 seconds
ServiceWait(nTimer)

CASE EXCEPTION:
// In case of exception, adds an error into the log of events

//Gestione LOG
nFileNum = fOpen("c:\XXXX\XXXX.log", foCreateIfNotExist)

IF nFileNum <> -1 THEN
nResPosition is int = fSeek(nFileNum , 0, fpEnd)
sLineToWrite = DateSys+" "+Now() +": Procedura IN ERRORE"

// Write the line
fWriteLine(nFileNum, sLineToWrite)

fClose(nFileNum)
ELSE
ServiceWriteEventLog("Procedura IN ERRORE", elInformation)
END

ServiceWriteEventLog(ExceptionInfo, elError)

// Stops the service
EndService(esFailure)
Re: [WD26] Windows Service problem
October 11, 2021 09:31AM
hi,
after adding the logs of the post before i saw that the service no not crash.
it stays alive the log procedure continues to work.
but it is no longer executed query, as if there was no more connection with mysql.

any idea?

thanks
Re: [WD26] Windows Service problem
November 16, 2021 02:01PM
hi,

i solved switching from SQLExec() to HExecuteQuery.

thanks

visit www.wxitalia.it
Re: [WD26] Windows Service problem
November 16, 2021 04:50PM
Hi Marco,

what I do as add in:

every Service writes in every servicloop executed a timestamp in a textfile.
Then I have a "watchdog" service with checks:
- is the service running, if not it trys to start the service (ServiceState(), ServicStart(), ServiceStop())
- is the timestamp too old (service seems to freeze) it restarts the service.

I implemented this years ago in a very critical application.
The watchdog service could also send e-Mail alerts or reports if needed.

Regards

Stefan.
Re: [WD26] Windows Service problem
November 24, 2021 08:00AM
I don't print but have only two httpsend calls.
after the weekend the service still stopped working.
I really don't know what to change.


——————————————————————————————————————————
boston celtic black jersey
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: