How to Remove a service

 

I have tried to successfully remove a Service from the Terminal, but failed to do so.

A Service can have (obviously) three states, "Running", "Stopped" and "Removed".

Status "Stopped" is reached when the Handler-Function OnStart() returns from execution. 

Status "Running" is only valid while the OnStart() function is being executed.

Status "Removed" cannot be reached without user intervention. - Meaning, if the Service critically fails, and the Terminal is restarted, the Service will also be started again.


I assumed the function "ExpertRemove()" would do its job here, but it doesnt. The Service only goes to state "Stopped".

According t othe documentation "ExpertRemove()" only applies to Experts loaded onto a chart. - Naturally, a script calling "ExpertRemove()" will set the _StopFlag and after ending/returning from OnStart() will be auto-removed. 

How could this be achieved for a Service? - Could this be considered an "insufficient" implementation in the functionality of ExpertRemove()?

 
A MQL5 Service program can only be removed (or added) manually by the user, not programmatically (at least not currently).
 
Dominik Christian Egert:

I have tried to successfully remove a Service from the Terminal, but failed to do so.

A Service can have (obviously) three states, "Running", "Stopped" and "Removed".

Status "Stopped" is reached when the Handler-Function OnStart() returns from execution. 

Status "Running" is only valid while the OnStart() function is being executed.

Status "Removed" cannot be reached without user intervention. - Meaning, if the Service critically fails, and the Terminal is restarted, the Service will also be started again.


I assumed the function "ExpertRemove()" would do its job here, but it doesnt. The Service only goes to state "Stopped".

According t othe documentation "ExpertRemove()" only applies to Experts loaded onto a chart. - Naturally, a script calling "ExpertRemove()" will set the _StopFlag and after ending/returning from OnStart() will be auto-removed. 

How could this be achieved for a Service? - Could this be considered an "insufficient" implementation in the functionality of ExpertRemove()?

I don't get what you are trying to achieve ?

 
Fernando Carreiro #:
A MQL5 Service program can only be removed (or added) manually by the user, not programmatically (at least not currently).

Yes. hats what my "complaint" is about....

 
Alain Verleyen #:

I don't get what you are trying to achieve ?

 Iwas refering to this context-menu, I cannot make the service "Remove" (delete) itself from the list of running services in case of (repeated) critical failure.



What I would like to do is being able to call "ExpertRemove()" inside the service and make it remove (delete) from the list of running services...

There is no difference in ExpertRemove() and returning from the handler "OnStart()". - ExpertRemove() only sets the _StopFlag to true, thats it. - 

Contrary to na Expert, the call to ExpertRemove() will also remove (delete) the Expert from the list of Experts currently running.


Maybe a function called "ServiceRemove()" should be introduced, or the functionality of ExpertRemove() could be expanded to cover services as well.

 
Dominik Christian Egert #:

 Iwas refering to this context-menu, I cannot make the service "Remove" (delete) itself from the list of running services in case of (repeated) critical failure.



What I would like to do is being able to call "ExpertRemove()" inside the service and make it remove (delete) from the list of running services...

There is no difference in ExpertRemove() and returning from the handler "OnStart()". - ExpertRemove() only sets the _StopFlag to true, thats it. - 

Contrary to na Expert, the call to ExpertRemove() will also remove (delete) the Expert from the list of Experts currently running.


Maybe a function called "ServiceRemove()" should be introduced, or the functionality of ExpertRemove() could be expanded to cover services as well.

I was not clear with my question, I know you want to find a way to remove the service.

What I would like to know is why ? Doesn't make much sense to me.

 

Do you know this: https://www.mql5.com/en/articles/11826 or the same in German: https://www.mql5.com/de/articles/11826?

It describes how a service ends: 2.4 Loading and unloading services

MQL5 Cookbook — Services
MQL5 Cookbook — Services
  • www.mql5.com
The article describes the versatile capabilities of services — MQL5 programs that do not require binding graphs. I will also highlight the differences of services from other MQL5 programs and emphasize the nuances of the developer's work with services. As examples, the reader is offered various tasks covering a wide range of functionality that can be implemented as a service.
 
Alain Verleyen #:

I was not clear with my question, I know you want to find a way to remove the service.

What I would like to know is why ? Doesn't make much sense to me.

I see where you are coming from.

The main idea was to be able to actively remove the service. This wish comes from the way services are typically handled by OSs, in case of failure, restart. Try 2 or 3 times, then kill.

Since there is no such option by the terminal, I thought I code it myself, and thus the wish arrived, remove the service, have the user actively interact to restart the service.

But I can do it without the removal. It's not a issue to do. It was more a questio of options and the consistency of the usage of ExpertRemove().




 
Carl Schreiber #:

Do you know this: https://www.mql5.com/en/articles/11826 or the same in German: https://www.mql5.com/de/articles/11826?

It describes how a service ends: 2.4 Loading and unloading services

Thank you for the article.

Although docs state ExpertRemov() is prohibited in services, it is actually not and doing exactly as expected. Calling it will set the flag _StopFlag and IsStopped() will be true from that point in time on.


So, maybe that's either a docs-issue or an Implementation bug.

Because it does do the job, except for removing the service.

 
Dominik Christian Egert #:
I see where you are coming from.

The main idea was to be able to actively remove the service. This wish comes from the way services are typically handled by OSs, in case of failure, restart. Try 2 or 3 times, then kill.

Since there is no such option by the terminal, I thought I code it myself, and thus the wish arrived, remove the service, have the user actively interact to restart the service.

But I can do it without the removal. It's not a issue to do. It was more a questio of options and the consistency of the usage of ExpertRemove().




You still didn't answer but that doesn't really matter, I am just curious.

Try what 2 or 3 times, what kind of critical error.

To terminate a service you just have to return in OnStart(), like scripts, there is no really a need for a shortcut function like ExpertRemove(). If you want consistency I can ask a developper to disable ExpertRemove() in scripts and services

 
Alain Verleyen #:

You still didn't answer but that doesn't really matter, I am just curious.

Try what 2 or 3 times, what kind of critical error.

To terminate a service you just have to return in OnStart(), like scripts, there is no really a need for a shortcut function like ExpertRemove(). If you want consistency I can ask a developper to disable ExpertRemove() in scripts and services

haha....

Not funny. 😀

Critical error was relating to something immutable from the service, like a missing "Allowed URL" or a repeated failure, not recoverable from within the service. iE a missing CSV file or similar. Or maybe a malformed link from input, where you get repeated error by WebRequest () function.



So, that's what I was looking at.

My conclusion was to have the service being removed, such that the user needs to interact, and the service doesn't autorun each time I start the terminal.

Maybe you could ask a dev to include the removal of services with ExpertRemove... 😉

Reason: