-
Notifications
You must be signed in to change notification settings - Fork 102
/
service-bus.sh
executable file
·283 lines (244 loc) · 7.4 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# @@@LICENSE
#
# Copyright (c) 2010 - 2013 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 "$@"
}
check_fs_attribute() {
echo
echo "Checking filesystem attribute on ${LUNA_STAGING}"
varfs=`df ${LUNA_STAGING} | tail -1 | awk '{print $6}'`
echo " ${LUNA_STAGING} appears to be mounted on $varfs "
mountline=`cat /proc/mounts | grep -E "[[:graph:]]+[[:blank:]]+${varfs}[[:blank:]]+" | grep -v rootfs`
echo
echo "found it in /proc/mounts:"
echo " $mountline"
# returns something like: /dev/disk/by-uuid/f652a09b-f52a-4735-98b7-14da6c42ebd2 / ext3 rw,relatime,errors=remount-ro,data=ordered 0 0
mountedflags=`echo $mountline | awk '{print $4}'`
echo
echo "current attributes from /proc/mounts:"
echo " $mountedflags"
# returns something like: rw,relatime,errors=remount-ro,data=ordered
# or: defaults
if ! `echo $mountedflags | grep -qs user_xattr` ; then
echo
echo "user_xattr is NOT curently set!"
echo "without this attribute, FileCache and Email won't work properly."
echo "remount $varfs with extended attributes by typing:"
echo “sudo mount -o remount,user_xattr $varfs”
echo
sleep 1;
fi
echo
}
#########################################################
export SCRIPT_DIR=$PWD
source ./webos-desktop-common.sh
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"
USR_BIN_DIR="${STAGING_DIR}/usr/bin"
USR_SBIN_DIR="${STAGING_DIR}/usr/sbin"
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 LunaUniversalSearchMgr"
# 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="${BASE}/luna-sysmgr/desktop-support"
#LOGGING="--pmloglib"
DEB_BUILD_MULTIARCH=$(dpkg-architecture -qDEB_BUILD_MULTIARCH)
export LD_PRELOAD=/lib/${DEB_BUILD_MULTIARCH}/libSegFault.so
export LD_LIBRARY_PATH=${LIB_DIR}:${USR_LIB_DIR}:${LD_LIBRARY_PATH}
export PATH=${SERVICE_BIN_DIR}:${USR_BIN_DIR}:${USR_SBIN_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
check_fs_attribute
services_start
echo
;;
LunaSysService)
service_start LunaSysService ;;
filecache)
check_fs_attribute
service_start filecache ;;
activitymanager)
service_start activitymanager ;;
mojodb|mojodb-luna|db8)
service_start mojodb-luna -c /etc/palm/mojodb.conf /var/db
;;
LunaUniversalSearchMgr)
service_start LunaUniversalSearchMgr ;;
send)
luna-send "$@"
;;
init)
service_start filecache
service_start mojodb-luna -c /etc/palm/mojodb.conf /var/db
luna-send -n 1 palm://com.palm.configurator/run '{"types":["dbkinds","filecache"]}'
luna-send -n 1 palm://com.palm.configurator/run '{"types":["dbpermissions"]}'
service_start LunaSysService
service_start activitymanager
luna-send -n 1 palm://com.palm.service.accounts/createLocalAccount '{}'
sleep 2
luna-send -n 1 palm://com.palm.configurator/run '{"types":["activities"]}'
services_stop
;;
status)
hubds_status ;;
monitor)
hubd_monitor ;;
help)
usage ;;
*)
usage && false ;;
esac