SSHD - pid not created - monit monitoring

Hi,

On a 15.1 box, i have ssh which is working except for this pid part.

I have uncommented line

PidFile /run/sshd.pid

in

/etc/ssh/sshd_config

.
[LEFT]
I then restarted SSH and also rebooted the box, however no pidfile is created in /run.
I can see cron.pid, http.pid etc in this /run directory - so its working for other application but not ssh?

ps -ef |grep ssh shows

 
root      1276     1  0 00:49 ?        00:00:00 /usr/sbin/sshd -D
root      1412  1276  0 00:51 ?        00:00:00 sshd: root@pts/0

Any ideas how i get sshd to keep its pid in /run so that i can use it for monit to monitor
ssh ?
[/LEFT]

Hi
Likely because it’s systemd generated…

You can see the pid via either;


systemctl status sshd
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-12-16 09:06:40 CST; 3 days ago
  Process: 1047 ExecStartPre=/usr/sbin/sshd-gen-keys-start (code=exited, status=0/SUCCESS)
  Process: 1052 ExecStartPre=/usr/sbin/sshd -t $SSHD_OPTS (code=exited, status=0/SUCCESS)
 Main PID: 1057 (sshd)
    Tasks: 1
   Memory: 892.0K
   CGroup: /system.slice/sshd.service
           └─1057 /usr/sbin/sshd -D

or

pidof sshd
1057

I don’t actually know the answer.

I think this is because “sshd” is started with the “-D” option, and that probably disables creating a pid file. But the man pages are not completely clear on this. It is started with “-D” because that’s how “systemd” wants to monitor the service.

Yes … i have something similar…
Its just that Monit requires the program’s pid or the programs’ regex to monitor.
I cant get more info on the regex.

So getting the pid is my best bet…

Any impact of me editing the sshd.service file and removing the -D ? Any other changes need to be made ?


systemctl status sshd
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-12-20 00:49:53 +08; 7h ago
 Main PID: 1276 (sshd)
    Tasks: 1
   CGroup: /system.slice/sshd.service
           └─1276 /usr/sbin/sshd -D

Dec 20 00:49:52 cloud06 systemd[1]: Starting OpenSSH Daemon...
Dec 20 00:49:52 cloud06 sshd-gen-keys-start[1186]: Checking for missing server keys in /etc/ssh
Dec 20 00:49:53 cloud06 sshd[1276]: Server listening on 0.0.0.0 port 2206.
Dec 20 00:49:53 cloud06 sshd[1276]: Server listening on :: port 2206.
Dec 20 00:49:53 cloud06 systemd[1]: Started OpenSSH Daemon.

Noted.

If i edit sshd.service to remove the -D , that could be gone the next update ?
Impact of removing the -D ?

Is monit not suitable for opensuse ?

Hi
Likely an upstream issue and not keeping up with systemd? Might pay to ask the developers of the application.

Copy the service to /etc/systemd/system and edit that it will not change after an update. The /etc/systemd location is for user modification or own systemd service files.

From a quick glance at the Monit site, it looks as if it has several different ways to identify a service/process. Maybe there’s already an answer in the documentation somewhere.

Update :

  1. Editing sshd.service and removing " -D " allows the PID file to be created as per settings in /etc/ssh/sshd_config. But this seems to cause some issues in monitoring ssh sessions. So aborted
    this approach.
  2. Use this snippet placed in /etc/monit.d/

check process sshd_monit matching "/usr/bin/sshd"
  start program "/usr/bin/systemctl start sshd"
  stop program "/usr/bin/systemctl stop sshd"
  if failed port 2206 protocol ssh then restart

Result - If sshd dies, its gets restarted via monit.

Thanks everybody.

That is exactly what systemd is supposed to do - restart failed service. Why you need yet another third-party application that duplicates main systemd functionality?

Also doing systemctl stop/start effectively resets failure indication on service (and prevents more advanced systemd features like rate limiting from being useful).