5 # don't let people kill us. We shouldn't be long, so this isn't a big deal.
13 function restart_xinetd
()
15 lockfile
-r-1 /var
/run
/.xinetd
-restart.lock
16 kill -HUP $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
|| /usr
/sbin
/xinetd
-pidfile /var
/run
/xinetd.pid
17 rm -f /var
/run
/.xinetd
-restart.lock
20 function restart_xinetd_hard
()
22 lockfile
-r-1 /var
/run
/.xinetd
-restart.lock
23 kill -TERM $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
|| echo >/dev
/null
24 kill -0 $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
&& sleep 1
25 /usr
/sbin
/xinetd
-pidfile /var
/run
/xinetd.pid
26 rm -f /var
/run
/.xinetd
-restart.lock
31 echo "Usage: $(basename $0) --list | <service-name> <command>" >&2
35 if [ "$1" == "--list" ]
39 cd /etc
/xinetd.d
2>/dev
/null
41 cd /System
/Library
/LaunchDaemons
2>/dev
/null
42 ls -1 | egrep '.plist$' | sed 's,.plist$,,g'
44 elif [ "$1" == "--test-if-configured-on" ]
46 if [ -f "/etc/xinetd.d/$2" ]
48 egrep "disable.*=.*no" /etc
/xinetd.d
/$2 >/dev
/null
2>&1
51 if [ -f /System
/Library
/LaunchDaemons
/$2.plist
]
53 IS_OFF
=$(defaults read /System/Library/LaunchDaemons/$2 Disabled 2>/dev/null || true)
63 egrep '^MAILSERVER.*-YES-' /etc
/hostconfig
>/dev
/null
2>&1
66 if [ "$2" = "fax-receive" ]
68 egrep '^fax.*unknown.*on$' /etc
/ttys
>/dev
/null
2>&1
72 elif [ "$1" == "--test-if-available" ]
74 [ -f /System
/Library
/LaunchDaemons
/$2.plist
] && exit 0
75 [ "$2" = "smtp" ] && exit 0
76 [ "$2" = "fax-receive" ] && exit 0
77 [ ! -f "/etc/xinetd.d/$2" ] && exit 1
78 SERVER_FILE
=$(egrep 'server[ ]' "/etc/xinetd.d/$2" | sed 's,.*server[ ]*=[ ]*\(.*\),\
1,g
')
79 [ ! -f "$SERVER_FILE" ] && exit 1
81 elif [ -f "/etc/xinetd.d/$1" ]
85 echo "You must be root to run this option" >&2
88 # yes, /var/run is gross, but it is tmp directory cleaned up a boot,
89 # writable only by root (so i don't need to worry about the security
90 # implications of mktemp)
91 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
92 cp -f "/etc/xinetd.d/$1" $TMPFILE
95 sed 's/disable.*=.*/disable = no/g' < $TMPFILE > "/etc/xinetd.d/$1"
99 sed 's/disable.*=.*/disable = yes/g' < $TMPFILE > "/etc/xinetd.d/$1"
100 if [ "$1" == "nmbd" ]
103 kill -TERM $(cat /var/run/nmbd.pid) || echo >/dev
/null
108 echo "No such service command" >&2
111 elif [ -f "/System/Library/LaunchDaemons/$1.plist" ]
113 [ "$2" == start
] && launchctl load
-w /System
/Library
/LaunchDaemons
/$1.plist
114 [ "$2" == stop
] && launchctl unload
-w /System
/Library
/LaunchDaemons
/$1.plist
115 elif [ "$1" = "smtp" ]
119 echo "You must be root to run this option" >&2
122 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
123 cp -f /etc
/hostconfig
$TMPFILE
126 if grep -q MAILSERVER
=-NO- /etc
/hostconfig
; then
127 sed 's,^MAILSERVER=-NO-,MAILSERVER=-YES-,g' < $TMPFILE > /etc
/hostconfig
131 elif [ "$2" == stop
]
133 if grep -q MAILSERVER
=-YES- /etc
/hostconfig
; then
134 sed 's,^MAILSERVER=-YES-,MAILSERVER=-NO-,g' < $TMPFILE > /etc
/hostconfig
138 echo "No such service command" >&2
141 elif [ "$1" = "fax-receive" ]
145 echo "You must be root to run this option" >&2
148 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
149 cp -f /etc
/ttys
$TMPFILE
152 sed 's,^fax\(.*\)off$,fax\1on,g' < $TMPFILE > /etc
/ttys
154 elif [ "$2" == stop
]
156 sed 's,^fax\(.*\)on$,fax\1off,g' < $TMPFILE > /etc
/ttys
159 echo "No such service command" >&2
163 echo "No such service $1" >&2