Last active
September 26, 2018 12:04
-
-
Save nosada/580cd40747f10059166799dd9d82aaa9 to your computer and use it in GitHub Desktop.
Expose port for privoxy running on nspawn container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CONTAINER_NAME="torspawn" | |
CONFIG_DIR="/etc/systemd/nspawn" | |
CONFIG_PREFIX="nspawn" | |
CONFIG_LOCATION="$CONFIG_DIR/$CONTAINER_NAME.$CONFIG_PREFIX" | |
INTERNAL="8118" | |
EXPOSING="58118" | |
# Wrong port already exposed: remove port configuration | |
grep $EXPOSING $CONFIG_LOCATION 1> /dev/null 2> /dev/null | |
EXPOSED_CORRECTLY=$? | |
if [ $EXPOSED_CORRECTLY -ne 0 ]; then | |
sed -i $CONFIG_LOCATION -e '/[Pp]ort/d' | |
fi | |
egrep '[Pp]ort' $CONFIG_LOCATION 1> /dev/null 2> /dev/null | |
PORT_CONFIGURED=$? | |
if [ $PORT_CONFIGURED -ne 0 ]; then | |
sed -i $CONFIG_LOCATION \ | |
-e 's/\(\[Network\]\)/\1\nPort='$EXPOSING':'$INTERNAL'/g' | |
fi | |
if [ $EXPOSED_CORRECTLY -ne 0 ] || [ $PORT_CONFIGURED -ne 0 ]; then | |
machinectl stop $CONTAINER_NAME | |
sleep 5 | |
machinectl start $CONTAINER_NAME | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME=expose-privoxy-port-on-nspawn | |
all: install | |
install: ${NAME} ${NAME}.service ${NAME}.timer | |
install -D -m 755 ${NAME} /usr/local/bin/ | |
install -D -m 644 ${NAME}.service /etc/systemd/system/ | |
install -D -m 644 ${NAME}.timer /etc/systemd/system/ | |
systemctl daemon-reload | |
systemctl enable ${NAME}.timer | |
uninstall: | |
systemctl disable ${NAME}.timer | |
rm -f /usr/local/bin/${NAME} | |
rm -f /etc/systemd/system/${NAME}.service | |
rm -f /etc/systemd/system/${NAME}.timer | |
systemctl daemon-reload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Expose port for privoxy running inside nspawn container | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/expose-privoxy-port-on-nspawn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Expose port for privoxy running inside nspawn container | |
[Timer] | |
OnBootSec=1min | |
OnUnitActiveSec=5min | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment