mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-03-10 04:59:55 +01:00
Adding more robust exit codes
This commit is contained in:
parent
a95491765d
commit
2f11f50bc2
@ -1,4 +1,4 @@
|
||||
description "Create a tunnel over SSH proxy"
|
||||
description "Create a transparent proxy over SSH"
|
||||
author "Jim Wyllie <jwyllie83@gmail.com>"
|
||||
|
||||
manual
|
||||
@ -8,15 +8,24 @@ nice -5
|
||||
# tunnel.
|
||||
env PREFIX_LOCATION=/etc/sshuttle/prefixes.conf
|
||||
|
||||
# Try all the keys in a given key directory
|
||||
env KEY_LOCATION=/etc/sshuttle/keys
|
||||
|
||||
# Routing table; defaults to 100
|
||||
env ROUTE_TABLE=100
|
||||
|
||||
# fwmark; defaults to 1
|
||||
env FWMARK=1
|
||||
|
||||
# SSH tunnel configuration file
|
||||
env SSHUTTLE_TUNNEL_FILE=/etc/sshuttle/tunnel.conf
|
||||
|
||||
# File containing the tunnel proxy name / host / whatever
|
||||
env TUNNEL_PROXY="/etc/sshuttle/tunnel.conf"
|
||||
|
||||
# Any other commands needed to run before or after loading the SSH tunnel.
|
||||
# This is where you can put any of your hacks to set up tunnels-in-tunnels,
|
||||
# etc. Scripts in this directory are executed in order.
|
||||
env MISC_START_DIR=/etc/sshuttle/pre-start.d
|
||||
env MISC_STOP_DIR=/etc/sshuttle/post-stop.d
|
||||
|
||||
start on (local-filesystems and net-device-up IFACE!=lo)
|
||||
stop on stopping network-services
|
||||
|
||||
@ -30,8 +39,6 @@ pre-start script
|
||||
if [ -f "${PREFIX_LOCATION}" ]; then
|
||||
cat "${PREFIX_LOCATION}" | while read ROUTE; do
|
||||
|
||||
logger "Working on route: ${ROUTE}"
|
||||
|
||||
# Skip comments
|
||||
if [ -n "$(echo ${ROUTE} | egrep "^[ ]*#")" ]; then
|
||||
continue
|
||||
@ -42,18 +49,21 @@ pre-start script
|
||||
continue
|
||||
fi
|
||||
|
||||
logger "Adding route command: ip route add local ${ROUTE} dev lo table ${ROUTE_TABLE}"
|
||||
logger "Adding route: ${ROUTE}"
|
||||
ip route add local ${ROUTE} dev lo table ${ROUTE_TABLE}
|
||||
done
|
||||
fi
|
||||
|
||||
for RUNFILE in ${MISC_START_DIR}/*; do
|
||||
logger "Executing ${RUNFILE}"
|
||||
/bin/sh -c "${RUNFILE}"
|
||||
done
|
||||
end script
|
||||
|
||||
post-stop script
|
||||
if [ -f "${PREFIX_LOCATION}" ]; then
|
||||
cat "${PREFIX_LOCATION}" | while read ROUTE; do
|
||||
|
||||
logger "Working on route: ${ROUTE}"
|
||||
|
||||
# Skip comments
|
||||
if [ -n "$(echo ${ROUTE} | egrep "^[ ]*#")" ]; then
|
||||
continue
|
||||
@ -64,12 +74,17 @@ post-stop script
|
||||
continue
|
||||
fi
|
||||
|
||||
logger "Deleting route command: ip route del local ${ROUTE} dev lo table ${ROUTE_TABLE}"
|
||||
logger "Deleting route: ${ROUTE}"
|
||||
ip route del local ${ROUTE} dev lo table ${ROUTE_TABLE}
|
||||
done
|
||||
fi
|
||||
|
||||
ip rule del fwmark ${FWMARK}
|
||||
|
||||
for RUNFILE in "${MISC_STOP_DIR}/*"; do
|
||||
logger "Executing ${RUNFILE}"
|
||||
/bin/sh -c "${RUNFILE}"
|
||||
done
|
||||
end script
|
||||
|
||||
exec sleep 60
|
||||
exec /home/jim/Projects/sshuttle.udp/src/sshuttle --method=tproxy --listen 0.0.0.0 --remote sshuttle_tunnel -s /etc/sshuttle/prefixes.conf -e "ssh -F ${TUNNEL_PROXY}"
|
||||
|
11
src/main.py
11
src/main.py
@ -193,7 +193,7 @@ try:
|
||||
ipport_v6 = parse_ipport6(ip)
|
||||
else:
|
||||
ipport_v4 = parse_ipport4(ip)
|
||||
sys.exit(client.main(ipport_v6, ipport_v4,
|
||||
return_code = client.main(ipport_v6, ipport_v4,
|
||||
opt.ssh_cmd,
|
||||
remotename,
|
||||
opt.python,
|
||||
@ -204,7 +204,14 @@ try:
|
||||
opt.auto_nets,
|
||||
parse_subnets(includes),
|
||||
parse_subnets(excludes),
|
||||
opt.syslog, opt.daemon, opt.pidfile))
|
||||
opt.syslog, opt.daemon, opt.pidfile)
|
||||
|
||||
if return_code == 0:
|
||||
log('Normal exit code, exiting...')
|
||||
else:
|
||||
log('Abnormal exit code detected, failing...' % return_code)
|
||||
sys.exit(return_code)
|
||||
|
||||
except Fatal, e:
|
||||
log('fatal: %s\n' % e)
|
||||
sys.exit(99)
|
||||
|
Loading…
Reference in New Issue
Block a user