net-proxy/trojan: add multi instances support
authorYixun Lan <dlan@gentoo.org>
Tue, 7 Apr 2020 14:08:04 +0000 (22:08 +0800)
committerYixun Lan <dlan@gentoo.org>
Tue, 7 Apr 2020 14:20:29 +0000 (22:20 +0800)
enable running multi instances while using openrc.

Package-Manager: Portage-2.3.89, Repoman-2.3.20
Signed-off-by: Yixun Lan <dlan@gentoo.org>
net-proxy/trojan/files/trojan.initd
net-proxy/trojan/trojan-1.14.1.ebuild
net-proxy/trojan/trojan-1.15.1.ebuild

index cee794ad4d72b3e1447dd925ab028bf2431ce5b8..2990245430dbf0fc8f81db530b04ad1103a56a1e 100644 (file)
@@ -1,10 +1,17 @@
 #!/sbin/openrc-run
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
-TJ_CONFIG="/etc/trojan/config.json"
-TJ_PIDFILE="/run/trojan.pid"
-TJ_LOG="/var/log/trojan.log"
+TJ_NAME=${SVCNAME##*.}
+if [ -n "${TJ_NAME}" -a "${SVCNAME}" != "trojan" ]; then
+       TJ_PIDFILE="/run/trojan.${TJ_NAME}.pid"
+       TJ_CONFIG="/etc/trojan/${TJ_NAME}.json"
+       TJ_LOG="/var/log/trojan.${TJ_NAME}.log"
+else
+       TJ_PIDFILE="/run/trojan.pid"
+       TJ_CONFIG="/etc/trojan/config.json"
+       TJ_LOG="/var/log/trojan.log"
+fi
 
 depend() {
        need net
index aa4fa9f95bebcc1849c1ca33a3ed5e3f866690a3..21f494f1364df9061de7871ae0c142ca711d1c0a 100644 (file)
@@ -45,3 +45,17 @@ src_install() {
 src_test() {
        cmake_src_test -j1
 }
+
+pkg_postinst() {
+       elog "Running Trojan with multi instances"
+       elog ""
+
+       elog "Prepare /etc/trojan/\${blah}.json first"
+       elog "Config with Openrc"
+       elog "   ln -s /etc/init.d/trojan{,.\${blah}}"
+       elog "   rc-update add trojan.\${blah} default"
+       elog ""
+       elog "Config with Systemd"
+       elog "   systemctl enable trojan.\${blah}"
+       elog ""
+}
index aa4fa9f95bebcc1849c1ca33a3ed5e3f866690a3..21f494f1364df9061de7871ae0c142ca711d1c0a 100644 (file)
@@ -45,3 +45,17 @@ src_install() {
 src_test() {
        cmake_src_test -j1
 }
+
+pkg_postinst() {
+       elog "Running Trojan with multi instances"
+       elog ""
+
+       elog "Prepare /etc/trojan/\${blah}.json first"
+       elog "Config with Openrc"
+       elog "   ln -s /etc/init.d/trojan{,.\${blah}}"
+       elog "   rc-update add trojan.\${blah} default"
+       elog ""
+       elog "Config with Systemd"
+       elog "   systemctl enable trojan.\${blah}"
+       elog ""
+}