Skip to content

Commit

Permalink
Enhancement: install.sh would install the Systemd service after downl…
Browse files Browse the repository at this point in the history
…oad the binary. (#461)

* add the systemd unit configuration

* update the README.md

* Update scripts/config.yaml

Co-authored-by: Bomin Zhang <[email protected]>

* Update scripts/install.sh

Co-authored-by: Bomin Zhang <[email protected]>

Co-authored-by: Bomin Zhang <[email protected]>
  • Loading branch information
haoel and localvar committed Jan 13, 2022
1 parent 9b29b1c commit 8a94330
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ The basic common usage of Easegress is to quickly set up proxy for the backend s

### Setting up Easegress

We can download the latest or history binaries from the [release page](https://github.com/megaease/easegress/releases). Following shell script will download and extract the latest binaries to `./easegress` folder:
We can download the latest or history binaries from the [release page](https://github.com/megaease/easegress/releases). The following shell script will do:

- Download and extract the latest binaries to `./easegress` folder
- Install the Easegress Systemd service.

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/megaease/easegress/main/scripts/install.sh)"
Expand Down
5 changes: 4 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ Easegress 的基本用法是做为后端服务器的代理。下面分步说明

### 安装 Easegress

我们可以从[发布页](https://github.com/megaease/easegress/releases)下载 Easegress 的最新或历史版本。下面的 Shell 命令会下载并解压最新版的 Easegress 到 `./easegress` 目录下:
我们可以从[发布页](https://github.com/megaease/easegress/releases)下载 Easegress 的最新或历史版本。下面的 Shell 命令会做如下的事:

- 下载并解压最新版的 Easegress 到 `./easegress` 目录下
- 安装 Systemd 服务,并启动 easegress

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/megaease/easegress/main/scripts/install.sh)"
Expand Down
83 changes: 83 additions & 0 deletions scripts/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
## name of this easegress instance
# name: eg-default-name

## labels for the instance (key/value pairs)
# labels:

## address([host]:port) to listen on for administration traffic
# api-addr: localhost:2381

## flag to set lowest log level from INFO to DEBUG
# debug: false

## flag to disable access log
# disable-access-log: false

## list of configuration files for initial objects, these objects will be created at startup if not already exist
# initial-object-config-files:

## human-readable name for new cluster, ignored while joining an existed cluster
# cluster-name: eg-cluster-default-name

## cluster role for this member (primary, secondary)
# cluster-role: primary

## timeout to handle request in the cluster
# cluster-request-timeout: 10s


## cluster options (note this option contains several sub-options)
# cluster:

## list of URLs to listen on for cluster client traffic
# listen-client-urls:
# - http:https://localhost:2379

## list of URLs to listen on for cluster peer traffic
# listen-peer-urls:
# - http:https://localhost:2380

## list of this member's client URLs to advertise to the rest of the cluster
# advertise-client-urls:
# - http:https://localhost:2379

## list of this member's peer URLs to advertise to the rest of the cluster
# initial-advertise-peer-urls:
# - http:https://localhost:2380

## list of (member name, URL) pairs that will form the cluster. E.g.
## primary-1: http:https://localhost:2380
# initial-cluster:

## cluster state (new, existing)
# state-flag: new

## list of peer URLs of primary members. Define this only when cluster-role is secondary
# primary-listen-peer-urls:
# - http:https://localhost:2380

## maximum size in bytes for cluster synchronization messages
# max-call-send-msg-size: 10485760


## path to the home directory
# home-dir: ##DIR##

## path to the data directory
# data-dir: ##DIR##/data

## path to the wal directory
# wal-dir: ##DIR##/wal

## path to the log directory
# log-dir: ##DIR##/log

## path to the member directory
# member-dir: ##DIR##/member

## path to the CPU profile file
# cpu-profile-file:

## path to the memory profile file
# memory-profile-file:

15 changes: 15 additions & 0 deletions scripts/easegress.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Easegress Gateway
Documentation=https://github.com/megaease/easegress/tree/main/doc
After=network.target

[Service]
Type=simple
ExecStart=##BINDIR##/easegress-server -f ##DIR##/config.yaml
ExecStop=/bin/kill -INT $MAINPID
Restart=on-failure
WorkingDirectory=##DIR##

[Install]
WantedBy=multi-user.target

57 changes: 52 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/bin/bash

set -e


# First - check OS.
OS="$(uname)"
if [[ "${OS}" == "Linux" ]]; then
OS=linux
DISTRO=$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '\"')
elif [[ "${OS}" == "Darwin" ]];then
OS=darwin
else
abort "Unsupport OS - ${OS}"
fi

#Second - check the CPU arch
#refer to: https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
# Second - check the CPU arch
# refer to: https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
ARCH=$(uname -m)
if [[ $ARCH == x86_64 ]]; then
ARCH=amd64
Expand All @@ -23,13 +27,56 @@ else
abort "Unsupport CPU - ${ARCH}"
fi

#Third - download the binaries
# Third - download the binaries
GITHUB_URL=https://github.com/megaease/easegress
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' ${GITHUB_URL}/releases/latest)
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
ARTIFACT="easegress-${LATEST_VERSION}-${OS}-${ARCH}.tar.gz"
ARTIFACT_URL="${GITHUB_URL}/releases/download/${LATEST_VERSION}/${ARTIFACT}"


DIR=$(pwd)/easegress
BINDIR=${DIR}/bin

mkdir -p ./easegress
curl -L ${ARTIFACT_URL} -o ./easegress/${ARTIFACT}
tar -zxf ./easegress/${ARTIFACT} -C easegress
echo "Create the directory - \"${DIR}\" successfully."
echo "Downloading the release file - \"${ARTIFACT}\" ..."
curl -sL ${ARTIFACT_URL} -o ./easegress/${ARTIFACT}
echo "Downloaded \"${ARTIFACT}\""
tar -zxf ./easegress/${ARTIFACT} -C easegress
echo "Extract the files successfully"

# Fourth - configure the easegress
echo "Download the config.yaml file"
RAW_GITHUB_URL=https://raw.githubusercontent.com/megaease/easegress
curl -sL ${RAW_GITHUB_URL}/main/scripts/config.yaml -o ./easegress/config.yaml
sed -i -e "s~##DIR##~${DIR}~g" ./easegress/config.yaml
if [[ "${OS}" == "linux" ]]; then

# SELinux prevents you from running a system service where the binary is in a user's home directory.
# We have to copy the binary to a proper directory, such as /usr/local/bin
if [[ "${DISTRO}" == "CentOS"* ]] && [[ $(getenforce) != "Disabled" ]]; then
BINDIR=/usr/local/bin
echo "Dealing with SELinux, copy Easegress to ${BINDIR}"
sudo cp -f ./easegress/bin/* ${BINDIR}
fi

# Prepare the unit file for Systemd
echo "Configuring the systemd unit file..."
curl -sL ${RAW_GITHUB_URL}/main/scripts/easegress.service -o ./easegress/easegress.service
sed -i -e "s~##BINDIR##~${BINDIR}~g" ./easegress/easegress.service
sed -i -e "s~##DIR##~${DIR}~g" ./easegress/easegress.service

# install the systemd unit file
echo "Enable the easegress service"
sudo cp -f ./easegress/easegress.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable easegress

echo "Start the easegress service"
sudo systemctl start easegress

#check the status
sleep 2
systemctl status easegress
fi

0 comments on commit 8a94330

Please sign in to comment.