-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchd-log
executable file
·72 lines (61 loc) · 1.45 KB
/
launchd-log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#
# Synopsis:
# Script to help poor logging of launchd and missing docs for SIP.
# Usage:
# cd /usr/local/blobio
#
# # source in optional config script
# echo 'ulimit -n 2048' >>etc/launch-log.conf
#
# launchd-log bin/flowd server etc/blobio.flow
#
# Exit Status:
# * exit status of launched process
# 127 unexpected error in launchd-log
# Note:
# Why put launched-log in $JMSCOTT_ROOT/sbin?
# Seems like /bin/ better for permissons, since typically /sbin/
# is only owned by a particular user.
#
# Consider renaming script to launchd-helper.
#
PROG=$(basename $0)
log()
{
echo "$(date +'%Y/%m/%d %H:%M:%S'): $@"
}
die()
{
log "ERROR: $@" >&1
exit 127
}
test $# -gt 0 || die 'wrong number of arguments, expected > 0'
PROG="$PROG: $(basename $1)"
log "hello, world"
trap 'log good bye, cruel world' EXIT TERM INT QUIT
CWD=$(pwd) # for security issue in new mac os
STATUS=$?
test $STATUS = 0 || die "cwd failed: exit status=$STATUS"
test -n "$CWD" || die 'empty output from pwd command'
log "working directory: $CWD"
CONF=etc/launchd-log.conf
log "launchd config: $CONF"
if [ -r $CONF ]; then
log "sourcing config file ..."
. $CONF || exit
else
log 'no config (ok)'
fi
log 'dump of process environment ...'
env | while read LINE; do
log "$LINE"
done
log "executing: $@"
$@ 2>&1 | while read LINE; do
log $LINE
done
STATUS=${PIPESTATUS[*]}
log "process exited with status: $STATUS"
STATUS=$(echo $STATUS | awk '{print $1}')
exit $STATUS