Skip to content

Instantly share code, notes, and snippets.

@alpenfritz
Forked from dryliketoast/socat daemon systemd
Created March 17, 2022 12:00
Show Gist options
  • Select an option

  • Save alpenfritz/eca3f9b9f54fcffe997046d517fe7aed to your computer and use it in GitHub Desktop.

Select an option

Save alpenfritz/eca3f9b9f54fcffe997046d517fe7aed to your computer and use it in GitHub Desktop.

Revisions

  1. @dryliketoast dryliketoast created this gist Dec 22, 2018.
    28 changes: 28 additions & 0 deletions socat daemon systemd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@

    https://unix.stackexchange.com/questions/125382/migrate-socat-init-script-to-systemd
    For socat, I use a pure systemd approach. This is an example for a serial loopback:

    [Unit]
    Description=Socat Serial Loopback
    #Before=my-other.service

    [Service]
    Type=simple
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=socat-serial-lo

    ExecStart=/usr/bin/socat -d -d pty,raw,echo=0,link=/tmp/seriallo-a pty,raw,echo=0,link=/tmp/seriallo-b
    Restart=always

    [Install]
    WantedBy=multi-user.target

    This can be written to /etc/systemd/system/socat-serial-lo.service (in Ubuntu 16.04+), and then:

    systemctl daemon-reload
    systemctl start socat-serial-lo
    systemctl enable socat-serial-lo # (to start it during bootup)

    One advantage of this method is that the command line defined by ExecStart can be tested directly from command line without alterations, in order to test the command.
    answered Sep 21 at 13:45