2

I'm running ASSP on CentOS 7 which uses systemd. The only pre-made service file I could find (howtoforge.com) uses oneshot type which I'm not sure is right. More importantly, the stop command seems to kill all perl programs I have running (so I commented that out). But now I'm not sure it's stopping properly on shutdown. Can someone advice on how to improve the service file:

[Unit]
Description=AntiSpam SMTP Proxy
After=network.target

[Service]
Type=Simple
Environment=PERL5LIB=/root/perl5/lib/perl5/
ExecStartPre=-rm -f /usr/local/assp/pid
ExecStart=/usr/bin/perl /usr/local/assp/assp.pl /usr/local/assp/
ExecStopPost=-rm -f /usr/local/assp/pid

[Install]
WantedBy=multi-user.target
TSG
  • 1,634
  • 6
  • 29
  • 51

1 Answers1

1

Type=oneshot doesn't make sense for any program that is meant to run continuously, whether as a daemon or otherwise. So you are right about that. You have indeed found another bad Internet tutorial (on a site infamous for them; and that tutorial has many other problems as well).

From reviewing the sample init script on assp's wiki, it appears that the program runs in the foreground, and does not daemonize itself. Type=simple (the default) is appropriate for this sort of service.

An ExecStop= line is not usually required for a Type=simple service, as systemd already knows what process to stop. It would only be required for something with an unusual stop procedure, but assp just accepts a signal and terminates, like any other process. You can omit this line.

Aside from those issues, you have duplicated an ExecStartPre= line. You probably only need it once. You might also want to set the WorkingDirectory= to the directory where you've installed assp, as the old style init script also did this.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • I corrected the duplicate ExecStartPre to be ExecStopPost. I found an empty assp pid file was sometimes found on system start, and the assp perl script complained about a non-numeric pid and crashed. (I assume it didn't get deleted). – TSG Sep 03 '18 at 00:36