-
Notifications
You must be signed in to change notification settings - Fork 1
/
start-flowd
115 lines (96 loc) · 2.6 KB
/
start-flowd
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
#
# Synopsis:
# Boot a schema flowd server from either launchd, systemd or command-line
# Usage:
# start-flowd pdfbox
# start-flowd <schema>
# Note:
# Rename $SETSPACE_ROOT/schema/sbin/launchd-start-init to
# $SETSPACE_ROOT/schema/sbin/start-flowd-init
#
PROG=$(basename $0)
log()
{
if [ -n "$FLOW" ]; then
echo "$(date +'%Y/%m/%d %H:%M:%S'): $PROG: $FLOW: $@"
else
echo "$(date +'%Y/%m/%d %H:%M:%S'): $PROG: $@"
fi
}
die()
{
log "ERROR: $@" >&2
exit 2
}
leave()
{
log 'good bye, cruel world'
}
test $# = 1 || die "wrong number of arguments, got $#, expected 1"
SCHEMA=$1
FLOW=etc/$SCHEMA.flow
log 'hello, world'
trap leave EXIT
log "schema: $SCHEMA"
test -n "$SETSPACE_ROOT" || die "environment var not defined: SETSPACE_ROOT"
log "SETSPACE_ROOT=$SETSPACE_ROOT"
#
# source in global $SETSPACE_ROOT/etc/profile
#
PROFILE=$SETSPACE_ROOT/etc/profile
log "source: $PROFILE"
test -r $PROFILE || die "can not read setspace profile: $PROFILE"
. $PROFILE || die "sourcing setspace profile failed: $PROFILE"
SCHEMA_ROOT=$SETSPACE_ROOT/schema/$SCHEMA
log "schema root: $SCHEMA_ROOT"
test -d $SCHEMA_ROOT || die "schema root dir does not exist: $SCHEMA_ROOT"
cd $SCHEMA_ROOT || die "cd schema root failed: exit status=$?"
#
# source in schema specific profile
#
PROFILE=etc/profile
log "source: $PROFILE"
test -r $PROFILE || die "can not read schema profile: $(pwd)/$PROFILE"
. $PROFILE || die "sourcing schema profile failed: $PROFILE"
# set up gnu tools on the mac
WHICH_OS=$(uname -s)
log "operating system: $WHICH_OS"
# on mac we require gnutools from ports distro to be install
if [ "$WHICH_OS" = Darwin ]; then
log 'checking for gnu tools from mac ports ...'
test -d /opt/local/libexec/gnubin || die 'port gnubin not installed'
case "$PATH" in
*/gnubin*)
;;
*)
PATH=/opt/local/libexec/gnubin:/opt/local/bin:$PATH
;;
esac
fi
log "PATH=$PATH"
log "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
log 'clearing run/ directory of stale files ...'
find run -follow -type f -name 'flowd*' | while read ZAP_RUN; do
log "zap run/ file: $ZAP_RUN"
rm $ZAP_RUN
done
INITX=sbin/launchd-flowd-init
if [ -x $INITX ]; then
log "$INITX exists, so invoking ..."
$INITX || die "launchd-flow-init failed: exit status=$?"
fi
log "flow file: $FLOW"
if [ $PPID = 1 -o -n "$LAUNCHED_STARTED" -o -n "$INVOCATION_ID" ]; then
log 'dumping process environment ...'
env | sort | while read E; do
log "$E"
done
log 'started by launchd or systemd'
log 'execing flowd ...'
exec flowd server $FLOW
fi
log "invoked from script, so forking flowd into background"
flowd server $FLOW &
BG_PID=$!
log "bg process id: $BG_PID"