k2hr3-api 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/ChangeLog +24 -0
  2. package/app.js +7 -4
  3. package/bin/run.sh +218 -172
  4. package/bin/watcher +7 -4
  5. package/bin/www +7 -4
  6. package/config/default.json +7 -4
  7. package/config/development.json +7 -4
  8. package/config/dummyuser.json +8 -5
  9. package/config/extdata-dummy.sh.templ +12 -9
  10. package/config/k2hr3-cloud-config.txt.templ +7 -4
  11. package/config/k2hr3-init-error.sh.templ +8 -5
  12. package/config/k2hr3-init.sh.templ +127 -207
  13. package/config/keystone_v2.json +7 -4
  14. package/config/keystone_v3.json +7 -4
  15. package/lib/basicipcheck.js +7 -4
  16. package/lib/cacerts.js +7 -4
  17. package/lib/dbglogging.js +7 -4
  18. package/lib/dummyuserapi.js +7 -4
  19. package/lib/ipwatch.js +7 -4
  20. package/lib/k2hr3acrutil.js +7 -5
  21. package/lib/k2hr3apiutil.js +7 -4
  22. package/lib/k2hr3cliutil.js +7 -4
  23. package/lib/k2hr3config.js +7 -4
  24. package/lib/k2hr3cryptutil.js +7 -4
  25. package/lib/k2hr3dkc.js +7 -4
  26. package/lib/k2hr3extdata.js +7 -4
  27. package/lib/k2hr3keys.js +7 -4
  28. package/lib/k2hr3resutil.js +7 -4
  29. package/lib/k2hr3template.js +7 -4
  30. package/lib/k2hr3tokens.js +7 -4
  31. package/lib/k2hr3userdata.js +8 -5
  32. package/lib/k8soidc.js +1 -1
  33. package/lib/openstackapiv2.js +7 -4
  34. package/lib/openstackapiv3.js +7 -4
  35. package/lib/openstackep.js +7 -4
  36. package/package.json +73 -72
  37. package/routes/acr.js +7 -4
  38. package/routes/debugVerify.js +7 -4
  39. package/routes/extdata.js +7 -4
  40. package/routes/list.js +7 -4
  41. package/routes/policy.js +7 -4
  42. package/routes/resource.js +7 -4
  43. package/routes/role.js +7 -4
  44. package/routes/service.js +7 -4
  45. package/routes/userTokens.js +7 -4
  46. package/routes/userdata.js +7 -4
  47. package/routes/version.js +7 -4
  48. package/templ/Dockerfile.templ +35 -52
  49. package/{test → tests}/auto_acr.js +7 -4
  50. package/{test → tests}/auto_acr_spec.js +7 -4
  51. package/{test → tests}/auto_all_spec.js +7 -4
  52. package/{test → tests}/auto_common.js +7 -4
  53. package/tests/auto_control_subprocess.sh +239 -0
  54. package/{test → tests}/auto_extdata.js +7 -4
  55. package/{test → tests}/auto_extdata_spec.js +7 -4
  56. package/tests/auto_init_config_json.sh +275 -0
  57. package/{test → tests}/auto_k2hdkc_server.ini +7 -4
  58. package/{test → tests}/auto_k2hdkc_slave.ini +7 -4
  59. package/{test → tests}/auto_list.js +7 -4
  60. package/{test → tests}/auto_list_spec.js +7 -4
  61. package/{test → tests}/auto_policy.js +7 -4
  62. package/{test → tests}/auto_policy_spec.js +7 -4
  63. package/{test → tests}/auto_resource.js +7 -4
  64. package/{test → tests}/auto_resource_spec.js +7 -4
  65. package/{test → tests}/auto_role.js +7 -4
  66. package/{test → tests}/auto_role_spec.js +7 -4
  67. package/{test → tests}/auto_service.js +7 -4
  68. package/{test → tests}/auto_service_spec.js +7 -4
  69. package/{test → tests}/auto_subprocesses.js +14 -11
  70. package/tests/auto_template.sh +126 -0
  71. package/{test → tests}/auto_token_util.js +7 -4
  72. package/{test → tests}/auto_userdata.js +7 -4
  73. package/{test → tests}/auto_userdata_spec.js +7 -4
  74. package/{test → tests}/auto_usertokens.js +7 -4
  75. package/{test → tests}/auto_usertokens_spec.js +7 -4
  76. package/{test → tests}/auto_version.js +7 -4
  77. package/{test → tests}/auto_version_spec.js +7 -4
  78. package/{test → tests}/auto_watcher.js +7 -4
  79. package/{test → tests}/auto_watcher_spec.js +7 -4
  80. package/{test → tests}/k2hdkc_test.data +7 -4
  81. package/tests/k2hdkc_test_load.sh +255 -0
  82. package/{test → tests}/k2hr3template_test.js +7 -4
  83. package/tests/k2hr3template_test.sh +339 -0
  84. package/{test → tests}/k2hr3template_test_async.js +7 -4
  85. package/{test → tests}/k2hr3template_test_template.result +14 -8
  86. package/{test → tests}/k2hr3template_test_template.txt +7 -4
  87. package/{test → tests}/k2hr3template_test_vars.js +7 -4
  88. package/{test → tests}/manual_acr_delete.js +7 -4
  89. package/{test → tests}/manual_acr_get.js +7 -4
  90. package/{test → tests}/manual_acr_postput.js +7 -4
  91. package/{test → tests}/manual_allusertenant_get.js +7 -4
  92. package/{test → tests}/manual_extdata_get.js +7 -4
  93. package/{test → tests}/manual_k2hr3keys_get.js +7 -4
  94. package/{test → tests}/manual_list_gethead.js +7 -4
  95. package/{test → tests}/manual_policy_delete.js +7 -4
  96. package/{test → tests}/manual_policy_gethead.js +7 -4
  97. package/{test → tests}/manual_policy_postput.js +7 -4
  98. package/{test → tests}/manual_resource_delete.js +7 -4
  99. package/{test → tests}/manual_resource_gethead.js +7 -4
  100. package/{test → tests}/manual_resource_postput.js +7 -4
  101. package/{test → tests}/manual_role_delete.js +7 -4
  102. package/{test → tests}/manual_role_gethead.js +7 -4
  103. package/{test → tests}/manual_role_postput.js +7 -4
  104. package/{test → tests}/manual_service_delete.js +7 -4
  105. package/{test → tests}/manual_service_gethead.js +7 -4
  106. package/{test → tests}/manual_service_postput.js +7 -4
  107. package/tests/manual_test.sh +338 -0
  108. package/{test → tests}/manual_userdata_get.js +7 -4
  109. package/{test → tests}/manual_usertoken_gethead.js +7 -4
  110. package/{test → tests}/manual_usertoken_postput.js +7 -4
  111. package/{test → tests}/manual_version_get.js +7 -4
  112. package/tests/run_local_test_k2hdkc.sh +174 -0
  113. package/tests/test.sh +331 -0
  114. package/test/auto_control_subprocess.sh +0 -170
  115. package/test/auto_init_config_json.sh +0 -246
  116. package/test/auto_template.sh +0 -127
  117. package/test/auto_test.sh +0 -321
  118. package/test/k2hdkc_test_load.sh +0 -198
  119. package/test/k2hr3template_test.sh +0 -296
  120. package/test/manual_test.sh +0 -321
  121. package/test/run_local_test_k2hdkc.sh +0 -154
package/tests/test.sh ADDED
@@ -0,0 +1,331 @@
1
+ #!/bin/sh
2
+ #
3
+ # K2HR3 REST API
4
+ #
5
+ # Copyright 2017 Yahoo Japan Corporation.
6
+ #
7
+ # K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
8
+ # common management information for the cloud.
9
+ # K2HR3 can dynamically manage information as "who", "what", "operate".
10
+ # These are stored as roles, resources, policies in K2hdkc, and the
11
+ # client system can dynamically read and modify these information.
12
+ #
13
+ # For the full copyright and license information, please view
14
+ # the license file that was distributed with this source code.
15
+ #
16
+ # AUTHOR: Takeshi Nakatani
17
+ # CREATE: Tue Dec 26 2017
18
+ # REVISION:
19
+ #
20
+
21
+ #==========================================================
22
+ # Common Variables
23
+ #==========================================================
24
+ PRGNAME=$(basename "$0")
25
+ SCRIPTDIR=$(dirname "$0")
26
+ SCRIPTDIR=$(cd "${SCRIPTDIR}" || exit 1; pwd)
27
+ SRCTOP=$(cd "${SCRIPTDIR}/.." || exit 1; pwd)
28
+
29
+ #
30
+ # Variables
31
+ #
32
+ COMMAND=""
33
+ CMD_PREFIX="auto_"
34
+ CMD_SUFFIX="_spec.js"
35
+ AUTO_INIT_SH="tests/auto_init_config_json.sh"
36
+
37
+ #
38
+ # Commands
39
+ #
40
+ COMMANDS="
41
+ all
42
+ version
43
+ list
44
+ usertokens
45
+ resource
46
+ policy
47
+ role
48
+ service
49
+ acr
50
+ userdata
51
+ extdata
52
+ watcher
53
+ "
54
+
55
+ #==============================================================
56
+ # Utility functions
57
+ #==============================================================
58
+ #
59
+ # Usage
60
+ #
61
+ PrintUsage()
62
+ {
63
+ echo "Usage: $1 [--production(-prod) | --development(-dev)]"
64
+ echo " [--logger(-l)]"
65
+ echo " [--timeout <ms>]"
66
+ echo " [--debuglevel(-d) DBG/MSG/WARN/ERR/(custom debug level)]"
67
+ echo " Command"
68
+ echo ""
69
+ echo "Option:"
70
+ echo " --production(-prod) : Set 'production' to NODE_ENV environment (exclusive with the '--development' option)"
71
+ echo " --development(-dev) : Set 'development' to NODE_ENV environment (this is default and exclusive with the '--production' option)"
72
+ echo " --logger(-l) : Specify when logging by morgan (this can be substituted by setting the 'NODE_LOGGER' environment variable to 'yes' or 'no')"
73
+ echo " --timeout(-t) : Specify the mocha timeout in milliseconds mocha sets a timeout of 2000ms by default,"
74
+ echo " but this test script currently sets it to 2000ms. This option can be used to change the timeout value."
75
+ echo " --debuglevel(-d) : Specify the level of debug output (DBG/MSG/WARN/ERR/custom debug level)"
76
+ echo ""
77
+ echo "Command:"
78
+ echo " all : All API test"
79
+ echo " version : Version API test"
80
+ echo " list : List API test"
81
+ echo " usertokens : User Token API test"
82
+ echo " resource : Resource API test"
83
+ echo " policy : Policy API test"
84
+ echo " role : Role API test"
85
+ echo " service : Service API test"
86
+ echo " acr : Accessing Cross Role(ACR) API test"
87
+ echo " userdata : Get userdata for openstack API test"
88
+ echo " extdata : Get extdata for user defined data"
89
+ echo " watcher : Watcher sub process test"
90
+ echo ""
91
+ }
92
+
93
+ #
94
+ # Check Commands
95
+ #
96
+ CheckCommands()
97
+ {
98
+ if [ -n "$1" ]; then
99
+ for command in ${COMMANDS}; do
100
+ if [ "$1" = "${command}" ]; then
101
+ echo "${command}"
102
+ return 0
103
+ fi
104
+ done
105
+ fi
106
+ echo ""
107
+ return 1
108
+ }
109
+
110
+ #==========================================================
111
+ # Parse options
112
+ #==========================================================
113
+ NODE_ENV_VALUE=""
114
+ IS_LOGGING=0
115
+ TIMEOUT=""
116
+ DEBUG_ENV_LEVEL=0
117
+ DEBUG_ENV_CUSTOM=""
118
+
119
+ while [ $# -ne 0 ]; do
120
+ if [ -z "$1" ]; then
121
+ break
122
+
123
+ elif [ "$1" = "-h" ] || [ "$1" = "-H" ] || [ "$1" = "--help" ] || [ "$1" = "--HELP" ]; then
124
+ PrintUsage "${PRGNAME}"
125
+ exit 0
126
+
127
+ elif [ "$1" = "-prod" ] || [ "$1" = "-PROD" ] || [ "$1" = "--production" ] || [ "$1" = "--PRODUCTION" ]; then
128
+ if [ -n "${NODE_ENV_VALUE}" ]; then
129
+ echo "[ERROR] already specified --production(-prod) or --development(-dev) option"
130
+ exit 1
131
+ fi
132
+ NODE_ENV_VALUE="production"
133
+
134
+ elif [ "$1" = "-dev" ] || [ "$1" = "-DEV" ] || [ "$1" = "--development" ] || [ "$1" = "--DEVELOPMENT" ]; then
135
+ if [ "${NODE_ENV_VALUE}" != "" ]; then
136
+ echo "[ERROR] already specified --production(-prod) or --development(-dev) option"
137
+ exit 1
138
+ fi
139
+ NODE_ENV_VALUE="development"
140
+
141
+ elif [ "$1" = "-l" ] || [ "$1" = "-L" ] || [ "$1" = "--logger" ] || [ "$1" = "--LOGGER" ]; then
142
+ if [ "${IS_LOGGING}" -eq 1 ]; then
143
+ echo "[ERROR] Already --logger(-l) option is set"
144
+ exit 1
145
+ fi
146
+ IS_LOGGING=1
147
+
148
+ elif [ "$1" = "-d" ] || [ "$1" = "-D" ] || [ "$1" = "--debuglevel" ] || [ "$1" = "--DEBUGLEVEL" ]; then
149
+ #
150
+ # DEBUG option
151
+ #
152
+ shift
153
+ if [ $# -eq 0 ]; then
154
+ echo "[ERROR] --debuglevel(-d) option needs parameter(dbg/msg/warn/err/custom debug level)"
155
+ exit 1
156
+ fi
157
+ if [ "$1" = "dbg" ] || [ "$1" = "DBG" ] || [ "$1" = "debug" ] || [ "$1" = "DEBUG" ]; then
158
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
159
+ echo "[ERROR] --debuglevel(-d) option already is set"
160
+ exit 1
161
+ fi
162
+ DEBUG_ENV_LEVEL=4
163
+ elif [ "$1" = "msg" ] || [ "$1" = "MSG" ] || [ "$1" = "message" ] || [ "$1" = "MESSAGE" ] || [ "$1" = "info" ] || [ "$1" = "INFO" ]; then
164
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
165
+ echo "[ERROR] --debuglevel(-d) option already is set"
166
+ exit 1
167
+ fi
168
+ DEBUG_ENV_LEVEL=3
169
+ elif [ "$1" = "warn" ] || [ "$1" = "WARN" ] || [ "$1" = "warning" ] || [ "$1" = "WARNING" ]; then
170
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
171
+ echo "[ERROR] --debuglevel(-d) option already is set"
172
+ exit 1
173
+ fi
174
+ DEBUG_ENV_LEVEL=2
175
+ elif [ "$1" = "err" ] || [ "$1" = "ERR" ] || [ "$1" = "error" ] || [ "$1" = "ERROR" ]; then
176
+ if [ "${DEBUG_ENV_LEVEL}" -ne 0 ]; then
177
+ echo "[ERROR] --debuglevel(-d) option already is set"
178
+ exit 1
179
+ fi
180
+ DEBUG_ENV_LEVEL=1
181
+ else
182
+ #
183
+ # Custom debug level value
184
+ #
185
+ if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
186
+ DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM},"
187
+ fi
188
+ DEBUG_ENV_CUSTOM="${DEBUG_ENV_CUSTOM}$1"
189
+ fi
190
+
191
+ elif [ "$1" = "-t" ] || [ "$1" = "-T" ] || [ "$1" = "--timeout" ] || [ "$1" = "--TIMEOUT" ]; then
192
+ #
193
+ # timeout option
194
+ #
195
+ if [ -n "${TIMEOUT}" ]; then
196
+ echo "[ERROR] Already --timeout(-t) option is set"
197
+ exit 1
198
+ fi
199
+ shift
200
+ if [ $# -eq 0 ]; then
201
+ echo "[ERROR] --timeout(-t) option needs parameter(millisecond)"
202
+ exit 1
203
+ fi
204
+ # check number value
205
+ if echo "$1" | grep -q '[^0-9]'; then
206
+ echo "[ERROR] --timeout(-t) option parameter must be number(millisecond)"
207
+ exit 1
208
+ fi
209
+ TIMEOUT="$1"
210
+
211
+ else
212
+ #
213
+ # Run test command
214
+ #
215
+ if [ -n "${COMMAND}" ]; then
216
+ echo "[ERROR] Already specified command name(${COMMAND}), could not specify multi command $1"
217
+ exit 1
218
+ fi
219
+ if ! COMMAND=$(CheckCommands "$1"); then
220
+ echo "[ERROR] $1 is not command name"
221
+ exit 1
222
+ fi
223
+ fi
224
+ shift
225
+ done
226
+
227
+ #
228
+ # Check Command
229
+ #
230
+ if [ -z "${COMMAND}" ]; then
231
+ echo "[ERROR] Command name is not specified"
232
+ exit 1
233
+ fi
234
+
235
+ #
236
+ # Check timeout
237
+ #
238
+ if [ -z "${TIMEOUT}" ]; then
239
+ TIMEOUT="3000"
240
+ fi
241
+
242
+ #
243
+ # Check NODE_ENV_VALUE
244
+ #
245
+ if [ -z "${NODE_ENV_VALUE}" ]; then
246
+ NODE_ENV_VALUE="development"
247
+ fi
248
+
249
+ #
250
+ # Make NODE_DEBUG environment
251
+ #
252
+ DEBUG_ENV_PARAM=""
253
+ if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
254
+ DEBUG_ENV_PARAM="LOGLEVEL_DBG"
255
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 3 ]; then
256
+ DEBUG_ENV_PARAM="LOGLEVEL_MSG"
257
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 2 ]; then
258
+ DEBUG_ENV_PARAM="LOGLEVEL_WAN"
259
+ elif [ "${DEBUG_ENV_LEVEL}" -ge 1 ]; then
260
+ DEBUG_ENV_PARAM="LOGLEVEL_ERR"
261
+ else
262
+ DEBUG_ENV_PARAM="LOGLEVEL_SILENT"
263
+ fi
264
+ if [ -n "${DEBUG_ENV_CUSTOM}" ]; then
265
+ if [ -n "${DEBUG_ENV_PARAM}" ]; then
266
+ DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM},"
267
+ fi
268
+ DEBUG_ENV_PARAM="${DEBUG_ENV_PARAM}${DEBUG_ENV_CUSTOM}"
269
+ fi
270
+
271
+ #
272
+ # Logging for NODE_LOGGER
273
+ #
274
+ if [ "${IS_LOGGING}" -eq 1 ]; then
275
+ NODE_LOGGER=""
276
+ else
277
+ if [ -z "${NODE_LOGGER}" ]; then
278
+ #
279
+ # Nothing to do for default
280
+ #
281
+ :
282
+ elif [ "${NODE_LOGGER}" = "yes" ] || [ "${NODE_LOGGER}" = "YES" ]; then
283
+ NODE_LOGGER=""
284
+ elif [ "${NODE_LOGGER}" = "no" ] || [ "${NODE_LOGGER}" = "NO" ]; then
285
+ NODE_LOGGER="no"
286
+ else
287
+ echo "[WARNING] NODE_LOGGER environment has wrong value(${NODE_LOGGER}), then do logging(default)"
288
+ NODE_LOGGER=""
289
+ fi
290
+ fi
291
+
292
+ #==========================================================
293
+ # Do work
294
+ #==========================================================
295
+ cd "${SRCTOP}" || exit 1
296
+
297
+ if [ "${DEBUG_ENV_LEVEL}" -ge 4 ]; then
298
+ echo "***** RUN *****"
299
+ echo "${AUTO_INIT_SH} --set"
300
+ echo "NODE_PATH=${NODE_PATH} NODE_ENV=${NODE_ENV_VALUE} NODE_DEBUG=${DEBUG_ENV_PARAM} NODE_LOGGER=${NODE_LOGGER} NODE_CONFIG_DIR= node_modules/.bin/mocha tests/${CMD_PREFIX}${COMMAND}${CMD_SUFFIX}"
301
+ echo "***************"
302
+ fi
303
+
304
+ if ! "${AUTO_INIT_SH}" --set; then
305
+ echo "[ERROR] Could not initialize local.json(symbolic link to dummy)"
306
+ exit 1
307
+ fi
308
+
309
+ if ! NODE_PATH="${NODE_PATH}" NODE_ENV="${NODE_ENV_VALUE}" NODE_DEBUG="${DEBUG_ENV_PARAM}" NODE_LOGGER="${NODE_LOGGER}" NODE_CONFIG_DIR='' node_modules/.bin/mocha --timeout "${TIMEOUT}" "tests/${CMD_PREFIX}${COMMAND}${CMD_SUFFIX}"; then
310
+ echo "[ERROR] Failed test."
311
+ if ! "${AUTO_INIT_SH}" --restore; then
312
+ echo "[ERROR] Could not restore local.json"
313
+ fi
314
+ exit 1
315
+ fi
316
+
317
+ if ! "${AUTO_INIT_SH}" --restore; then
318
+ echo "[ERROR] Could not restore local.json"
319
+ exit 1
320
+ fi
321
+
322
+ exit 0
323
+
324
+ #
325
+ # Local variables:
326
+ # tab-width: 4
327
+ # c-basic-offset: 4
328
+ # End:
329
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
330
+ # vim<600: noexpandtab sw=4 ts=4
331
+ #
@@ -1,170 +0,0 @@
1
- #!/bin/sh
2
- #
3
- # K2HR3 REST API
4
- #
5
- # Copyright 2017 Yahoo! Japan Corporation.
6
- #
7
- # K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
8
- # common management information for the cloud.
9
- # K2HR3 can dynamically manage information as "who", "what", "operate".
10
- # These are stored as roles, resources, policies in K2hdkc, and the
11
- # client system can dynamically read and modify these information.
12
- #
13
- # For the full copyright and license information, please view
14
- # the license file that was distributed with this source code.
15
- #
16
- # AUTHOR: Takeshi Nakatani
17
- # CREATE: Tue Dec 19 2017
18
- # REVISION:
19
- #
20
-
21
- #
22
- # This script starts/stops k2hdkc cluster/chmpx server/chmpx slave processes,
23
- # and initializes data on k2hdkc for testing.
24
- #
25
- #
26
- # Common
27
- #
28
- CMDLINE_PROCESS_NAME=$0
29
- CMDLINE_ALL_PARAM=$@
30
- PROGRAM_NAME=`basename ${CMDLINE_PROCESS_NAME}`
31
- MYSCRIPTDIR=`dirname ${CMDLINE_PROCESS_NAME}`
32
-
33
- #
34
- # Parse arguments
35
- #
36
- IS_RUN_MODE=-1
37
- RUN_INTERVAL=-1
38
- CHILD_PROCESS_MANAGE_KEY=""
39
-
40
- while [ $# -ne 0 ]; do
41
- if [ "X$1" = "X--help" -o "X$1" = "X--HELP" -o "X$1" = "X-h" -o "X$1" = "X-H" ]; then
42
- echo "${PROGRAM_NAME} [ -help | -start | -stop ] {-key key} {-interval <number>} <process> <arg>..."
43
- exit 1
44
-
45
- elif [ "X$1" = "X-start" -o "X$1" = "X-START" ]; then
46
- if [ ${IS_RUN_MODE} -ne -1 ]; then
47
- echo "Already run mode(option) is specified."
48
- exit 1
49
- fi
50
- IS_RUN_MODE=1
51
-
52
- elif [ "X$1" = "X-stop" -o "X$1" = "X-STOP" ]; then
53
- if [ ${IS_RUN_MODE} -ne -1 ]; then
54
- echo "Already run mode(option) is specified."
55
- exit 1
56
- fi
57
- IS_RUN_MODE=0
58
-
59
- elif [ "X$1" = "X-key" -o "X$1" = "X-KEY" ]; then
60
- if [ "X${CHILD_PROCESS_MANAGE_KEY}" != "X" ]; then
61
- echo "Already -key option is specified."
62
- exit 1
63
- fi
64
- shift
65
- if [ $# -eq 0 ]; then
66
- echo "-key option needs parameter"
67
- exit 1
68
- fi
69
- CHILD_PROCESS_MANAGE_KEY="_$1"
70
-
71
- elif [ "X$1" = "X-interval" -o "X$1" = "X-INTERVAL" -o "X$1" = "X-int" -o "X$1" = "X-INT" ]; then
72
- if [ ${RUN_INTERVAL} -ne -1 ]; then
73
- echo "Already -interval option is specified."
74
- exit 1
75
- fi
76
- shift
77
- if [ $# -eq 0 ]; then
78
- echo "-interval option needs parameter"
79
- exit 1
80
- fi
81
- RUN_INTERVAL=$1
82
-
83
- else
84
- #
85
- # Finish to parse option, rest arguments are command and it's args
86
- #
87
- break
88
- fi
89
- shift
90
- done
91
-
92
- if [ $# -eq 0 ]; then
93
- echo "There is no process name and arguments"
94
- exit 1
95
- fi
96
- CHILD_PROCESS_NAME=$1
97
- CHILD_PROCESS_CMD=$@
98
-
99
- #
100
- # Process pid/log
101
- #
102
- CHILD_PROCESS_PIDFILE="/tmp/${PROGRAM_NAME}_${CHILD_PROCESS_NAME}${CHILD_PROCESS_MANAGE_KEY}.pid"
103
- CHILD_PROCESS_LOGFILE="/tmp/${PROGRAM_NAME}_${CHILD_PROCESS_NAME}${CHILD_PROCESS_MANAGE_KEY}.log"
104
-
105
- #
106
- # Execute
107
- #
108
- if [ ${IS_RUN_MODE} -eq 1 ]; then
109
- #
110
- # Start Process
111
- #
112
- ${CHILD_PROCESS_CMD} >${CHILD_PROCESS_LOGFILE} 2>&1 &
113
- CHILD_PROCESS_PID=$!
114
-
115
- if [ ${RUN_INTERVAL} -ne -1 -a ${RUN_INTERVAL} -ne 0 ]; then
116
- sleep ${RUN_INTERVAL}
117
- fi
118
-
119
- ps -p ${CHILD_PROCESS_PID} >/dev/null 2>&1
120
- if [ $? -ne 0 ]; then
121
- echo "Could not start child process : ${CHILD_PROCESS_CMD}"
122
- exit 1
123
- fi
124
- echo ${CHILD_PROCESS_PID} > ${CHILD_PROCESS_PIDFILE}
125
- echo "Succeed to start process(${CHILD_PROCESS_PID}) : ${CHILD_PROCESS_CMD}"
126
-
127
- else
128
- #
129
- # Stop Process
130
- #
131
- if [ -f ${CHILD_PROCESS_PIDFILE} ]; then
132
- CHILD_PROCESS_PID=`cat ${CHILD_PROCESS_PIDFILE}`
133
-
134
- ps -p ${CHILD_PROCESS_PID} >/dev/null 2>&1
135
- if [ $? -eq 0 ]; then
136
- kill -HUP ${CHILD_PROCESS_PID}
137
-
138
- if [ ${RUN_INTERVAL} -ne -1 -a ${RUN_INTERVAL} -ne 0 ]; then
139
- sleep ${RUN_INTERVAL}
140
- fi
141
-
142
- ps -p ${CHILD_PROCESS_PID} >/dev/null 2>&1
143
- if [ $? -eq 0 ]; then
144
- kill -9 ${CHILD_PROCESS_PID}
145
-
146
- if [ ${RUN_INTERVAL} -ne -1 -a ${RUN_INTERVAL} -ne 0 ]; then
147
- sleep ${RUN_INTERVAL}
148
- fi
149
-
150
- ps -p ${CHILD_PROCESS_PID} >/dev/null 2>&1
151
- if [ $? -eq 0 ]; then
152
- echo "Could not stop child process : ${CHILD_PROCESS_CMD}"
153
- exit 1
154
- fi
155
- fi
156
- fi
157
- echo "Succeed to stop process : ${CHILD_PROCESS_CMD}(${CHILD_PROCESS_PID})"
158
- rm -f ${CHILD_PROCESS_PIDFILE}
159
- else
160
- echo "Not found child process pid file : ${CHILD_PROCESS_PIDFILE}"
161
- fi
162
- fi
163
-
164
- exit 0
165
-
166
- #
167
- # VIM modelines
168
- #
169
- # vim:set ts=4 fenc=utf-8:
170
- #