]> git.saurik.com Git - apple/launchd.git/blame - rc/rc.common
launchd-842.92.1.tar.gz
[apple/launchd.git] / rc / rc.common
CommitLineData
e91b9f68
A
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
ed34e3c3
A
51alias ConsoleMessage=echo
52
e91b9f68
A
53##
54# Process management
55##
56GetPID ()
57{
58 local program="$1"
59 local pidfile="${PIDFILE:=/var/run/${program}.pid}"
60 local pid=""
61
62 if [ -f "${pidfile}" ]; then
63 pid=$(head -1 "${pidfile}")
64 if ! kill -0 "${pid}" 2> /dev/null; then
65 echo "Bad pid file $pidfile; deleting."
66 pid=""
67 rm -f "${pidfile}"
68 fi
69 fi
70
71 if [ -n "${pid}" ]; then
72 echo "${pid}"
73 return 0
74 else
75 return 1
76 fi
77}
78
79##
80# Generic action handler
81##
82RunService ()
83{
84 case $1 in
85 start ) StartService ;;
86 stop ) StopService ;;
87 restart) RestartService ;;
88 * ) echo "$0: unknown argument: $1";;
89 esac
90}
91
92##########################
93# Get host configuration #
94##########################
95. /etc/hostconfig