summaryrefslogtreecommitdiffstats
path: root/initscript/stap-server.in
blob: ccd527191cfb30bc754f5ad42e32eafe0cba6433 (plain)
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
#!/bin/bash
#
# stap-server	init.d script for the systemtap compile server
#
# chkconfig: - 00 99
# description: The systemtap compile server provides a centralized and secure environment for compiling systemtap scripts.
# config: /etc/stap-server/config
# config: /etc/stap-server/conf.d
### BEGIN INIT INFO
# Provides: Systemtap compile server management
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Short-Description: Manage systemtap compile servers
# Description: The systemtap compile server provides a centralized and secure environment for compiling systemtap scripts.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

prog=stap-server

# Commands
STAP_START_SERVER=@bindir@/stap-start-server
STAP_STOP_SERVER=@bindir@/stap-stop-server
UNAME=/bin/uname

# Path setup
CONFIG_PATH=/etc/stap-server/conf.d
STAT_PATH=/var/run/stap-server
TEMP_PATH=/tmp
LOG_FILE=/var/log/stap-server.log

# Default option settings

CONFIG=/etc/stap-server/config

echo_usage () {
  echo $"Usage: $prog {start|stop|restart|status|cleanup} [option]"
  echo $"Options:"
  echo $"	-c configfile	: specify config file"
}

#-----------------------------------------------------------------
# Helper functions
#-----------------------------------------------------------------
log () { # message
  echo `LC_ALL=en date +"%b %e %T"`": $1" >> "$LOG_FILE"
}
clog () { # message [-n]
  echo $2 "$1"
  log "$1"
}
slog () { # message
  logger "$1" # if syslogd is running, this message will be sent to syslog.
  log "$1"
}
logex () { # command
  eval log \"Exec: $@\"
  "$@" >> "$LOG_FILE" 2>&1
  return $?
}
do_warning () { # message
  slog "Warning: $1"
  warning "$1"
}
do_failure () { # message
  slog "Error: $1"
  failure "$1"
}
do_success () { # message
  log "Pass: $1"
  success "$1"
}
# Normalize options
check_bool () { # value
  case $1 in
  n|N|no|No|NO|0)
  return 0;;
  y|Y|yes|Yes|YES|1)
  return 1;;
  *)
  return 2;;
  esac
}
ask_yesno () { # message
  local yn ret=2
  [ "$OPT_ASSUMEYES" ] && return 1
  while [ $ret -eq 2 ]; do
    echo -n "$1 [y/N]: "
    read yn
    [ -z "$yn" ] && return 0
    check_bool $yn
    ret=$?
  done
  return $ret
}

#------------------------------------------------------------------
# Parameter parsing and setup options
#------------------------------------------------------------------
parse_args () { # arguments
  local error=0
  while [ -n "$1" ]; do
    case "$1" in
      -c)
        CONFIG=$2
        shift 1
        ;;
      *)
	error=1
        ;;
    esac
    shift 1
  done
  test error=1 && echo_usage
}

CMD=$1
shift 1
OPTS=`getopt -s bash -u -o 'c:Ry' $@`
if [ $? -ne 0 ]; then
  slog "Error: Argument parse error: $@"
  failure $"parse error"
  echo_usage
  exit 3
fi
parse_args $OPTS

# Include configs
. "$CONFIG"

for f in "$CONFIG_PATH"/*.conf; do
  if [ -f "$f" ]; then
    . "$f"
  fi
done

prepare_stat_dir () {
  if [ ! -d "$STAT_PATH" ]; then
    logex mkdir -p "$STAT_PATH"
    [ $? -ne 0 ] && return 1
  fi
  return 0
}

start () {
  clog $"Starting $prog: " -n

  prepare_stat_dir
  if [ $? -ne 0 ]; then
    do_failure $"Failed to make stat directory ($STAT_PATH)"
    return 1
  fi

  # Start the server here
  do_failure $"$prog start not implemented"

  do_success $"$prog start"
  return 0
}

stop () {
  clog $"Stopping $prog: " -n

  # Stop the server here
  do_failure $"$prog stop not implemented"

  do_success $"$prog stop"
  return 0
}

status () {
  # Print the status here
  do_failure $"$prog status not implemented"

  do_success $"$prog status"
  return 0
}

# Cleanup caches
cleanup () {
  clog $"Stopping systemtap compile servers: " -n

  # Clean up the server(s) here
  do_failure $"$prog cleanup not implemented"

  do_success $"$prog cleanup"
  return 0
}

# Restart scripts
function restart () {
  # Restart the server(s) here
  do_failure $"$prog restart not implemented"

  do_success $"$prog restart"
  return 0
}

RETVAL=0

case $CMD in
  start)
  start
  RETVAL=$?
  ;;
  stop)
  stop
  RETVAL=$?
  ;;
  restart)
  restart
  RETVAL=$?
  ;;
  status)
  status
  exit $?
  ;;
  cleanup)
  cleanup
  RETVAL=$?
  ;;
  *)
  echo_usage
  RETVAL=3
  ;;
esac

echo
exit $RETVAL