SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Use this forum for discussions about SpamAssassin and anti-spam in general.
Post Reply
User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-11 09:52

I just installed SpamAssassin For Windows.

I ran the sa-update.exe program to update SpamAssassin with current rules update in a Windows Command Prompt.

sa-update -v --nogpg

This did a successful retrieval of SapamAssassin updates.

I then set up a Task Schedule to automatically run this update each day.

Task Schedule Actions are:

Action 1: net stop SpamAssassin
Action 2: "C:\Program Files\JAM Software\SpamAssassin for Windows\sa-update.exe" -v --nogpg
Action 3: net start SpamAssassin

The scheduled Task gets a Successful completion but Action 2 gets a Return Code 2147942401 with a Windows Event Id: 201 but still the Task Scheduler History still reports Action2 as successful. Actions 1 and 3 all got Return Code 0.

Windows Event Id: 201 is supposed to mean a Successful Task Action and No Further Action is Required.

However, I cannot determine if this just means that the Task Action fully completed and with no errors or if it means the Tasks Action Completed without any regard to the actual Action, meaning sa-update, completing successfully.

My question then is did the Action sa-update successfully retrieve the Update Rules for SpamAssassin. Now of course since I had run sa-update in Command Prompt there weren't anymore Rules to retrieve since they had just been retrieved under Command Prompt.

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

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jimimaseye » 2020-05-11 10:10

I run the following (shortened) section in a bat file and it works perfectly.

Code: Select all

net stop spamassassin
sa-update.exe -v --nogpg --channelfile UpdateChannels.txt 
if errorlevel 1 then....
Net start spamassassin
(Note that errorlevel 1 is returned even if there are now no updates since the last update).

More details here: https://www.hmailserver.com/forum/viewt ... 21&t=28139

[Entered by mobile. Excuse my spelling.]
5.7 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

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-11 13:14

jimimaseye wrote:
2020-05-11 10:10
I run the following (shortened) section in a bat file and it works perfectly.

Code: Select all

net stop spamassassin
sa-update.exe -v --nogpg --channelfile UpdateChannels.txt 
if errorlevel 1 then....
Net start spamassassin
(Note that errorlevel 1 is returned even if there are now no updates since the last update).

More details here: https://www.hmailserver.com/forum/viewt ... 21&t=28139

[Entered by mobile. Excuse my spelling.]
Stupid me. I had planned to try running it as a batch file also but got side tracked. It appears to run correctly with a return code now of 0 for the batch file.

One thing to note though is that at least with the SpamAssassin For Windows I installed on my system, apparently the UpdateChannels.txt file does not seem to exist when installing SpamAssassin. I found when searching for how to update SpamAssassin with sa-update that apparently with the arguments I used it will update the rules also from some kind of standard set (best as I recall reading).

Additionally, when examining the Task History to see if the Task executed successfully, you will only see as the Action that 'cmd.exe' was executed instead of your Batch File. This is of course because batch files need to run as a Command Prompt. But you still code the batch file into the Program entry of the Task Scheduler Action tab. And you need to fill in the 'Start in' field with the Path to the batch file which in my case was C:\Program Files\JAM Software\SpamAssassin for Windows\.

One last thing in order to tell if your Batch file ran correctly without failure, in order to see the progress in the Command Prompt, you can code in a 'Pause' in your Batch File to pause the Batch file execution so you can what the results are. You must also set your Task to run only when user is logged on to be able to see the Command Prompt execution. Once you have verified the Batch File ran properly, you can then change your Task to run 'Whether or not the user is logged on' and remove the 'Pause' from the Batch File otherwise it won't run unattended properly.

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-13 19:13

SpamAssassin now runs.

But why in hMailAdmin must I specify localhost or IP Address 127.0.0.1 in order to Test. What I would like to do is to use the Hostname of my Local Network so I can access this SpamAssassin installation from another Local Network I have also running hMailServer. I have tried to Test on the other Local Network using the Hostname of my Local Network which has SpamAssassin installed on it and it always fails.

I have Port 783 open on the SpamAssassin Local Network. I have Port 783 for Spamd.exe open for all PCs in my McAffee Firewall running on the computer with SpamAssassin installed on it.

Is the problem that for Test Purposes you can only run Test when SpamAssassin is installed on the same computer as hMailServer. Doesn't make sense to me. At some point I might like to put SpamAssassin on a server computer to be accessed by any computer which may happen to be running hMailServer without having to install SpamAssassin on the computer running hMailServer. At this point, I don't need to but I like to set up installations when possible to be able to be accessed from anywhere without having to change the setup of the Server.

User avatar
katip
Senior user
Senior user
Posts: 757
Joined: 2006-12-22 07:58
Location: Istanbul

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by katip » 2020-05-13 20:47

jim.bus wrote:
2020-05-13 19:13
SpamAssassin now runs.

But why in hMailAdmin must I specify localhost or IP Address 127.0.0.1 in order to Test. What I would like to do is to use the Hostname of my Local Network so I can access this SpamAssassin installation from another Local Network I have also running hMailServer. I have tried to Test on the other Local Network using the Hostname of my Local Network which has SpamAssassin installed on it and it always fails.

I have Port 783 open on the SpamAssassin Local Network. I have Port 783 for Spamd.exe open for all PCs in my McAffee Firewall running on the computer with SpamAssassin installed on it.

Is the problem that for Test Purposes you can only run Test when SpamAssassin is installed on the same computer as hMailServer. Doesn't make sense to me. At some point I might like to put SpamAssassin on a server computer to be accessed by any computer which may happen to be running hMailServer without having to install SpamAssassin on the computer running hMailServer. At this point, I don't need to but I like to set up installations when possible to be able to be accessed from anywhere without having to change the setup of the Server.
feel free to change IP nr. to that computer's where SA is running and test, within same LAN though. if that box is on another LAN, this is a network (routing) issue. but should also run fine if set up properly.
even installations on WAN is documentec IIRC.
Katip
--
HMS 5.7.0 x64, MariaDB 10.4.10 x64, SA 3.4.2, ClamAV 0.101.2 + SaneS

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-13 23:30

I am going to make an educated guess as to why SpamAssassin has to be run with hostname localhost or IP Address 127.0.0.1.

Apparently to set up SpamAssasin to run as a Windows Service, jimmimaseye advised to use NSSM to make SpamAssassin run as a Windows Service. Apparently SpamAssassin probably because it is an Apache Product and to install it on Windows we had to use JAM Software compile of SpamAssassin, have to use NSSM to be able to install as a Windows Service otherwise it is not entirely compatible with Windows Services requirements.

The actual service which runs in Windows Services is not SpamAssasin but rather NSSM. I am suspecting it is this which makes it a requirement to access SpamAssasin as localhost on my Windows Computer. hMailServer can't find it under the External Hostname nor even under the Computer Name within my Local Network. It strictly needs localhost or IP Address 127.0.0.1 because anywhere outside of the Computer running SpamAssassin, hMailServer will not be able to locate SpamAssassin by its actual application name. Outside of the running computer, SpamAssassin is probably only identified as NSSM as in my installation of it and not by Spamd.exe.

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-13 23:54

jim.bus wrote:
2020-05-13 23:30
I am going to make an educated guess as to why SpamAssassin has to be run with hostname localhost or IP Address 127.0.0.1.

Apparently to set up SpamAssasin to run as a Windows Service, jimmimaseye advised to use NSSM to make SpamAssassin run as a Windows Service. Apparently SpamAssassin probably because it is an Apache Product and to install it on Windows we had to use JAM Software compile of SpamAssassin, have to use NSSM to be able to install as a Windows Service otherwise it is not entirely compatible with Windows Services requirements.

The actual service which runs in Windows Services is not SpamAssasin but rather NSSM. I am suspecting it is this which makes it a requirement to access SpamAssasin as localhost on my Windows Computer. hMailServer can't find it under the External Hostname nor even under the Computer Name within my Local Network. It strictly needs localhost or IP Address 127.0.0.1 because anywhere outside of the Computer running SpamAssassin, hMailServer will not be able to locate SpamAssassin by its actual application name. Outside of the running computer, SpamAssassin is probably only identified as NSSM as in my installation of it and not by Spamd.exe.
spamd listens per default only on 127.0.0.1 ... You should be able to change this by using this commandline parameter:
-i [ipaddress], --listen-ip[=ipaddress], --ip-address[=ipaddress]
Tells spamd to listen on the specified IP address (defaults to 127.0.0.1). If you specify no IP address after the switch, spamd will listen on all interfaces. (This is equal to the address 0.0.0.0). You can also use a valid hostname which will make spamd listen on the first address that name resolves to.
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 00:20

Forgot this one ... so by running "spamd -A 192.168.0.0/24 -i" you make spamd listen on all interfaces (0.0.0.0) and authorise the 192.168.0.0 subnet.

This is all "book ware" as I have not tried it myself ... Yet :wink:
-A host,..., --allowed-ips=host,...
Specify a list of authorized hosts or networks which can connect to this spamd instance. Single IP addresses can be given, ranges of IP addresses in address/masklength CIDR format, or ranges of IP addresses by listing 3 or less octets with a trailing dot. Hostnames are not supported, only IP addresses. This option can be specified multiple times, or can take a list of addresses separated by commas. Examples:
-A 10.11.12.13 -- only allow connections from 10.11.12.13.

-A 10.11.12.13,10.11.12.14 -- only allow connections from 10.11.12.13 and 10.11.12.14.

-A 10.200.300.0/24 -- allow connections from any machine in the range 10.200.300.*.

-A 10. -- allow connections from any machine in the range 10.*.*.*.

By default, connections are only accepted from localhost [127.0.0.1].
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 00:21

jimimaseye wrote:
2020-05-14 00:17
Spamassassin does not run as a service on windows. Nssm is a mechanism to run it as a service.

Spamassassin and nssm must be installed together on whatever computer you choose. You can install them on the same machine as hms or a remote machine.

Hms admin is then told the ip address and port (default 783) of whatever that computer is.

Most run spamassassin on the same machine as hmailserver and so 'localhost' suffices. But if you have installed spamassassin elsewhere then specify it accordingly.

Note: I say this without the hms admin screen in front of me.

[Entered by mobile. Excuse my spelling.]
I use srvany on my server and with Sysinternals TCPView I can see spamd listens on a different interface when I change the parameters.
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

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

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jimimaseye » 2020-05-14 00:23

Spamassassin does not run as a service on windows. Nssm is a mechanism to run it as a service. 

Spamassassin and nssm (if choosing the windows version) must be installed together on whatever computer you choose. You can install them on the same machine as hms or a remote machine. Remote machine can be Linux version of spamassassin if desired.

Hms admin is then told the ip address and port (default 783) of whatever that computer is. 

Most run spamassassin on the same machine as hmailserver and so 'localhost' suffices. But if you have installed spamassassin elsewhere then specify it accordingly.

From what soren is suggesting you may need to tell that remote machine to accept remote connections (instead of just from localhost).

Note: I say this without the hms admin screen in front of me. 

[Entered by mobile. Excuse my spelling.]
5.7 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

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 00:48

hMailServer runs on 192.168.0.5
SpamAssassin runs on 192.168.0.5

Code: Select all

spamd.exe -A 192.168.0.5 --ip-address --allow-tell --max-children=15 --syslog=C:\spamassassin\logs\spamd.log
hMailAdmin.png
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 01:10

changed parameters to allow the entire 192.168.0.0 subnet to use SpamAssassin.

Code: Select all

spamd.exe --allowed-ips=192.168.0.0/24,127.0.0.1 --ip-address --allow-tell --max-children=15 --syslog=C:\spamassassin\logs\spamd.log
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

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

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by mattg » 2020-05-14 03:27

jim.bus wrote:
2020-05-13 19:13
Is the problem that for Test Purposes you can only run Test when SpamAssassin is installed on the same computer as hMailServer.
Nope

I run Spamassassin on my Ubuntu webserver
Test from hMailserver works fine pointing to the IP address of my webserver
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-14 13:31

mattg wrote:
2020-05-14 03:27
jim.bus wrote:
2020-05-13 19:13
Is the problem that for Test Purposes you can only run Test when SpamAssassin is installed on the same computer as hMailServer.
Nope

I run Spamassassin on my Ubuntu webserver
Test from hMailserver works fine pointing to the IP address of my webserver
I believe you don't have the problem because you are running on Ubuntu. I run on Windows 10. If I remember the documentation correctly I believe SpamAssassin was designed for systems that were more Lenix based. Ubuntu is a distribution of Lenix. SpamAssassin apparently is not fully compatible as a Windows Service and as per a jimmisaeye tutoroial needs to be installed as a service called NSSM and it is NSSM which is installed as the Windows Service. From the SpamAssassin website to install SpamAssassin for Windows, I had to download a version of SpamAssassin from JAM Software. Apparently that version specifies spamd.exe to listen by default on only IP Address 127.0.0.1. However, apparently by specifying options, I can have it listen on all IP Addresses if I am interpreting what SorenR and the documentation says correctly by specifying overriding line command options.

So apparently the problem for me is because I am using SpamAssasin for Windows and it defaults to only listen on IP 127.0.0.1. This poses an additional concern as I believe I read in the documentation that it would be possible for an outsider to read messages passed to SpamAssassin. So, if I want to run SpamAssassin on another computer, I need to look at the Authentication and Encryption Options of spamd.exe. Running it on the same computer as hMailServer would, I believe, not necessitate having to use Authentication and Encryption Options as SpamAssassin would already be behind my Router and Computer McAffee Firewalls and protected that way because it would only be listening on Port 783 for IP 127.0.0.1 which is only used internally in the hMailServer computer.

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 13:54

jim.bus wrote:
2020-05-14 13:31
mattg wrote:
2020-05-14 03:27
jim.bus wrote:
2020-05-13 19:13
Is the problem that for Test Purposes you can only run Test when SpamAssassin is installed on the same computer as hMailServer.
Nope

I run Spamassassin on my Ubuntu webserver
Test from hMailserver works fine pointing to the IP address of my webserver
I believe you don't have the problem because you are running on Ubuntu. I run on Windows 10. If I remember the documentation correctly I believe SpamAssassin was designed for systems that were more Lenix based. Ubuntu is a distribution of Lenix. SpamAssassin apparently is not fully compatible as a Windows Service and as per a jimmisaeye tutoroial needs to be installed as a service called NSSM and it is NSSM which is installed as the Windows Service. From the SpamAssassin website to install SpamAssassin for Windows, I had to download a version of SpamAssassin from JAM Software. Apparently that version specifies spamd.exe to listen by default on only IP Address 127.0.0.1. However, apparently by specifying options, I can have it listen on all IP Addresses if I am interpreting what SorenR and the documentation says correctly by specifying overriding line command options.

So apparently the problem for me is because I am using SpamAssasin for Windows and it defaults to only listen on IP 127.0.0.1. This poses an additional concern as I believe I read in the documentation that it would be possible for an outsider to read messages passed to SpamAssassin. So, if I want to run SpamAssassin on another computer, I need to look at the Authentication and Encryption Options of spamd.exe. Running it on the same computer as hMailServer would, I believe, not necessitate having to use Authentication and Encryption Options as SpamAssassin would already be behind my Router and Computer McAffee Firewalls and protected that way because it would only be listening on Port 783 for IP 127.0.0.1 which is only used internally in the hMailServer computer.
Could you just go back and read my last 3 posts? You need 2 extra parameters on the spamd.exe commandline to break the "localhost conundrum". I spend 3 hours investigating this issue last night triggered by your conclusion and my own curiosity. :roll:

If your service launcher for spamd cannot honor parameters on the spamd commandline I suggest you get another!
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-14 15:01

SorenR wrote:
2020-05-14 13:54
jim.bus wrote:
2020-05-14 13:31
mattg wrote:
2020-05-14 03:27


Could you just go back and read my last 3 posts? You need 2 extra parameters on the spamd.exe commandline to break the "localhost conundrum". I spend 3 hours investigating this issue last night triggered by your conclusion and my own curiosity. :roll:

If your service launcher for spamd cannot honor parameters on the spamd commandline I suggest you get another!
SorenR, I believe I acknowledged the information from your 3 Posts in my statement which was really directed to mattg responding to his statement he was able to run SpamAssassin on his Ubuntu Web Server. I was explaining I had the problem because I believed since I used Windows, SpamAssassin for Windows was not fully compatible as a Windows Service but pointed out that you had indicated I could override the default listening only to IP 127.0.0.1 bt extending spamd.exe ti listening on all IP Addresses by use of the line command options you had indicated for which I also had found the Options listed on a SpamAssassin webpage (I think you may have pointed me to that as well).

I added additional information which I believed I had read prior about the possibility of other outside connections being able to have access to SpamAssasin which made me have to consider how secure doing that would be and I would need to look at the Options to see if what I remembered of them allowing Authentication of the connection would overcome the security concern. I knew from what you had already posted that I could specify the listening to more IP Addresses than 127.0.0.1.

Especially from what you indicated about the Options allowing all interfaces to listen on Port 783, I need to go back and check if I really need to use NSSM as the Options you refer to being missing from the Command Line might have been my problem in the first place and I may not really need NSSM. The documentation from jimmisaye was a few years old and JAM Software may have updated their version of SpamAssassin. But I still have to consider the possibility I need to Authenticate to make SpamAssassin secure because what I read about access indicated external connections could have access to to email messages. I need to verify that and if so look at the Authentication and SSL options.

So in short, I was aware of your 3 posts and what you were telling me. I needed to consider the possibility of needing Authentication and SSL before rushing ahead and implementing your information. Above all, I don't want to install something that isn't secure if I can help it. And I was appreciative of the information you had supplied as it let me know there was a way around the issue which I knew probably existed but hadn't yet found.

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by SorenR » 2020-05-14 15:24

open a command window and enter: nssm edit spamassassin (or whatever you named it)
.
nssm.png
nssm.png (10.65 KiB) Viewed 1304 times
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
jim.bus
Senior user
Senior user
Posts: 382
Joined: 2011-05-28 11:49
Location: US

Re: SpamAssassin SA-Update.exe In Task Scheduler Reports Task Successful But SA-Update Gets Nonzero Return Code

Post by jim.bus » 2020-05-14 20:11

SorenR wrote:
2020-05-14 15:24
open a command window and enter: nssm edit spamassassin (or whatever you named it)
.
nssm.png
Thanks much SorenR. I thought it would be something like that. I just needed to go back and find how to do that and you saved me the effort.

Post Reply