From 3b15d8dcd8912825281367ed959d7ad212e6a0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 8 Apr 2017 21:56:30 +0200 Subject: Add user services --- local/sbin/user-service.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 local/sbin/user-service.sh (limited to 'local') diff --git a/local/sbin/user-service.sh b/local/sbin/user-service.sh new file mode 100755 index 0000000..e48bb9d --- /dev/null +++ b/local/sbin/user-service.sh @@ -0,0 +1,90 @@ +#!/bin/sh +set -e + +[ -z "$1" ] && {echo "Run this script only from user-service file!" && exit 1} + +# Name of service +NAME="$(basename "$1")" +SERVICE="$1" + +# Source input file +. "$1" +shift + +OP="status" +Q=true +# Parse arguments +while [ -n "$1" ]; do + case "$1" in + -h|--help) + echo "User service: $NAME" + echo " $description" + echo "$SERVICE [OPTION]... OPERATION" + echo " Options:" + echo " -q - be quiet" + echo " Operations:" + echo " status - show status of service" + echo " start - start service" + echo " stop - stop service" + echo " restart - restart service" + ;; + -q) + Q=false + ;; + status|start|stop|restart) + OP="$1" + ;; + *) + echo "Unknown argument: $1" + exit 1 + ;; + esac + shift +done + +case "$OP" in + status) + if status; then + $Q && echo "Service $NAME is running" + exit 0 + else + $Q && echo "Service $NAME is not running" + exit 1 + fi + ;; + start) + $Q && echo -n "Starting service $NAME..." + if start; then + $Q && echo " ok" + else + $Q && echo " fail" + exit 1 + fi + ;; + stop) + $Q && echo -n "Stopping service $NAME..." + if stop; then + $Q && echo " ok" + else + $Q && echo " fail" + exit 1 + fi + ;; + restart) + $Q && echo "Restarting service $NAME..." + if ! stop; then + $Q && echo " stop failed" + exit 1 + fi + if start; then + $Q && echo " ok" + else + $Q && echo " start failed" + exit 1 + fi + ;; + *) + echo "Invalid operation!" + exit 3 + ;; +esac -- cgit v1.2.3