The inst_start() function does not check if a process is already
running, making it unusable for the implementation of singleton
daemons.
This commit adds the inst_singleton() function, which allows the
caller to implement daemons which can only be run one at a time.
echo "${status%%:*}"
return 0
}
+
+inst_count() {
+ local -i num
+
+ if ! num=$(find "$__inst_path" -regex ".*/[0-9]+" | wc -l); then
+ return 1
+ fi
+
+ echo "$num"
+ return 0
+}
+
+inst_singleton() {
+ local args=("$@")
+
+ if (( $(inst_count) > 0 )); then
+ log_error "Another instance is already running"
+ return 1
+ fi
+
+ if ! inst_start "${args[@]}"; then
+ return 1
+ fi
+
+ return 0
+}