How to get systemd "socket" unit to automatically restart? specifically dropbear.socket

3

On my BeagleBone Black Angstrom system, the dropbear.socket UNIT seems to spontaneously die after a while. The effect is that I can not ssh into the machine without restarting the dropbear.socket UNIT. This fixes the problem in the short term:

systemctl restart dropbear.socket

I tried adding Restart=always to the /lib/systemd/system/dropbear.socket file, but that is not allowed (I get an error in the system log).

[Unit]
Conflicts=dropbear.service

[Socket]
ListenStream=22
Accept=yes
Restart=always

[Install]
WantedBy=sockets.target
Also=dropbearkey.service

What's the correct way of getting dropbear.socket to restart automatically? It would be nice to fix the root cause, but this seems like an easy workaround and will make the system more robust.

Update

Here is the list of failed units (I didn't filter it, in case the music service (which I am not using) is a suspect).

% systemctl list-units --failed --full
UNIT                                                  LOAD   ACTIVE SUB    DESCRIPTION
dropbear@1-192.168.0.43:22-192.168.0.40:55370.service loaded failed failed SSH Per-Connection Server
mpd.service                                           loaded failed failed Music Player Daemon

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

Also here is /lib/systemd/system/dropbear@.service

[Unit]
Description=SSH Per-Connection Server
Requires=dropbearkey.service
After=syslog.target dropbearkey.service

[Service]
ExecStart=-/usr/sbin/dropbear -i -r /etc/dropbear/dropbear_rsa_host_key -p 22
ExecReload=/bin/kill -HUP $MAINPID
StandardInput=socket
KillMode=process

Mark Lakata

Posted 2014-02-07T21:15:47.607

Reputation: 4 260

I've created an upstream issue: https://github.com/systemd/systemd/issues/11553

– Jakub Klinkovský – 2019-01-25T10:11:47.493

That's not the service. It's a socket unit. A service will be named dropbear@0-127.0.0.1:22-127.0.0.1:37855.service or similar and is one of a set of services generated from the service template dropbear@.service. You can help answerers by putting the output of systemctl list-units --failed --full|fgrep dropbear@ into your question, or somewhere that they can read it. – JdeBP – 2014-02-07T21:34:14.380

@JdeBP Thanks for the clarification. Does my edit to the question help – Mark Lakata – 2014-02-08T01:22:04.833

What is the error message which follows the Restart=Always statement? – MariusMatutiae – 2014-02-08T10:37:46.977

It will, and has. It helped me to eliminate one answer. (-: – JdeBP – 2014-02-10T02:09:58.463

Answers

0

Have you tried setting the OnFailure flag? Example:

[Unit]
Conflicts=dropbear.service
OnFailure=dropbear.socket

[Socket]
ListenStream=22
Accept=yes
Restart=always

[Install]
WantedBy=sockets.target
Also=dropbearkey.service

0pcode

Posted 2014-02-07T21:15:47.607

Reputation: 13

OnFailure did not work for me. systemd says "foo.socket: Dependency OnFailure=foo.socket dropped" – DrP3pp3r – 2020-01-31T11:10:08.683