From db185a57ca64bed6962615a72ab9a124860a4d4e Mon Sep 17 00:00:00 2001 From: pierreozoux Date: Sat, 26 Nov 2016 16:30:39 +0000 Subject: [PATCH] Use libre as a command to rule them all \o/ --- README.md | 28 ++++++------------ utils/disable | 1 - utils/enable | 1 - utils/libre | 63 ++++++++++++++++++++++++++++++++++++++++ utils/restart | 1 - utils/start | 1 - utils/status | 1 - utils/stop | 1 - utils/systemctl_commands | 15 ---------- 9 files changed, 72 insertions(+), 40 deletions(-) delete mode 120000 utils/disable delete mode 120000 utils/enable create mode 100755 utils/libre delete mode 120000 utils/restart delete mode 120000 utils/start delete mode 120000 utils/status delete mode 120000 utils/stop delete mode 100755 utils/systemctl_commands diff --git a/README.md b/README.md index 6ff9de9..3d8f501 100644 --- a/README.md +++ b/README.md @@ -63,17 +63,8 @@ Go to their respective page for more details. cd /system/ git clone module cd module -systemctl enable s@module -start -``` - -### To debug a module: - -``` -docker-compose ps -docker-compose logs -stop -restart +libre enable +libre start ``` ## Applications @@ -83,19 +74,18 @@ restart To install application `wordpress` on `example.org`, first make point example.org to your server IP, and then, just run: ``` -provision -a github.com/indiehosters/wordpress -u example.org -s +libre provision -a github.com/indiehosters/wordpress -u example.org -s ``` -Run `provision` for more details on the capabilities of the script. +Run `libre provision` for more details on the capabilities of the script. -### debug an application +## To debug a module or an application: ``` -docker-compose ps -docker-compose logs -stop -start -restart +libre ps +libre logs -f --tail=100 +libre stop +libre restart ``` ## Contributing diff --git a/utils/disable b/utils/disable deleted file mode 120000 index 8b293ee..0000000 --- a/utils/disable +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/enable b/utils/enable deleted file mode 120000 index 8b293ee..0000000 --- a/utils/enable +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/libre b/utils/libre new file mode 100755 index 0000000..09fdec9 --- /dev/null +++ b/utils/libre @@ -0,0 +1,63 @@ +#!/bin/bash -eu + + +function error_path { + >&2 echo "Error: you must be in either /data/domains/*/ or /system/*/ to execute these commands" + exit 1 +} + +function systemctl_param { + first_level_path=`pwd | cut -d'/' -f2` + second_level_path=`pwd | cut -d'/' -f3` + + if [ "$first_level_path" == "system" ]; then + module=`pwd | cut -d'/' -f3` + if [ -n "$module" ]; then + echo s@$module + else + error_path + fi + elif [ "$first_level_path" == "data" ] && [ "$second_level_path" == "domains" ]; then + domain=`pwd | cut -d'/' -f4` + if [ -n "$domain" ]; then + echo u@$domain + else + error_path + fi + else + error_path + fi +} + + +case "$1" in + start|status|enable|disable|restart|stop) + if [ -n "$(systemctl_param)" ]; then + echo "systemctl $1 $(systemctl_param)" + systemctl $1 $(systemctl_param) + fi;; + ps|exec|logs) + if [ -f ./env ]; then + env $(cat ./env | xargs) docker-compose $1 ${@:2} + else + docker-compose $1 ${@:2} + fi;; + update) + if [ "$(pwd)" == "/libre.sh" ]; then + echo "Indiehosters"; + git pull + cp /libre.sh/unit-files/* /etc/systemd/system && systemctl daemon-reload &&\ + cp /libre.sh/utils/* /opt/bin/ + elif [ -n "$(systemctl_param)" ]; then + git pull + docker-compose pull + libre restart + fi;; + provision) + provision ${@:2};; + *) + echo "Usage:" + echo " - start|status|enable|disable|restart|stop: command sent to systemctl." + echo " - ps|exec|logs: command sent to docker compose." + echo " - update: to update the current folder." +esac diff --git a/utils/restart b/utils/restart deleted file mode 120000 index 8b293ee..0000000 --- a/utils/restart +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/start b/utils/start deleted file mode 120000 index 8b293ee..0000000 --- a/utils/start +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/status b/utils/status deleted file mode 120000 index 8b293ee..0000000 --- a/utils/status +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/stop b/utils/stop deleted file mode 120000 index 8b293ee..0000000 --- a/utils/stop +++ /dev/null @@ -1 +0,0 @@ -systemctl_commands \ No newline at end of file diff --git a/utils/systemctl_commands b/utils/systemctl_commands deleted file mode 100755 index 60915d5..0000000 --- a/utils/systemctl_commands +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -command=`basename "$0"` -first_level_path=`pwd | cut -d'/' -f2` -second_level_path=`pwd | cut -d'/' -f3` - -if [ "$first_level_path" == "system" ]; then - module=`pwd | cut -d'/' -f3` - systemctl $command s@$module -elif [ "$first_level_path" == "data" ]; then - if [ "$second_level_path" == "domains" ]; then - domain=`pwd | cut -d'/' -f4` - systemctl $command u@$domain - fi -fi -- GitLab