| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Start a systemtap server |
| 4 |
# |
| 5 |
# Copyright (C) 2008-2011 Red Hat Inc. |
| 6 |
# |
| 7 |
# This file is part of systemtap, and is free software. You can |
| 8 |
# redistribute it and/or modify it under the terms of the GNU General |
| 9 |
# Public License (GPL); either version 2, or (at your option) any |
| 10 |
# later version. |
| 11 |
|
| 12 |
# This script attempts to start a systemtap server and echoes the |
| 13 |
# process id, if successful. |
| 14 |
|
| 15 |
# Initialize the environment |
| 16 |
. ${PKGLIBEXECDIR}stap-env |
| 17 |
|
| 18 |
startup_timeout=10 |
| 19 |
|
| 20 |
# start the server |
| 21 |
cd / # change to a dir we're 100% sure we have RD_ONLY access to |
| 22 |
${stap_pkglibexecdir}stap-serverd "$@" </dev/null >/dev/null 2>/dev/null & |
| 23 |
server_pid=$! |
| 24 |
|
| 25 |
# Make sure the server is started |
| 26 |
for ((attempt=0; $attempt < $startup_timeout; ++attempt)) |
| 27 |
do |
| 28 |
# Has the server started? |
| 29 |
if ! (ps -e | grep stap-serverd | grep $server_pid) >/dev/null 2>&1; then |
| 30 |
sleep 1 |
| 31 |
continue |
| 32 |
fi |
| 33 |
|
| 34 |
# The server is ready |
| 35 |
echo $server_pid |
| 36 |
exit 0 |
| 37 |
done |
| 38 |
|
| 39 |
echo -n "Unable to start a systemtap server: " >&2 |
| 40 |
echo "${stap_pkglibexecdir}stap-serverd did not start" >&2 |
| 41 |
|
| 42 |
exit 1 # server did not start |