updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / tcpcrypt-git / tcpcryptd.rc
blob26534d28a696d59cfc436a7125c4b0d7927f582b
1 #!/bin/bash
3 daemon_name=tcpcryptd
5 . /etc/rc.conf
6 . /etc/rc.d/functions
7 . /etc/conf.d/$daemon_name.conf
9 get_pid() {
10 pidof -o %PPID $daemon_name
13 [ -z "$NFQUEUE_NUM" ] && NFQUEUE_NUM=666
14 [ -z "$PORT" ] && PORT=80
16 # This is taken from launch_tcpcryptd.sh
17 linux_set_iptables() {
18 iptables -I INPUT \! --in-interface lo -p tcp --sport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM || return 1
19 iptables -I OUTPUT \! --out-interface lo -p tcp --dport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM || return 1
22 linux_unset_iptables() {
23 iptables -D INPUT \! --in-interface lo -p tcp --sport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM
24 iptables -D OUTPUT \! --out-interface lo -p tcp --dport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM
26 # These are for easing upgrades, since older versions didn't specify an interface
27 iptables -D INPUT -p tcp --sport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM 2>/dev/null
28 iptables -D OUTPUT -p tcp --dport $PORT -j NFQUEUE --queue-num $NFQUEUE_NUM 2>/dev/null
32 case "$1" in
33 start)
34 stat_busy "Starting $daemon_name daemon"
36 PID=$(get_pid)
37 if [ -z "$PID" ]; then
38 [ -f /var/run/$daemon_name.pid ] && rm -f /var/run/$daemon_name.pid
39 # RUN
40 linux_set_iptables
41 if [ $? -gt 0 ]; then
42 stat_fail
43 exit 1
46 $daemon_name $OPTS -p $NFQUEUE_NUM >/dev/null &
48 if [ $? -gt 0 ]; then
49 stat_fail
50 exit 1
51 else
52 echo $(get_pid) > /var/run/$daemon_name.pid
53 add_daemon $daemon_name
54 stat_done
56 else
57 stat_fail
58 exit 1
62 stop)
63 stat_busy "Stopping $daemon_name daemon"
64 PID=$(get_pid)
65 # KILL
66 linux_unset_iptables
68 [ ! -z "$PID" ] && kill $PID &> /dev/null
70 if [ $? -gt 0 ]; then
71 stat_fail
72 exit 1
73 else
74 rm -f /var/run/$daemon_name.pid &> /dev/null
75 rm_daemon $daemon_name
76 stat_done
80 restart)
81 $0 stop
82 sleep 3
83 $0 start
86 status)
87 stat_busy "Checking $daemon_name status";
88 ck_status $daemon_name
92 echo "usage: $0 {start|stop|restart|status}"
93 esac
95 exit 0