]> git.saurik.com Git - apple/launchd.git/blame_incremental - launchd/src/rc.common
launchd-106.13.tar.gz
[apple/launchd.git] / launchd / src / rc.common
... / ...
CommitLineData
1##
2# Common setup for startup scripts.
3##
4# Copyright 1998-2002 Apple Computer, Inc.
5##
6
7#######################
8# Configure the shell #
9#######################
10
11##
12# Be strict
13##
14#set -e
15set -u
16
17##
18# Set command search path
19##
20PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices; export PATH
21
22##
23# Set the terminal mode
24##
25#if [ -x /usr/bin/tset ] && [ -f /usr/share/misc/termcap ]; then
26# TERM=$(tset - -Q); export TERM
27#fi
28
29####################
30# Useful functions #
31####################
32
33##
34# Determine if the network is up by looking for any non-loopback
35# internet network interfaces.
36##
37CheckForNetwork()
38{
39 local test
40
41 if [ -z "${NETWORKUP:=}" ]; then
42 test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l)
43 if [ "${test}" -gt 0 ]; then
44 NETWORKUP="-YES-"
45 else
46 NETWORKUP="-NO-"
47 fi
48 fi
49}
50
51##
52# Process management
53##
54GetPID ()
55{
56 local program="$1"
57 local pidfile="${PIDFILE:=/var/run/${program}.pid}"
58 local pid=""
59
60 if [ -f "${pidfile}" ]; then
61 pid=$(head -1 "${pidfile}")
62 if ! kill -0 "${pid}" 2> /dev/null; then
63 echo "Bad pid file $pidfile; deleting."
64 pid=""
65 rm -f "${pidfile}"
66 fi
67 fi
68
69 if [ -n "${pid}" ]; then
70 echo "${pid}"
71 return 0
72 else
73 return 1
74 fi
75}
76
77##
78# Generic action handler
79##
80RunService ()
81{
82 case $1 in
83 start ) StartService ;;
84 stop ) StopService ;;
85 restart) RestartService ;;
86 * ) echo "$0: unknown argument: $1";;
87 esac
88}
89
90##########################
91# Get host configuration #
92##########################
93. /etc/hostconfig