diff --git a/Makefile b/Makefile index 91b9ded..3c7d9b0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # "Makefile" for graftcp. -# Copyright (C) 2016, 2018 Hmgle +# Copyright (C) 2016, 2018, 2020 Hmgle # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,6 +70,12 @@ install_graftcp:: graftcp uninstall_graftcp:: -rm -f $(DESTDIR)$(BINDIR)/graftcp +install_systemd:: + $(MAKE) -C graftcp-local install_systemd + +uninstall_systemd:: + $(MAKE) -C graftcp-local uninstall_systemd + install_graftcp_local:: $(MAKE) -C graftcp-local install diff --git a/graftcp-local/Makefile b/graftcp-local/Makefile index 1a5fdb8..9de2e26 100644 --- a/graftcp-local/Makefile +++ b/graftcp-local/Makefile @@ -27,6 +27,25 @@ graftcp-local: .gopath/.created $(wildcard *.go) install:: graftcp-local $(INSTALL) $< $(DESTDIR)$(BINDIR)/$< +SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null) + +install_systemd:: install + $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) + test -f $(DESTDIR)/etc/graftcp-local/graftcp-local.conf || \ + install -Dm644 example-graftcp-local.conf $(DESTDIR)/etc/graftcp-local/graftcp-local.conf + install -Dm644 contrib/systemd/graftcp-local.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/graftcp-local.service +ifneq ($(PREFIX),/usr/) + sed -i -re 's#/usr/bin/graftcp-local#$(subst #,\#,${PREFIX})/bin/graftcp-local#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/graftcp-local.service +endif + @echo "Enable and start the graftcp-local systemd unit" + systemctl daemon-reload && systemctl --now enable graftcp-local.service + +uninstall_systemd:: + $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) + @echo "Disable and stop the graftcp-local systemd unit" + systemctl disable --now graftcp-local.service + rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/graftcp-local.service + uninstall:: graftcp-local -rm -f $(DESTDIR)$(BINDIR)/$< diff --git a/graftcp-local/contrib/systemd/graftcp-local.service b/graftcp-local/contrib/systemd/graftcp-local.service new file mode 100644 index 0000000..2e148a1 --- /dev/null +++ b/graftcp-local/contrib/systemd/graftcp-local.service @@ -0,0 +1,15 @@ +[Unit] +Description=Translate graftcp TCP to SOCKS5 or HTTP proxy +After=network.target + +[Service] +StartLimitInterval=5 +StartLimitBurst=10 +ExecStart=/usr/bin/graftcp-local -config /etc/graftcp-local/graftcp-local.conf + + +Restart=always +RestartSec=120 + +[Install] +WantedBy=multi-user.target