| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Start a systemtap server |
| 4 |
# |
| 5 |
# Copyright (C) 2008 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 stop a systemtap server with the |
| 13 |
# given pid. |
| 14 |
|
| 15 |
# Get the process id. |
| 16 |
pid=$1 |
| 17 |
if test "X$pid" = "X"; then |
| 18 |
echo "Usage: $0 PROCESS_ID" >&2 |
| 19 |
exit 1 |
| 20 |
fi |
| 21 |
|
| 22 |
# Verify that it is a systemtap server |
| 23 |
(ps -e | grep stap-serverd | grep -q $pid) |
| 24 |
if test $? != 0; then |
| 25 |
echo "$pid is not a systemtap server" >&2 |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
|
| 29 |
# Try to kill the server |
| 30 |
i=0 |
| 31 |
while kill -s SIGTERM $pid > /dev/null 2>&1; do |
| 32 |
sleep 0.5 |
| 33 |
|
| 34 |
# If we've tried and failed to kill the server for around 10 |
| 35 |
# seconds (20 * 0.5 seconds), quit. |
| 36 |
i=$((i + 1)) |
| 37 |
if test $i -ge 20; then |
| 38 |
echo "$pid not shutting down" >&2 |
| 39 |
exit 1 |
| 40 |
break |
| 41 |
fi |
| 42 |
done |