Socket Builder Example
This example shows how to use the SocketBuilder
to create unit file [Socket]
section.
socket_builder.py |
---|
| from systemd_py import SocketBuilder
def main():
builder = SocketBuilder()
builder.with_listen_stream(["8000"])
builder.with_accept(True)
section = builder.build()
print(section)
if __name__ == "__main__":
main()
|
output |
---|
| [Service]
Type='simple'
ExecStart='/usr/bin/python3 -m http.server 8000'
ExecStop='/usr/bin/kill $MAINPID'
Restart='on-failure'
|