10

This is the complaint I get from systemd:

"opendkim.service: Can't open PID file /var/run/opendkim/opendkim.pid"

As seen here:

systemctl status opendkim.service

puts out this:

● opendkim.service - OpenDKIM DomainKeys Identified Mail (DKIM) Milter
   Loaded: loaded (/lib/systemd/system/opendkim.service; enabled; vendor preset: enabled)
   Active: deactivating (stop-sigterm) (Result: timeout)
     Docs: man:opendkim(8)
           man:opendkim.conf(5)
           man:opendkim-genkey(8)
           man:opendkim-genzone(8)
           man:opendkim-testadsp(8)
           man:opendkim-testkey
           http://www.opendkim.org/docs.html
  Process: 8217 ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf (code=exited, status=0/SUCCESS)
    Tasks: 6 (limit: 2361)
   CGroup: /system.slice/opendkim.service
           └─8226 /usr/sbin/opendkim -x /etc/opendkim.conf

Feb 11 04:56:48 hacksaw.org systemd[1]: Starting OpenDKIM DomainKeys Identified Mail (DKIM) Milter...
Feb 11 04:56:48 hacksaw.org systemd[1]: opendkim.service: Can't open PID file /var/run/opendkim/opendkim.pid (yet?) after start: No such file or directory
Feb 11 04:56:48 hacksaw.org opendkim[8226]: OpenDKIM Filter v2.11.0 starting (args: -x /etc/opendkim.conf)
Feb 11 04:58:18 hacksaw.org systemd[1]: opendkim.service: Start operation timed out. Terminating.

If I start the daemon by hand, it goes. This seems to be about systemd.

Other data:

#ls -ld /var/run/opendkim/
drwxr-xr-x 2 opendkim opendkim 40 Feb 11 04:25 /var/run/opendkim/

The only line on the opendkim.conf:

UserID      opendkim:opendkim

The default opendkim service file, from /lib/systemd/service:

[Unit]
Description=OpenDKIM DomainKeys Identified Mail (DKIM) Milter
Documentation=man:opendkim(8) man:opendkim.conf(5) man:opendkim-genkey(8) man:opendkim-genzone(8) man:opendkim-testadsp(8) man:opendkim-testkey http://www.opendkim.org/docs.html
After=network.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/opendkim/opendkim.pid
UMask=0007
ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf
Restart=on-failure
ExecReload=/bin/kill -USR1 $MAINPID

[Install]
WantedBy=multi-user.target
Hack Saw
  • 331
  • 1
  • 3
  • 11
  • 2
    Does [this](https://serverfault.com/questions/293006/opendkim-filter-unable-to-create-listening-socket/779630) answer your question? – Jos Feb 11 '19 at 10:28
  • No, but it did shorten my path to an answer. – Hack Saw Feb 11 '19 at 21:38
  • Note to self: [this is the right answer to this problem](https://serverfault.com/questions/847435/cant-change-opendkim-socket-in-debian-stretch-in-etc-default-opendkim) – sanmai Jul 24 '19 at 08:21

6 Answers6

13

I fixed it by specifying the PidFile in the /etc/opendkim.conf file:

PidFile                 /var/run/opendkim/opendkim.pid

I think it's better to solve it here than modifying the systemd script. Also, systemd recommends the PIDFile option if the Type option is set to forking, which it seems to be in this service.

This PidFile setting was present in the default /etc/opendkim.conf file. However, I replaced that file while I was following a tutorial for configuring OpenDKIM. So that is where it went wrong for me.

gitaarik
  • 713
  • 6
  • 12
  • Right answer ... but ... really??? The service file knows where to expect the PID file, but the default configuration does not put it there. This answer saved my hours, thank you! – BurninLeo Aug 29 '20 at 14:53
6

Since this daemon runs alone, systemd doesn't need anything special to manage it. Importantly, having a "PIDFile" directive suggests that it's a more complicated service, and will put a PID into the PIDFile on it's own.

The solution is to remove the PIDFile line. Now systemd handles it just fine.

Hack Saw
  • 331
  • 1
  • 3
  • 11
  • 1
    This should have been upvoted. Just do sudo systemctl edit opendkim and add the line [Service] followed by the ine PIDFile= – Dominic108 Nov 16 '19 at 03:57
  • 1
    This worked for me also on Ubuntu 18.04. Edit /lib/systemd/system/opendkim.service and remove the line: PIDFile=/var/run/opendkim/opendkim.pid – meelash Mar 27 '20 at 14:37
  • @meelash your comment is correctly. Thank you. – Duque Sep 07 '22 at 16:06
1

In my case was due to the fact that /var/run was a symlink to /run. After changing the PIDFile path from /var/run/opendkim/opendkim.pid in /run/opendkim/opendkim.pid in opendkim.service, the problem went away.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
CozC
  • 11
  • 1
0

Editing this file here does it for me.

/usr/lib/systemd/system/opendkim.service

by changing PidFile /var/run/opendkim/opendkim.pid to

PidFile   /run/opendkim/opendkim.pid

my platform is centos 7

Bluelily
  • 1
  • 1
0

I fixed this issue by editing the systemctl file like this:

nano /etc/systemd/system/multi-user.target.wants/opendkim.service

[Service]
PIDFile=/var/run/opendkim/opendkim.pid
ExecStartPost=/bin/sh -c 'chown opendkim:opendkim /var/run/opendkim/opendkim.pid'

It will set the correct permission for the opendkim.pid file before starting the service. This is the reason why opendkim said "No such file or directory". The file is not available for the opendkim service.

Feriman
  • 198
  • 4
-1

I solve this problem just by creating opendkim folder in /var/run/ and chowned it to opendkim:opendkim. After that the service started correctly and created its pid-file.