View Full Version : Console - function to be called at shutdown
Petr Schreiber
12-03-2016, 09:54
I am thinking about solution for maintaining large amounts of scripts running on servers.
The problem occurs, when new installation of thinBASIC arrives, and I would like to shut them down before the update.
Because most of the scripts are console based, I cannot handle this by processing %WM_CLOSE, but would need something similar.
Now, thinBASIC has TBMain, which is called automagically, so what about new one:
- TBTerminate
Would be called, when somebody attempts to kill thinBASIC process.
It could return a value, indicating whether the shutdown can be performed, or it could also block it.
Let me know, what do you think...
Petr
ErosOlmi
12-03-2016, 11:20
Ciao Petr,
not sure what you need, I try to guess something:
you want a controlled closing of your script so when something try to close it (by [X] for example), thinBasic intercept it and, if present, will perform TBTerminate function
or you want a global command to shut down all scripts under execution
or both
or something I didn't get
I understand in such a situation where many scripts are executed, updating thinBasic can be a problem.
The only solution I see is a kind of "watchdog service" able to "talk" with all running scripts (for example via TCP or UDP) able to tells all script to shut down and later to resume all of them.
Using UDP it would not be that complex to create it, it is very close to UDP_Notify_Server.tBasic, UDP_Notify_Client.tBasic you can find at \SampleScripts\TcpUdp\
I'm thinking to some Server script used as coordinator, all clients share a bit of code able to talk to server.
Every client let the server know that it is alive and what is the script/process/...
The server collects all those info and have some commands to send to all registered clients to shutdown.
Do not know, just an idea
Eros
Petr Schreiber
12-03-2016, 13:31
Hi Eros,
my apologies for not being clear. The note about "many scripts" was just to give context. All I need is a function, which is executed automatically once somebody presses Ctrl-C or tries to terminate tBasic script with console in other way.
So BASICally "you want a controlled closing of your script so when something try to close it (by [X] for example), thinBasic intercept it and, if present, will perform TBTerminate function".
The server idea is great, but I wanted something simple, so I could have scripts like:
Uses "Console"
Function TBMain()
Do
' -- Monitoring
Loop
End Function
Function TBTerminate()
' -- Do any task needed before killing script (writing data, ...)
End Function
Petr