case "$opt" in
"stop")
- if ! inst_stop "$arg"; then
+ if ! inst_stop "$arg" "$__inst_name"; then
ret=1
fi
;;
"list")
- if ! inst_list; then
+ if ! inst_list "$__inst_name"; then
ret=1
fi
;;
}
inst_list() {
+ local instname="$1"
+
+ local instpath
local sem
+ if [[ -z "$instname" ]]; then
+ instname="$__inst_name"
+ fi
+ instpath="$TOOLBOX_HOME/inst/$instname"
+
while read -r sem; do
local owner
local semval
continue
fi
- if ! status_text=$(inst_get_status_message "$owner") ||
- ! status_time=$(inst_get_status_timestamp "$owner"); then
+ if ! status_text=$(inst_get_status_message "$owner" "$instname") ||
+ ! status_time=$(inst_get_status_timestamp "$owner" "$instname"); then
continue
fi
state="RUNNING"
fi
- echo "$owner $state [$timestamp:$status_text] $__inst_name $argv"
- done < <(find "$__inst_path" -regex ".*/[0-9]+")
+ echo "$owner $state [$timestamp:$status_text] $instname $argv"
+ done < <(find "$instpath" -regex ".*/[0-9]+")
return 0
}
inst_stop() {
local pid="$1"
+ local instname="$2"
local sem
+ local instpath
+
+ if [[ -z "$instname" ]]; then
+ instname="$__inst_name"
+ fi
+ instpath="$TOOLBOX_HOME/inst/$instname"
- sem="$__inst_path/$pid"
+ sem="$instpath/$pid"
if ! sem_post "$sem" &> /dev/null; then
log_error "No such instance"
inst_get_status() {
local pid="$1"
+ local instname="$2"
local status
+ local instpath
- if ! status=$(< "$__inst_path/$pid.status"); then
- log_error "Could not read from $__inst_path/$pid.status"
+ if [[ -z "$instname" ]]; then
+ instname="$__inst_name"
+ fi
+ instpath="$TOOLBOX_HOME/inst/$instname"
+
+ if ! status=$(< "$instpath/$pid.status"); then
+ log_error "Could not read from $instpath/$pid.status"
return 1
fi
inst_get_status_message() {
local pid="$1"
+ local instname="$2"
- if ! status=$(inst_get_status "$pid"); then
+ if ! status=$(inst_get_status "$pid" "$instname"); then
return 1
fi
inst_get_status_timestamp() {
local pid="$1"
+ local instname="$2"
local status
- if ! status=$(inst_get_status "$pid"); then
+ if ! status=$(inst_get_status "$pid" "$instname"); then
return 1
fi
}
inst_count() {
+ local instname="$1"
+
local -i num
+ local instpath
+
+ if [[ -z "$instname" ]]; then
+ instname="$__inst_name"
+ fi
+ instpath="$TOOLBOX_HOME/inst/$instname"
- if ! num=$(find "$__inst_path" -regex ".*/[0-9]+" | wc -l); then
+ if ! num=$(find "$instpath" -regex ".*/[0-9]+" | wc -l); then
return 1
fi
inst_singleton() {
local args=("$@")
- if (( $(inst_count) > 0 )); then
+ if (( $(inst_count "$__inst_name") > 0 )); then
log_error "Another instance is already running"
return 1
fi