Skip to content

Create 'service timeout' and 'appcmd timeout' command line parameters - #92

Merged
sujitnayak merged 3 commits into
microsoft:mainfrom
leewilmott:feature/create_timeout_parameters
Dec 15, 2025
Merged

sujitnayak merged 3 commits into
microsoft:mainfrom
leewilmott:feature/create_timeout_parameters

Conversation

@leewilmott

Copy link
Copy Markdown
Contributor

This PR fixes an issue whereby it fails intermittently for a number of my containers.

In my case, stopping the w3svc service took longer than the 20 seconds allowed by the original version. This version allows you to specify a timeout to restart the service.

I have also allowed an optional timeout to execute the appcmd command. This addresses an issue originally found here: #79

The new functionality added to this script does not break the existing behaviour.

@leewilmott
leewilmott requested a review from a team as a code owner April 23, 2025 12:14
@leewilmott

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service agree company="Microsoft"

@leewilmott

Copy link
Copy Markdown
Contributor Author

John Hart (@John-Hart),

Please can you review?

Many thanks!

Comment thread src/ServiceMonitor/resource.h Outdated
// Microsoft Visual C++ generated include file.
// Used by ServiceMonitor.rc
//
#define SM_MAJORNUMBER 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These version settings are already defined in version.h. We should be using the values from version.h so this file may not be needed.

Comment thread src/ServiceMonitor/Main.cpp Outdated
bool invalidSyntax = false;
int nextPositionalArgument = 1;

TCHAR buffDrive[3], buffDirName[1024], buffFileName[1024], buffExt[25];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use wchar throughout.

Comment thread src/ServiceMonitor/Main.cpp Outdated
int index;

for (index = 0; index < wcslen(strpointer); index++) {
if ((strpointer[index] < 48) || (strpointer[index] > 57)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use iswdigit or '0'/'9' instead of harcoding ascii values.

Comment thread src/ServiceMonitor/Main.cpp Outdated
return TRUE;
}

bool isNumber(LPCTSTR strpointer) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use LPCWSTR

Comment thread src/ServiceMonitor/Main.cpp Outdated
invalidSyntax = true;
break;
} else if (_wcsicmp(argv[argIndex], L"-st") == 0) {
if (isNumber(argv[argIndex + 1])) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check that argIndex + 1 is less than argc.

@sujitnayak

Copy link
Copy Markdown
Contributor

We should track the .rc change to the copyright string separately from this PR since we would need to get it confirmed from a legal standpoint otherwise.

@leewilmott
leewilmott force-pushed the feature/create_timeout_parameters branch from 18c25f5 to d45f80f Compare August 7, 2025 18:05
@leewilmott

Copy link
Copy Markdown
Contributor Author

Hi sujitnayak,

Many thanks for your review. In light of your comments I have made some changes.

Please forgive my coding...I have never coded in C before. If you want any more changes then please let me know and I'd be happy to do them.

Kind regards,

Lee

Comment thread src/ServiceMonitor/IISConfigUtil.h Outdated
~IISConfigUtil();
HRESULT Initialize();
HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName);
HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, int appcmdTimeoutSeconds);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change the all the timeout types to DWORD?

@sujitnayak

sujitnayak commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Hi sujitnayak,

Many thanks for your review. In light of your comments I have made some changes.

Please forgive my coding...I have never coded in C before. If you want any more changes then please let me know and I'd be happy to do them.

Kind regards,

Lee

Sorry for the delay in following up. The changes look good to me. I have 1 final comment about the type of the timeout variables. Once it is addressed, I will approve the PR. Thanks.

@leewilmott

Copy link
Copy Markdown
Contributor Author

Sorry for the delay in following up. The changes look good to me. I have 1 final comment about the type of the timeout variables. Once it is addressed, I will approve the PR. Thanks.

Hi sujitnayak,

No worries...thank you for taking the time to look at it.

I have now changed the timeout variables from int to DWORD.

Once again, any problems then please let me know.

Out of interest, once this is approved (and merged) will the final .exe be automatically added to new Windows container images?

Many thanks,

Lee

@sujitnayak

Copy link
Copy Markdown
Contributor

Sorry for the delay in following up. The changes look good to me. I have 1 final comment about the type of the timeout variables. Once it is addressed, I will approve the PR. Thanks.

Hi sujitnayak,

No worries...thank you for taking the time to look at it.

I have now changed the timeout variables from int to DWORD.

Once again, any problems then please let me know.

Out of interest, once this is approved (and merged) will the final .exe be automatically added to new Windows container images?

Many thanks,

Lee

There is some additional work at our end to produce a signed binary that can be ingested into the container images.
Once that is completed, I will update this thread.

@sujitnayak
sujitnayak merged commit d8d521e into microsoft:main Dec 15, 2025
1 check passed
@leewilmott

Copy link
Copy Markdown
Contributor Author

Hi sujitnayak,

Is there any update on this issue? Will we see a signed release and will that release be added to the Windows containers?

Many thanks and sorry to chase!

Lee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants