<div dir="ltr">Hi folks,<div><br></div><div>I am trying to achieve:</div><div><br></div><div>    # systemctl start sshd-shell.service (1)</div><div>    # systemctl start sshd-sftp.service (2)<br></div><div>    # systemctl stop sshd-shell.service (3)<br></div><div>    # systemctl stop sshd-sftp.service (4)</div><div><br></div><div>Before the command (1), sshd is not running. By typing (1), /etc/sshd_config is configured to accept ssh shell connections but no sftp connections, and then start sshd. By typing (2), /etc/sshd_config is configured to accept sftp connections too, and sshd is reloaded. By typing (3), /etc/sshd_config is configured to refuse ssh shell connection, and sshd is reloaded again. By typing (4), sshd will be stopped.</div><div><br></div><div>Basically, I wrote the following 3 service units:</div><div><br></div><div>- sshd-core.service: the original sshd</div><div>- sshd-shell.service: ssh shell</div><div>- sshd-sftp.service: sftp server</div><div><br></div><div>The units looks like:</div><div><br></div><div><div>    # sshd-core.service</div><div>    [Unit]</div><div>    Description=OpenSSH Daemon</div><div>    After=network.target</div><div>    StopWhenUnneeded=yes</div><div>    RefuseManualStart=yes</div><div><br></div><div>    [Service]</div><div>    ExecStart=/usr/bin/sshd -D</div><div>    ExecReload=/bin/kill -HUP $MAINPID</div><div>    KillMode=process</div><div>    Restart=always</div><div><br></div><div>    # sshd-shell.service</div><div>    [Unit]</div><div>    Requires=sshd-core.service</div><div>    After=sshd-core.service</div><div>    PropagatesReloadTo=sshd-core.service</div><div><br></div><div>    [Service]</div><div>    Type=oneshot</div><div>    ExecStart=/usr/local/bin/config-sshd.sh enable-shell</div><div>    ExecStop=/usr/local/bin/config-sshd.sh disable-shell</div><div>    ExecReload=/bin/true</div><div>    RemainAfterExit=yes</div><div>    ExecStartPost=/bin/sleep 1</div><div>    ExecStartPost=-/bin/systemctl reload --no-block sshd-core.service</div><div>    ExecStopPost=-/bin/systemctl reload --no-block sshd-core.service</div></div><div><br></div><div>And sshd-sftp.service is similar to sshd-shell.service except the ExecStart= and ExecStop= configures sftp.</div><div><br></div><div>The current problem is that I don't know if there is a better way to achieve this. For example, I have to sleep 1 second before reloading sshd-core.service in sshd-shell.service because otherwise sshd didn't setup the signal handler for SIGHUP and will terminate itself. Or systemd doesn't suggest such use case?</div><div><br></div><div>Thanks for any comments.</div><div><br></div><div>John</div></div>