hMailServer hangs on restarting via a script to reload certificate

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-06 16:51

I'm using LetsEncrypt to review my certificates which are used by the website server and also by hMailServer. I read on the forum that hMailServer needs to be restarted to reload the new certificates and the best way to do it so to run the following scripts in the task scheduler when letsencrypt is run.

So I added the following script to be run after letsencrypts runs.

Code: Select all

Option Explicit

Private const g_sAdminPassword = "superpwd"

Dim oApp
Set oApp = CreateObject("hMailServer.Application")
' Give this script permission to access all
' hMailServer settings.
Call oApp.Authenticate("Administrator", g_sAdminPassword)

Call oApp.Stop
Wait(5)
Call oApp.Start

Function Wait(sec)
	Dim t
	t = Timer
	Do While ((Timer - t) < sec) Xor (Timer < t)
	Loop
End Function
This was working fine, until about a week ago now the server hangs when the task scheduler runs the script. The server looks like this:
Stopping.png
Stopping.png (47 KiB) Viewed 473 times
When I force restart the hMailServer from the windows service manager, I get this error:
RestartError.png
RestartError.png (7.48 KiB) Viewed 473 times
This suggests that the line failing is:
Call oApp.Stop
Anyone has any idea why this scripts has suddenly stopped working and if there's a better way to restart hMailServer to reload the letsencrypt certificates?

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-06 17:29

The script was taken from this topic:
https://www.hmailserver.com/forum/viewtopic.php?t=32593

I even tried switching to a bat file to use the net stop service command this is what I get:
C:\Windows\system32>NET STOP hMailServer
The service is not responding to the control function.

More help is available by typing NET HELPMSG 2186.

User avatar
jimimaseye
Moderator
Moderator
Posts: 7953
Joined: 2011-09-08 17:48

Re: hMailServer hangs on restarting via a script to reload certificate

Post by jimimaseye » 2019-06-06 21:41

The RCVD_SYN problems previously discussed in the other thread only come in to play when doing this action. I still think your problem is related to it.

[Entered by mobile. Excuse my spelling.]
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-06 22:00

I checked and there are no SYNC_RCVD connections on hMailServer when this happens. Just one UDP port on hMailServer that’s it.

User avatar
jimimaseye
Moderator
Moderator
Posts: 7953
Joined: 2011-09-08 17:48

Re: hMailServer hangs on restarting via a script to reload certificate

Post by jimimaseye » 2019-06-06 22:03

Several months ago there was a windows patch but also caused the same symptoms. It was only resolved after either the patch was removed or the subsequent fix patch was installed from Microsoft. Are you sure you don't have something like that causing you your problem?

Edit : https://www.hmailserver.com/forum/viewt ... 10#p205310

[Entered by mobile. Excuse my spelling.]
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-06 22:14

Thanks. I checked and it doesn’t apply here since we are using 2012 R2. Any other thoughts ?

User avatar
jimimaseye
Moderator
Moderator
Posts: 7953
Joined: 2011-09-08 17:48

Re: hMailServer hangs on restarting via a script to reload certificate

Post by jimimaseye » 2019-06-06 22:21

Nope. Except to say they are the only things i know (so far) that have caused similar symptoms. Your cause may not be the same but perhaps they might give you some food for thought for similar esoteric causes. (Every cause had a 1st time)

[Entered by mobile. Excuse my spelling.]
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-07 00:42

So true to Windows, I did a reboot and for now the batch file seems to be working fine. However the script above is definitely creating an issue and still causing a hang (which then hangs the batch file also). I don't know what's with the script/API but it isn't happy about something which then messes up the system. I'll track for a few more days and report back if anything changes.

User avatar
mattg
Moderator
Moderator
Posts: 19810
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: hMailServer hangs on restarting via a script to reload certificate

Post by mattg » 2019-06-07 01:37

Try with more than 5 seconds in the wait
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

palinka
Senior user
Senior user
Posts: 837
Joined: 2017-09-12 17:57

Re: hMailServer hangs on restarting via a script to reload certificate

Post by palinka » 2019-06-07 02:02

RBoy wrote:
2019-06-07 00:42
So true to Windows, I did a reboot and for now the batch file seems to be working fine. However the script above is definitely creating an issue and still causing a hang (which then hangs the batch file also). I don't know what's with the script/API but it isn't happy about something which then messes up the system. I'll track for a few more days and report back if anything changes.
I had the same problems with Jimi's excellent backup script: hang at net stop. So i used powershell to beat the service into submission.

https://www.hmailserver.com/forum/viewt ... &start=120

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-07 14:17

mattg wrote:
2019-06-07 01:37
Try with more than 5 seconds in the wait
It never makes it to the 5 second wait in the script. It just hangs indefinitely at the stop call

User avatar
jimimaseye
Moderator
Moderator
Posts: 7953
Joined: 2011-09-08 17:48

Re: hMailServer hangs on restarting via a script to reload certificate

Post by jimimaseye » 2019-06-07 14:51

You tried not doing the stop call and simply doing net stop / start?

[Entered by mobile. Excuse my spelling.]
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

RBoy
New user
New user
Posts: 21
Joined: 2018-12-04 04:28

Re: hMailServer hangs on restarting via a script to reload certificate

Post by RBoy » 2019-06-07 18:00

Yes that’s what works (see my earlier posts). Net stop throws an error but eventually returns and then net start works.

Post Reply