forked from openwebos/build-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-bus.sh
executable file
·235 lines (204 loc) · 5.87 KB
/
service-bus.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/sh
# @@@LICENSE
#
# Copyright (c) 2010 - 2012 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# LICENSE@@@
#set -x
usage() {
cat <<-EOF
Starts or stops local (ls2) ls-hubd sessions
Usage: ${0} [--help] [command] [args...]
Options:
--help Show this help message
Commands:
start Starts the pub/priv ls-hubd instances
services Starts the static native services
(LunaSysService, filecache, activitymanager, mojodb-luna)
(services can also be started individually by name)
init Perform first-time initialization (db and local account)
send Sends a service bus request (using luna-send)
stop Stops currently running ls-hubd and services
status Displays status of pub/priv ls-hubd instances
monitor [...] Invokes ls-monitor
EOF
echo
# log [public] Show ls-hubd output (default=private)
# add <svc1> [<svc2> ...] Register one or more ls2 services
# remove <svc1> [<svc2> ...] Unregister one or more ls2 services
# purge Unregister all ls2 services
# dir <svcsDir> Register all ls2 services in <svcsDir>
# list Lists all registered ls2 services
}
get_pidfile() {
echo "/tmp/webos/ls2/ls-hubd.${1}.pid"
}
hubd_status() {
if [ -e "`get_pidfile ${1}`" ] ; then
echo "${1} hubd is running."
else
echo "${1} hubd is NOT running."
fi
}
hubds_status() {
hubd_status public
hubd_status private
}
hubd_stop() {
PID_FILE="/tmp/webos/ls2/ls-hubd.${1}.pid"
if [ -e "${PID_FILE}" ] ; then
echo "Stopping ${1} hub daemon"
kill -9 `cat ${PID_FILE}`
rm ${PID_FILE}
fi
}
hubds_stop() {
hubd_stop public
hubd_stop private
}
hubds_start() {
ls-hubd --conf ${CONF_DIR}/ls2/ls-private.conf ${LOGGING} 2>&1 &
ls-hubd --public --conf ${CONF_DIR}/ls2/ls-public.conf ${LOGGING} 2>&1 &
sleep 1
echo
echo "hub daemons started!"
echo "(Type: '${0} stop' to stop hub daemons.)"
}
services_stop() {
echo
for SERVICE in ${STATIC_SERVICES} ; do
killall ${SERVICE} && echo "Killed ${SERVICE}"
done
killall mojomail-imap && echo "Killed ${SERVICE}"
killall mojomail-pop && echo "Killed ${SERVICE}"
killall mojomail-smtp && echo "Killed ${SERVICE}"
}
service_start() {
SERVICE=${1}
shift
if [ -x ${SERVICE_BIN_DIR}/${SERVICE} ] ; then
echo
echo "Starting service: ${SERVICE} ..."
${SERVICE_BIN_DIR}/${SERVICE} "$@" &
sleep 1
else
echo
echo "ERROR: ${SERVICE} not present in ${SERVICE_BIN_DIR}"
echo
exit 1
fi
}
services_start() {
for SERVICE in ${STATIC_SERVICES} ; do
case "${SERVICE}" in
mojodb-luna)
service_start mojodb-luna -c /etc/palm/mojodb.conf /var/db
;;
*)
service_start ${SERVICE}
;;
esac
done
sleep 1
echo
echo "Services started!"
echo "(Type: '${0} stop' to stop services and hub daemons.)"
}
hubd_monitor() {
ls-monitor "$@"
}
#########################################################
BASE="${HOME}/luna-desktop-binaries"
ROOTFS="${BASE}/rootfs"
LUNA_STAGING="${BASE}/staging"
STAGING_DIR="${LUNA_STAGING}"
BIN_DIR="${STAGING_DIR}/bin"
LIB_DIR="${STAGING_DIR}/lib"
USR_LIB_DIR="${STAGING_DIR}/usr/lib"
ETC_DIR="${STAGING_DIR}/etc"
# NOTE: this links to ROOTFS/usr/lib/luna which is what the role and service files refer to
SERVICE_BIN_DIR="/usr/lib/luna"
STATIC_SERVICES="LunaSysService filecache activitymanager mojodb-luna luna-universalsearchmgr"
# TODO: Consider moving ls2 dir to traditional locations (requires changes to scripts AND .conf files)
CONF_DIR="${ROOTFS}/etc"
mkdir -p ${ROOTFS}/etc/ls2
if [ ! -f "${ROOTFS}/etc/ls2/ls-private.conf" ] || grep -qs dbus ${ROOTFS}/etc/ls2/ls-private.conf ; then
cp -f ls2/ls-private.conf ${ROOTFS}/etc/ls2
fi
if [ ! -f "${ROOTFS}/etc/ls2/ls-public.conf" ] || grep -qs dbus ${ROOTFS}/etc/ls2/ls-public.conf ; then
cp -f ls2/ls-public.conf ${ROOTFS}/etc/ls2
fi
SRC_DIR="${HOME}/luna-desktop-binaries/luna-sysmgr/desktop-support"
#LOGGING="--pmloglib"
export LD_PRELOAD=/lib/i386-linux-gnu/libSegFault.so
export LD_LIBRARY_PATH=${LIB_DIR}:${USR_LIB_DIR}:${LD_LIBRARY_PATH}
export PATH=${SERVICE_BIN_DIR}:${BIN_DIR}:${PATH}
CMD="$1"
if [ -z "$CMD" ]; then
CMD=help
else
shift
fi
echo
case "$CMD" in
start)
echo "Halting old services..."
services_stop
hubds_stop
hubds_start
echo
;;
stop)
echo "Halting services..."
services_stop
echo
hubds_stop
echo
;;
services)
echo "Halting old services..."
services_stop
echo
services_start
echo
;;
LunaSysService)
service_start LunaSysService ;;
filecache)
service_start filecache ;;
activitymanager)
service_start activitymanager ;;
mojodb|mojodb-luna|db8)
service_start mojodb-luna -c /etc/palm/mojodb.conf /var/db
;;
luna-universalsearchmgr)
service_start luna-universalsearchmgr ;;
send)
luna-send "$@"
;;
init)
luna-send -n 1 palm://com.palm.configurator/run '{"types":["dbkinds","filecache"]}'
luna-send -n 1 palm://com.palm.configurator/run '{"types":["dbpermissions"]}'
luna-send -n 1 palm://com.palm.service.accounts/createLocalAccount '{}'
;;
status)
hubds_status ;;
monitor)
hubd_monitor ;;
help)
usage ;;
*)
usage && false ;;
esac