7 # don't let people kill us. We shouldn't be long, so this isn't a big deal.
15 function restart_xinetd
()
17 lockfile
-r-1 /var
/run
/.xinetd
-restart.lock
18 kill -HUP $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
|| /usr
/sbin
/xinetd
-pidfile /var
/run
/xinetd.pid
19 rm -f /var
/run
/.xinetd
-restart.lock
22 function restart_xinetd_hard
()
24 lockfile
-r-1 /var
/run
/.xinetd
-restart.lock
25 kill -TERM $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
|| echo >/dev
/null
26 kill -0 $(cat /var/run/xinetd.pid 2>/dev/null) 2>/dev
/null
&& sleep 1
27 /usr
/sbin
/xinetd
-pidfile /var
/run
/xinetd.pid
28 rm -f /var
/run
/.xinetd
-restart.lock
33 echo "Usage: $(basename $0) --list | <service-name> <command>" >&2
37 if [ "$1" == "--list" ]
41 cd /etc
/xinetd.d
2>/dev
/null
43 cd /System
/Library
/LaunchDaemons
2>/dev
/null
44 ls -1 | egrep '.plist$' | sed 's,.plist$,,g'
46 elif [ "$1" == "--test-if-configured-on" ]
48 if [ -f "/etc/xinetd.d/$2" ]
50 egrep "disable.*=.*no" /etc
/xinetd.d
/$2 >/dev
/null
2>&1
53 if [ -f /System
/Library
/LaunchDaemons
/$2.plist
]
55 IS_OFF
=$(defaults read /System/Library/LaunchDaemons/$2 Disabled 2>/dev/null || true)
65 egrep '^MAILSERVER.*-YES-' /etc
/hostconfig
>/dev
/null
2>&1
68 if [ "$2" = "fax-receive" ]
70 egrep '^fax.*unknown.*on$' /etc
/ttys
>/dev
/null
2>&1
74 elif [ "$1" == "--test-if-available" ]
76 [ -f /System
/Library
/LaunchDaemons
/$2.plist
] && exit 0
77 [ "$2" = "smtp" ] && exit 0
78 [ "$2" = "fax-receive" ] && exit 0
79 [ ! -f "/etc/xinetd.d/$2" ] && exit 1
80 SERVER_FILE
=$(egrep 'server[ ]' "/etc/xinetd.d/$2" | sed 's,.*server[ ]*=[ ]*\(.*\),\
1,g
')
81 [ ! -f "$SERVER_FILE" ] && exit 1
83 elif [ -f "/etc/xinetd.d/$1" ]
87 echo "You must be root to run this option" >&2
90 # yes, /var/run is gross, but it is tmp directory cleaned up a boot,
91 # writable only by root (so i don't need to worry about the security
92 # implications of mktemp)
93 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
94 cp -f "/etc/xinetd.d/$1" $TMPFILE
97 sed 's/disable.*=.*/disable = no/g' < $TMPFILE > "/etc/xinetd.d/$1"
101 sed 's/disable.*=.*/disable = yes/g' < $TMPFILE > "/etc/xinetd.d/$1"
102 if [ "$1" == "nmbd" ]
105 kill -TERM $(cat /var/run/nmbd.pid) || echo >/dev
/null
110 echo "No such service command" >&2
113 elif [ -f "/System/Library/LaunchDaemons/$1.plist" ]
115 [ "$2" == start
] && launchctl load
-w /System
/Library
/LaunchDaemons
/$1.plist
116 [ "$2" == stop
] && launchctl unload
-w /System
/Library
/LaunchDaemons
/$1.plist
117 elif [ "$1" = "smtp" ]
121 echo "You must be root to run this option" >&2
124 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
125 cp -f /etc
/hostconfig
$TMPFILE
128 if grep -q MAILSERVER
=-NO- /etc
/hostconfig
; then
129 sed 's,^MAILSERVER=-NO-,MAILSERVER=-YES-,g' < $TMPFILE > /etc
/hostconfig
133 elif [ "$2" == stop
]
135 if grep -q MAILSERVER
=-YES- /etc
/hostconfig
; then
136 sed 's,^MAILSERVER=-YES-,MAILSERVER=-NO-,g' < $TMPFILE > /etc
/hostconfig
140 echo "No such service command" >&2
143 elif [ "$1" = "fax-receive" ]
147 echo "You must be root to run this option" >&2
150 TMPFILE
=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX)
151 cp -f /etc
/ttys
$TMPFILE
154 sed 's,^fax\(.*\)off$,fax\1on,g' < $TMPFILE > /etc
/ttys
156 elif [ "$2" == stop
]
158 sed 's,^fax\(.*\)on$,fax\1off,g' < $TMPFILE > /etc
/ttys
161 echo "No such service command" >&2
165 echo "No such service $1" >&2