summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2019-09-26 11:37:49 +0200
committerRamón M. Gómez <ramongomez@us.es>2019-09-26 11:37:49 +0200
commit84954097c4bce5b4eb700546c7b5c98c6a86a747 (patch)
tree25db2b1aa97f818ff36028ff4a3d7bcda976071a /server/lib
parent8645a4a3854dda6384ee64d9992240bb51345c3f (diff)
#925: settoken: new server script to generate service access tokens.
Diffstat (limited to 'server/lib')
-rwxr-xr-xserver/lib/ogfunctions.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/server/lib/ogfunctions.sh b/server/lib/ogfunctions.sh
index 51de6b77..34b2ab7b 100755
--- a/server/lib/ogfunctions.sh
+++ b/server/lib/ogfunctions.sh
@@ -23,6 +23,9 @@ function raiseError() {
download)
echo "$PROG: Download error: $2" >&2
exit 4 ;;
+ cancel)
+ echo "$PROG: Operation cancelled: $2" >&2
+ exit 5 ;;
*)
echo "$PROG: Unknown error" >&2
exit 1 ;;
@@ -54,6 +57,20 @@ function help() {
exit 0
}
+# Functions to manage a service.
+function restart() {
+ _service restart "$1"
+}
+function start() {
+ _service start "$1"
+}
+function stop() {
+ _service stop "$1"
+}
+
+
+### Meta-functions and private functions.
+
# Metafunction to check if JSON result exists.
JQ=$(which jq 2>/dev/null) || raiseError notfound "Need to install \"jq\"."
function jq() {
@@ -63,3 +80,17 @@ function jq() {
echo "$OUTPUT"
}
+# Private function to acts on a service (do not use directly).
+function _service() {
+ local ACTION="$1"
+ local SERVICE="$2"
+ if which systemctl 2>/dev/null; then
+ systemctl "$ACTION" "$SERVICE"
+ elif which service 2>/dev/null; then
+ service "$SERVICE" "$ACTION"
+ elif [ -x /etc/init.d/"$SERVICE" ]; then
+ /etc/init.d/"$SERVICE" "$ACTION"
+ else
+ raiseError notfound "Service $SERVICE"
+ fi
+}