Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows service - config file

I know this has probably been asked before but I can't seem to find the right answer for me.

I have a windows service named foobar.exe. I have an application configuration file named foobar.exe.config in the same folder.

Is the config file only read at startup?

I would like to make changes to the config file without having to restart the service but that is the only way I can get the new settings read.

What am I doing wrong?

Can a windows service have a dynamic config file?

like image 599
Lance Perry Avatar asked Feb 24 '11 12:02

Lance Perry


People also ask

Where is service configuration file?

To register the service DLL locally, place the completed service configuration file on each node in the service registration folder located at %CCP_HOME%\ServiceRegistration.

How do I edit a Windows service file?

Click the Start button in the Windows taskbar. In the menu, right-click Command Prompt. On the pop-up right click context menu, select Run as administrator. At the command prompt, enter the SC Config command with the service name to be modified and the parameters to be changed.

How do I configure Windows services?

Press the keys Windows logo+R to open the “Run” dialog. Enter services. msc to open the Window services configuration tool. Configure each new Windows service following the steps of the section above.

Where is WCF config file?

By default, WCF configuration is stored in your app. config (or web. config) file in the <system. serviceModel> section.


2 Answers

.NET applications will read their config files at startup and cache them for performance reasons.

I see two basic ways around this:

  • in your service, keep track of the last update date/time for the config file. Check this last update date regularly and if you detect a change, re-load the config file

  • a Windows NT service can respond to a special OnCustomCommand event. You could implement such an event handler to reload the config, and when you do change the config, you could have a small utility to signal to your service that the config has changed and send that "custom command" to your service

like image 166
marc_s Avatar answered Nov 03 '22 18:11

marc_s


Assuming your windows service was written with .NET:

Configuration files are only read at startup. If you change values in the configuration, you will need to restart the service in order for them to be picked up.

If you want to have dynamic configuration, you will need to implement this yourself - polling the filesystem to see if the configuration file changed and apply the changes.

like image 32
Oded Avatar answered Nov 03 '22 17:11

Oded