From 916aa4d2da709b4e9fa93b13a233d49cba0205b2 Mon Sep 17 00:00:00 2001 From: Michel Diz Date: Mon, 10 Aug 2020 17:07:42 -0300 Subject: [PATCH 1/3] add template --- contrib/service.tmpl | 17 ++++++++++++ getdgraph.sh | 61 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 contrib/service.tmpl diff --git a/contrib/service.tmpl b/contrib/service.tmpl new file mode 100644 index 0000000..63984af --- /dev/null +++ b/contrib/service.tmpl @@ -0,0 +1,17 @@ +[Unit] +Description=${description} +Wants=network.target +After=network.target ${empty:-${afterService}} ${empty:-${requires}} + +[Service] +Type=simple +WorkingDirectory=/var/lib/dgraph +ExecStart=${myShell} -c '${command}' +Restart=on-failure +StandardOutput=journal +StandardError=journal +User=dgraph +Group=dgraph + +[Install] +WantedBy=multi-user.target ${empty:-${requiredBy}} diff --git a/getdgraph.sh b/getdgraph.sh index 27d8a96..d7e9673 100755 --- a/getdgraph.sh +++ b/getdgraph.sh @@ -28,6 +28,7 @@ ACCEPT_LICENSE=${acceptLower:-n} INSTALL_IN_SYSTEMD=${systemdLower:-n} sudo_cmd="" argVersion= +myShell=$(which bash) print_instruction() { printf '%b\n' "$BOLD$1$RESET" @@ -237,29 +238,69 @@ addGroup() { exit 0 } +render_template() { + eval "echo \"$(cat $1)\"" +} + + gen() { + empty='' + description=$1 + requires=$2 + requiredBy=$3 + command=$4 + afterService=$5 + render_template "$tmplTemp/service.tmpl" > $6 +} + setup_systemD() { - pathToFiles="https://raw.githubusercontent.com/dgraph-io/dgraph/master/contrib/systemd/centos" + pathToTemplate="https://raw.githubusercontent.com/dgraph-io/Install-Dgraph/master/contrib" systemdPath="/etc/systemd/system/" dgraphPath="/var/lib/dgraph" + tmplTemp="/tmp/dgraph" $sudo_cmd mkdir -p $dgraphPath $sudo_cmd mkdir -p $dgraphPath/{p,w,zw} $sudo_cmd mkdir -p /var/log/dgraph - $sudo_cmd chown -R dgraph:dgraph /var/{lib,log}/dgraph + $sudo_cmd mkdir -p $tmplTemp + + _getTmpl="$pathToTemplate/service.tmpl" + + $sudo_cmd curl -LJ --progress-bar "$_getTmpl" -o "$tmplTemp/service.tmpl" - _alpha="$pathToFiles/dgraph-alpha.service" - _zero="$pathToFiles/dgraph-zero.service" - _ui="$pathToFiles/dgraph-ui.service" - _addAccount="$pathToFiles/add_dgraph_account.sh" + echo "#### Creating dgraph-ui.service ..." - $sudo_cmd curl -LJ --progress-bar "$_alpha" -o "$systemdPath/dgraph-alpha.service" - $sudo_cmd curl -LJ --progress-bar "$_zero" -o "$systemdPath/dgraph-zero.service" - $sudo_cmd curl -LJ --progress-bar "$_ui" -o "$systemdPath/dgraph-ui.service" + gen "dgraph.io Web UI" \ + "" \ + "" \ + "dgraph-ratel" \ + "" \ + $systemdPath/dgraph-ui.service + + echo "#### Creating dgraph-alpha.service ..." + + gen "dgraph.io Alpha instance" \ + "\nRequires=dgraph-zero.service" \ + "" \ + "dgraph alpha --lru_mb 2048 -p /var/lib/dgraph/p -w /var/lib/dgraph/w" \ + "dgraph-zero.service" \ + $systemdPath/dgraph-alpha.service + + echo "#### Creating dgraph-zero.service ..." + + gen "dgraph.io Zero instance" \ + "" \ + "\nRequiredBy=dgraph-alpha.service" \ + "dgraph zero --wal /var/lib/dgraph/zw" \ + "" \ + $systemdPath/dgraph-zero.service + + rm "/tmp/""$tar_file"; + rm -rf "$temp_dir" $sudo_cmd systemctl daemon-reload - + $sudo_cmd systemctl enable dgraph-alpha $sudo_cmd systemctl start dgraph-alpha From d578825310106dab60b062def412cacd52fbd5b0 Mon Sep 17 00:00:00 2001 From: Michel Diz Date: Mon, 10 Aug 2020 17:10:26 -0300 Subject: [PATCH 2/3] fix typo --- getdgraph.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/getdgraph.sh b/getdgraph.sh index d7e9673..40e52f5 100755 --- a/getdgraph.sh +++ b/getdgraph.sh @@ -296,8 +296,7 @@ setup_systemD() { "" \ $systemdPath/dgraph-zero.service - rm "/tmp/""$tar_file"; - rm -rf "$temp_dir" + rm -rf "$tmplTemp" $sudo_cmd systemctl daemon-reload From 77409e0f8a8072176e36453ccdc18d76268ccc45 Mon Sep 17 00:00:00 2001 From: Michel Diz Date: Wed, 19 Aug 2020 16:26:06 -0300 Subject: [PATCH 3/3] change reserved word --- contrib/service.tmpl | 2 +- getdgraph.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/service.tmpl b/contrib/service.tmpl index 63984af..e0b9bbe 100644 --- a/contrib/service.tmpl +++ b/contrib/service.tmpl @@ -6,7 +6,7 @@ After=network.target ${empty:-${afterService}} ${empty:-${requires}} [Service] Type=simple WorkingDirectory=/var/lib/dgraph -ExecStart=${myShell} -c '${command}' +ExecStart=${myShell} -c '${cmd}' Restart=on-failure StandardOutput=journal StandardError=journal diff --git a/getdgraph.sh b/getdgraph.sh index 40e52f5..12ad306 100755 --- a/getdgraph.sh +++ b/getdgraph.sh @@ -247,7 +247,7 @@ render_template() { description=$1 requires=$2 requiredBy=$3 - command=$4 + cmd=$4 afterService=$5 render_template "$tmplTemp/service.tmpl" > $6 }