diff --git a/.github/linters/.dockerfilelintrc b/.github/linters/.dockerfilelintrc deleted file mode 100644 index d5d9330..0000000 --- a/.github/linters/.dockerfilelintrc +++ /dev/null @@ -1,3 +0,0 @@ -rules: - uppercase_commands: off - expose_host_port: off diff --git a/.github/workflows/Installation.yml b/.github/workflows/Installation.yml deleted file mode 100644 index 7bf9314..0000000 --- a/.github/workflows/Installation.yml +++ /dev/null @@ -1,24 +0,0 @@ - - -name: RecSync-env installation test - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - run: sudo apt install -y python-twisted python-requests python-simplejson python-urllib3 git make - - run: | - make init || exit - make vars || exit - - run: | - make install || exit - make exist || exist diff --git a/.github/workflows/debian11.yml b/.github/workflows/debian11.yml new file mode 100644 index 0000000..a023b83 --- /dev/null +++ b/.github/workflows/debian11.yml @@ -0,0 +1,48 @@ +--- +name: Debian 11 + +on: + push: + branches: [ master ] + paths-ignores: + - '*.md' + - 'docker/**' + - '.github/workflows/docker.yml' + - '.github/workflows/ubuntu.yml' + - '.github/workflows/rocky8.yml' + - '.github/workflows/linter.yml' + + pull_request: + branches: [ master ] + +jobs: + Debian11: + + runs-on: ubuntu-latest + container: debian:bullseye + + steps: + - uses: actions/checkout@v3 + - name: Install required packages + run: | + apt update -y + apt install -y git make sudo tree + apt install -y python3-twisted python3-requests python3-simplejson python3-urllib3 + update-alternatives --install /usr/bin/python python /usr/bin/python3 1 + update-alternatives --install /usr/bin/twistd twistd /usr/bin/twistd3 1 + - name: Check PYTHON environment + run: | + which python + python --version + which twistd + twistd --version + - name: Configuration + run: | + make init + make vars + - name: Build + run: | + make src_install + - name: Environment Check + run: make exist + diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 76a7351..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Docker Image - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - - build: - - runs-on: ubuntu-latest - - continue-on-error: false - - steps: - - uses: actions/checkout@v2 - - name: Build the Docker image - run: | - make build.docker || exit diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..d88bb5c --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,68 @@ +# 0. change name +name: Docker +# change path name +on: + push: + branches: [ master ] + paths: + - 'docker/**' + - '.github/workflows/docker.yml' + pull_request: + branches: [ master ] +# +jobs: +# change job name + recsync: + runs-on: ubuntu-latest + env: + # change the following 4 variables + DOCKER_FILE: docker/Dockerfile + DOCKER_ACCOUNT: alscontrols + DOCKER_REPO: recsync + DOCKER_TAG: latest + + steps: + - + name: checkout + uses: actions/checkout@v2 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + ${{ env.DOCKER_ACCOUNT }}/${{ env.DOCKER_REPO }} + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + file: ${{ github.workspace }}/${{ env.DOCKER_FILE }} + push: ${{ github.event_name != 'pull_request' }} + #tags: ${{ steps.meta.outputs.tags }} + tags: ${{ env.DOCKER_ACCOUNT }}/${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 8047879..fbd5f9e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -13,10 +13,10 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Lint Code Base - uses: docker://github/super-linter:latest + uses: docker://github/super-linter:v4.9.5 env: -# VALIDATE_ALL_CODEBASE: true - VALIDATE_MD: true - VALIDATE_BASH: true + VALIDATE_MD: true + VALIDATE_BASH: true + diff --git a/.github/workflows/rocky8.yml b/.github/workflows/rocky8.yml new file mode 100644 index 0000000..f57e0cc --- /dev/null +++ b/.github/workflows/rocky8.yml @@ -0,0 +1,52 @@ +--- +name: Rocky8 + +on: + push: + branches: [ master ] + paths-ignores: + - '*.md' + - 'examples/*.bash' + - 'docker/**' + - '.github/workflows/ubuntu.yml' + - '.github/workflows/docker.yml' + - '.github/workflows/ubuntu.yml' + - '.github/workflows/linter.yml' + + pull_request: + branches: [ master ] + +jobs: + Rocky8: + + runs-on: ubuntu-latest + container: rockylinux/rockylinux:8 + + steps: + - uses: actions/checkout@v3 + - name: Install required packages + run: | + dnf -y install dnf-plugins-core + dnf update -y + dnf config-manager --set-enabled powertools + dnf update -y + dnf -y install "epel-release" + dnf update -y + dnf install -y git make sudo tree which + dnf install -y python3-twisted python3-requests python3-simplejson python3-urllib3 + alternatives --set python /usr/bin/python3 + - name: Check PYTHON environment + run: | + which python + python --version + which twistd + twistd --version + - name: Configuration + run: | + make init + make vars + - name: Build + run: | + make src_install + - name: Environment Check + run: make exist diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..99bbd56 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,47 @@ +--- +name: Ubuntu latest + +on: + push: + branches: [ master ] + paths-ignores: + - '*.md' + - 'docker/**' + - '.github/workflows/docker.yml' + - '.github/workflows/ubuntu.yml' + - '.github/workflows/rocky8.yml' + - '.github/workflows/linter.yml' + + pull_request: + branches: [ master ] + +jobs: + Ubuntu: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install required packages + run: | + sudo apt update -y + sudo apt install -y git make tree + sudo apt install -y python3-twisted python3-requests python3-simplejson python3-urllib3 + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1 + sudo update-alternatives --install /usr/bin/twistd twistd /usr/bin/twistd3 1 + - name: Check PYTHON environment + run: | + which python + python --version + which twistd + twistd --version + - name: Configuration + run: | + make init + make vars + - name: Build + run: | + sudo make install + - name: Environment Check + run: make exist + diff --git a/.gitignore b/.gitignore index 2adaeb4..66a635d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ site-template/recsync.conf /modules/RELEASE.*.local /modules/Makefile.local /*Top/configure/*.local +*.swp +.rs_local_pid +*.local diff --git a/README.md b/README.md index 9e6693d..ac7f962 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,76 @@ # RecSync-env - -![RecSync-env installation test](https://github.com/ChannelFinder/RecSync-env/workflows/RecSync-env%20installation%20test/badge.svg) -![Docker Image CI](https://github.com/ChannelFinder/RecSync-env/workflows/Docker%20Image%20CI/badge.svg) -![Linter Run](https://github.com/ChannelFinder/RecSync-env/workflows/Linter%20Run/badge.svg) +[![Debian 11](https://github.com/jeonghanlee/RecSync-env/actions/workflows/debian11.yml/badge.svg)](https://github.com/jeonghanlee/RecSync-env/actions/workflows/debian11.yml) +[![Ubuntu latest](https://github.com/jeonghanlee/RecSync-env/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/jeonghanlee/RecSync-env/actions/workflows/ubuntu.yml) +[![Rocky8](https://github.com/jeonghanlee/RecSync-env/actions/workflows/rocky8.yml/badge.svg)](https://github.com/jeonghanlee/RecSync-env/actions/workflows/rocky8.yml) +[![Linter Run](https://github.com/jeonghanlee/RecSync-env/actions/workflows/linter.yml/badge.svg)](https://github.com/jeonghanlee/RecSync-env/actions/workflows/linter.yml) +[![Docker](https://github.com/jeonghanlee/RecSync-env/actions/workflows/docker.yml/badge.svg)](https://github.com/jeonghanlee/RecSync-env/actions/workflows/docker.yml) Configuration Environment for the recsync server (aka. RecCeiver) at -## Role - -In order to download, install, setup all relevant components, one should do many steps manually. This repository was designed for the easy-to-reproducible environment for recsync server (aka RecCeiver). - -## Requirements +## Pre-required Packages -* ChannelFinder : Please check it -* systemd service : this repository has its own systemd configuration. -* `SUDO` permission -* Few system packages : Please see below. We **will** use the system default python packages and system package manager (e.g., apt for Debian) instead of `conda`, `pip`, or whatever python tools, because we would like to install `RecCeiver` in a specific local directory instead of any Python related paths. This approach gives users, who may not be familiar with many Python environments, to focus only `RecCeiver`. I am sure that users should learn million different and continuous evolving Python environments later if one would like to use it within them. -* pyCFClient : In order to integrate `RecCeiver` with ChannelFinder, pyCFClient Python application [1] or package is required. The repository [1] was already integrated into the current repository. Thus one doesn't need to care about it. - -### system packages +``` +git make sudo tree +``` -Note that `sqlite3` may not be necessary if one would like to test it with ChannelFinder directly. +## Debian 11 -* Debian 10 +We may need to tune the default python version as `python3` ```bash -sudo apt install sqlite3 python-twisted python-requests python-simplejson python-urllib3 +make install.p3deb ``` -* CentOS 7 - -```bash -sudo yum install sqlite python-twisted-web python-requests python2-simplejson python-urllib3 ``` - -* CentOS 8 - -```bash -sudo dnf install sqlite python3-twisted python-requests-futures python3-simplejson python3-urllib3 -sudo update-alternatives --set python /usr/bin/python3 +make init +make conf +make conf.show +make install +make sd_start +make sd_status ``` -* Fedora 31 -```bash -sudo dnf install sqlite python3-twisted python-requests-futures python3-simplejson python3-urllib3 +``` +make init +make local.conf +make local.conf.show +make local.install +make exist +make local.run +make local.stop +make local.status ``` -### Python - -* Debian 10 +## macOS -```bash -Python 2.7.16 (default, Oct 10 2019, 22:02:15) -[GCC 8.3.0] on linux2 -``` +We only support macOS for testing and developing purposes, so we don't have launchd configuration. We localize the recsync service within a local folder, and define several simple Makefile rules to maintain them. +To use the following rules, one need to setup `homebrew` first. -* Fedora 31 +* Install Python3 and its required packages through `pip3` ```bash -$ python -Python 3.8.2 (default, Feb 28 2020, 00:00:00) -[GCC 10.0.1 20200216 (Red Hat 10.0.1-0.8)] on linux +make install.p3mac ``` -## Few Makefile Rules - -### `make` +* Installation and running procedures -* Print out selected rules with a little explanation - -### `make init` - -* Download recsync [2] and pyCFClient [1] -* Switch to specific versions defined as `$(SRC1_TAG)` for recsync and `$(SRC2_TAG)` for pyCFClinet in `configure/RELEASE` - -### `make install` - -* `sudo` permission is required. -* Add a user `recceiver` and a group id `65534` into a host system. Note that `nogroup` is valid only for Debian. -* Copy all files in `recsync/server` and `pyCFClient` into defined a local installation path `INSTALL_LOCATION` in `configure/RELEASE` -* Setup and enable systemd service - -### `make distclean` - -* Remove the downloaded recsync [2] and pyCFClient [1] source files. - -### `make vars` - -* Print out interesting variables -* One can use `make PRINT.VARIABLE_NAME` to print out them. For example, `make PRINT.INSTALL_LOCATION`. - -## A typical example to configure the ChannelFinder service - -Note that this example has the assumption which ES service is running. - -```bash +``` make init -make install -sudo systemctl start recsync.service -systemctl status recsync.service +make conf +make conf.show +make local.install +make exist +make local.run +make local.stop ``` -## Customize site-specific configuration - -Please consult two files in `configure` path, such as `RELEASE` and `CONFIG_SITE`. There are few comments on there. If you are familiar with the standard EPICS building system [3], it should be easy to understand them, because we mimic that concept into this repository. +The log file will be located in `RS_INSTALL_LOCATION`, e.g., `$(TOP)/recsync.local` folder, which can be checked through `make local.status`. And one can remove all local directory through `make local.rm` ## Docker Image -See [docs/Docker.md](docs/Docker.md) :whale: +* The Docker image is hosted at https://hub.docker.com/orgs/alscontrols. +* See [docs/Docker.md](docs/Docker.md) :whale: ## While evaluating its configuration @@ -120,12 +82,6 @@ sudo systemctl start recsync.service systemctl status recsync.service ``` -## Notice - -* If one installs this at the first time, or reinstall from scratch, for example, `make restart`, one has to start its systemd service one more time, because of the issue mentioned in . - -* There are two important configuration files, which are configured carefully. One is `site-template/recsync.conf.in` and the other is `site-template/channelfinderapi.conf`. Especially, one should use the same and correct information in `channelfinderapi.conf` in order to match with its ChannelFinder configuration. For example, user name and its password should be matched with . - ## Reference [1] diff --git a/configure/CONFIG_COMMON b/configure/CONFIG_COMMON index 4c42655..741e8bb 100644 --- a/configure/CONFIG_COMMON +++ b/configure/CONFIG_COMMON @@ -1,3 +1,4 @@ + # CF_PRTO:=http CF_HOST:=localhost @@ -9,7 +10,7 @@ CF_PASSWD:=1234 # # -RS_ADDR_LIST:=127.255.255.255:5049 +RS_ADDR_LIST:=127.255.255.255:5049, 10.255.255.255:5049 # These allow developers to override the variable -include $(TOP)/../CONFIG_COMMON.local diff --git a/configure/CONFIG_SITE b/configure/CONFIG_SITE index 06549c1..2d78695 100644 --- a/configure/CONFIG_SITE +++ b/configure/CONFIG_SITE @@ -1,20 +1,35 @@ # # ### channelfinder installation location -RS_INSTALL_LOCATION=/opt/RecSync +RS_INSTALL_PATH=/opt +RS_INSTALL_LOCATION=$(RS_INSTALL_PATH)/recsync # # # -RS_CFG_FILE:=recsync.conf -RS_CFG_FILE_IN:=$(RS_CFG_FILE).in +RECSYNC_CONF:=recsync.conf # ### CF Properties for DB info tag -CF_PROPERTIES:=archive elemName elemType elemField devName handle area sector +RS_CFG_LOGLEVEL=WARN +RS_BIND_ADDR=0.0.0.0:45722 +RS_PROCS_CHAIN=cf +RS_ANNOUNCE_INTERVAL=15 +RS_TCPTIMEOUT=15.0 +RS_COMMIT_INTERVAL=5 +RS_MAXACTIVE=20 +RS_CONF_INFOTAGS:=archive elemName elemType elemField devName handle area sector +# Do not forget to enclose them with " ". +RS_CONF_ENV_VARS:=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory +RS_CONF_ALIAS:=on +RS_CONF_RECORDTYPE:=on +RS_CONF_RECORDDESC:=on # # -### Default TWISD path and its options -TWISD_PATH:=/usr/bin +### Default TWISTD path and its options +TWISTD_PATH:=/usr/local/bin + +# +CFAPI_CONF:=channelfinderapi.conf SYSTEMD_PATH:=/etc/systemd/system # @@ -28,10 +43,26 @@ RS_USERID:=recceiver ### nfsgroup is valid for CentOS ### Both has 65534 gid, ### Do not change it if one doesn't know what could be done properly. -GROUPID:=65534 +RS_GROUPID:=65534 # # +RS_SITE_TEMPLATE_PATH=$(TOP)/site-template + + +# SYSTEDM Required and After Service List +# This is After and Required services for the systemd archiver appliance systemd service. +# mariadb.service was defined in there, but sometimes, we need to check our directories where +# our data will be saved. +# one can check the mounting service name through `systemctl list-units --type=mount` +# Here is the example for the ALS environment +# CONFIG_SITE.local can be used to hold this information locally +# Each service need one space between them, and backslash must be double backslash +RS_SYSTEMD_SERVICES:=channelfinder.service + +# If you want to run this as a user level systemd service +# You can set this to: --user +RS_SYSTEMD_USER:= # These allow developers to override the CONFIG_SITE variable # settings without having to modify the configure/CONFIG_SITE diff --git a/configure/CONFIG_SRC b/configure/CONFIG_SRC index f36b54c..c0db56c 100644 --- a/configure/CONFIG_SRC +++ b/configure/CONFIG_SRC @@ -24,7 +24,6 @@ INIT_SRC2 = 1 endif # # -RS_SITE_TEMPLATE_PATH:=$(TOP)/site-template RS_SYSTEMD_FILENAME:=recsync.service # # @@ -34,3 +33,9 @@ VARS_EXCLUDES+=INSTALL_PROGRAM VARS_EXCLUDES+=INSTALL_DATA # # + +# These allow developers to override the CONFIG_SRC variable +# settings without having to modify the configure/CONFIG_SRC +# file itself. +-include $(TOP)/../CONFIG_SRC.local +-include $(TOP)/configure/CONFIG_SRC.local diff --git a/configure/CONFIG_VARS b/configure/CONFIG_VARS index 6279c5a..2e2214a 100644 --- a/configure/CONFIG_VARS +++ b/configure/CONFIG_VARS @@ -9,8 +9,13 @@ RS_SRC_GITURL:=$(CF_SRC_URL)/$(RS_SRC_NAME) ### SRC_PATH used for a local directory which is a clone git repository RS_SRC_PATH:=$(RS_SRC_NAME)-src # +#DOCURL:=https://docs.payara.fish/community/docs/$(SRC_VERSION)/README.html +DOCURL1:=$(RS_SRC_GITURL) + # -PY_CF_SRC_GITURL:=$(CF_SRC_URL)/$(PY_CF_SRC_NAME) +PY_CF_SRC_GITURL:=$(PY_CF_SRC_URL)/$(PY_CF_SRC_NAME) ### SRC_PATH used for a local directory which is a clone git repository PY_CF_SRC_PATH:=$(PY_CF_SRC_NAME)-src # +DOCURL2:=$(PY_CF_SRC_GITURL) + diff --git a/configure/RELEASE b/configure/RELEASE index 314dc0a..8e560f7 100644 --- a/configure/RELEASE +++ b/configure/RELEASE @@ -4,22 +4,22 @@ CF_SRC_URL:=https://github.com/ChannelFinder RS_SRC_NAME:=recsync ### Which the source tag / branch / hash id would like to use -RS_SRC_TAG:=ae7f476 +# 2022-05-17 +RS_SRC_TAG:=32a49d1 ### Placeholder for the site-specific version control RS_SRC_VERSION:=$(RS_SRC_TAG) # # ### Where the Source repository SRC2_URL/SRC2_NAME +PY_CF_SRC_URL:=$(CF_SRC_URL) PY_CF_SRC_NAME:=pyCFClient ### Which the source tag / branch / hash id would like to use +# 2019-03-04 PY_CF_SRC_TAG:=9689d5b ### Placeholder for the site-specific version control PY_CF_SRC_VERSION:=$(PY_CF_SRC_TAG) # # - - - -include $(TOP)/../RELEASE.local -include $(TOP)/configure/RELEASE.local diff --git a/configure/RULES b/configure/RULES index 8915579..c75a7dc 100644 --- a/configure/RULES +++ b/configure/RULES @@ -1,12 +1,18 @@ +vpath %.local $(TOP)/configure +vpath %.in $(RS_SITE_TEMPLATE_PATH) +vpath %.in $(RS_SITE_TEMPLATE_PATH)/systemd +vpath %.services $(RS_SITE_TEMPLATE_PATH)/systemd + # include $(TOP)/configure/RULES_FUNC -# +include $(TOP)/configure/RULES_REQ include $(TOP)/configure/RULES_SRC -# include $(TOP)/configure/RULES_INSTALL -# +include $(TOP)/configure/RULES_RUN +include $(TOP)/configure/RULES_SYSTEMD include $(TOP)/configure/RULES_DOCKER -# +include $(TOP)/configure/RULES_PROPERTIES +include $(TOP)/configure/RULES_CI include $(TOP)/configure/RULES_VARS # diff --git a/configure/RULES_CI b/configure/RULES_CI new file mode 100644 index 0000000..1b7cc6d --- /dev/null +++ b/configure/RULES_CI @@ -0,0 +1,18 @@ +.PHONY: conf.macos conf.macbrew + + +conf.macos: conf.macbrew +conf.macos.show: conf.macbrew + + +conf.macbrew: + $(QUIET)echo ">>> Generating $(TOP)/configure/CONFIG_SITE.local" + $(QUIET)echo "TWISTD_PATH=/opt/homebrew/bin" > $(TOP)/configure/CONFIG_SITE.local + $(QUIET)echo "RS_INSTALL_LOCATION:=$(TOP)/recsync.local" >> $(TOP)/configure/CONFIG_SITE.local + $(QUIET)echo "RS_USERID:=${USER}" >> $(TOP)/configure/CONFIG_SITE.local + $(QUIET)echo "RS_GROUPID:=admin" >> $(TOP)/configure/CONFIG_SITE.local + $(QUIET)cat -b $(TOP)/configure/CONFIG_SITE.local + +conf.macbrew.show: + cat -b $(TOP)/configure/CONFIG_SITE.local + diff --git a/configure/RULES_DOCKER b/configure/RULES_DOCKER index d73a442..2094841 100644 --- a/configure/RULES_DOCKER +++ b/configure/RULES_DOCKER @@ -1,29 +1,18 @@ -.PHONY: install.docker docker.src_preinst build.docker prune.docker +.PHONY: install.docker build.docker prune.docker # Docker internal install rule # twisted will be installed later, so we have to keep dropin.cache in $(RS_INSTALL_LOCATION) first # we will move it later within Dockfile # -install.docker: docker.src_preinst +install.docker: conf $(QUIET)$(INSTALL) -d $(RS_INSTALL_LOCATION) - $(QUIET)cp -r $(RS_SRC_PATH)/server/recceiver/ $(RS_INSTALL_LOCATION)/ - $(QUIET)cp -r $(RS_SRC_PATH)/server/twisted/ $(RS_INSTALL_LOCATION)/ - $(QUIET)cp -r $(PY_CF_SRC_PATH)/channelfinder/ $(RS_INSTALL_LOCATION)/ - $(QUIET)$(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE) $(RS_INSTALL_LOCATION)/ - $(QUIET)$(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf $(RS_INSTALL_LOCATION)/ - $(QUIET)$(INSTALL) -m 755 -b $(RS_SITE_TEMPLATE_PATH)/dropin.cache $(RS_INSTALL_LOCATION)/ - $(QUIET)$(INSTALL_DATA) -b $(RS_SITE_TEMPLATE_PATH)/.versions $(RS_INSTALL_LOCATION)/ -# $(QUIET)chown -R $(RS_USERID):$(GROUPID) $(RS_INSTALL_LOCATION) - -docker.src_preinst: src_versions -# $(QUIET)bash $(RS_SITE_TEMPLATE_PATH)/recceiver.postinst "configure" "$(RS_USERID)" "$(GROUPID)" - $(QUIET)sed -e "s:@CF_PROPERTIES@:$(CF_PROPERTIES):g" \ - -e "s/@RS_ADDR_LIST@/$(RS_ADDR_LIST)/g" \ - < $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE_IN) > $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE) - $(QUIET)sed -e "s|@CF_FULL_URL@|$(CF_FULL_URL)|g" \ - -e "s:@CF_USER@:$(CF_USER):g" \ - -e "s:@CF_PASSWD@:$(CF_PASSWD):g" \ - < $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf.in > $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf + $(QUIET)cp -r $(RS_SRC_PATH)/server/recceiver $(RS_INSTALL_LOCATION)/ + $(QUIET)cp -r $(RS_SRC_PATH)/server/twisted $(RS_INSTALL_LOCATION)/ + $(QUIET)cp -r $(PY_CF_SRC_PATH)/channelfinder $(RS_INSTALL_LOCATION)/ + $(QUIET)$(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(RECSYNC_CONF) $(RS_INSTALL_LOCATION)/ + $(QUIET)$(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(CFAPI_CONF) $(RS_INSTALL_LOCATION)/ + $(QUIET)$(INSTALL) -m 755 -b $(RS_SITE_TEMPLATE_PATH)/dropin.cache $(RS_INSTALL_LOCATION)/ + $(QUIET)$(INSTALL_DATA) -b $(RS_SITE_TEMPLATE_PATH)/.versions $(RS_INSTALL_LOCATION)/ build.docker: distclean $(QUIET) bash $(TOP)/docker/scripts/docker_builder.bash -a "RS_INSTALL_LOCATION=$(RS_INSTALL_LOCATION)" -a "CF_PORT_HTTP=$(CF_PORT)" diff --git a/configure/RULES_INSTALL b/configure/RULES_INSTALL index 228fb24..b12922f 100644 --- a/configure/RULES_INSTALL +++ b/configure/RULES_INSTALL @@ -1,101 +1,55 @@ # # -.PHONY: sd_config sd_install sd_status sd_start sd_stop sd_restart sd_clean sd_enable sd_disable -# -# -sd_config: - $(QUIET)sed -e "s:_PYTHONPATH_:$(RS_INSTALL_LOCATION):g" \ - -e "s:_TWISDPATH_:$(TWISD_PATH):g" \ - -e "s:_CONFIGFILE_:$(RS_CFG_FILE):g" \ - -e "s:_USERID_:$(RS_USERID):g" \ - -e "s:_GROUPID_:$(GROUPID):g" \ - < $(RS_SITE_TEMPLATE_PATH)/rs.service.in > $(RS_SITE_TEMPLATE_PATH)/$(RS_SYSTEMD_FILENAME) -# -# -sd_install: sd_config - $(QUIET)$(SUDO) $(INSTALL_DATA) -b $(RS_SITE_TEMPLATE_PATH)/$(RS_SYSTEMD_FILENAME) $(SYSTEMD_PATH)/ - $(QUIET)$(SUDO) systemctl daemon-reload -# -# -sd_status: - $(QUIET) systemctl status -l $(RS_SYSTEMD_FILENAME) | cat -b -# -# -sd_start: - $(QUIET)$(SUDO) systemctl start $(RS_SYSTEMD_FILENAME) -# -# We ignore its error -sd_stop: - -$(QUIET)$(SUDO) systemctl stop $(RS_SYSTEMD_FILENAME) -# -# -sd_restart: - $(QUIET)$(SUDO) systemctl restart $(RS_SYSTEMD_FILENAME) -# -# We ignore its error -sd_clean: - -$(QUIET)$(SUDO) systemctl disable $(RS_SYSTEMD_FILENAME) - -$(QUIET)$(SUDO) rm -f $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME) -# -# -sd_enable: - $(if $(wildcard $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)), $(SUDO) systemctl enable $(RS_SYSTEMD_FILENAME)) -# -# -sd_disable: - $(if $(wildcard $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)), $(SUDO) systemctl disable $(RS_SYSTEMD_FILENAME)) -# -# -.PHONY: src_install src_preinst src_versions src_postrm install uninstall restart - -src_install: src_preinst - $(QUIET)$(SUDO) $(INSTALL) --owner=$(RS_USERID) --group=$(GROUPID) -d $(RS_INSTALL_LOCATION) - $(QUIET)$(SUDO) cp -r $(RS_SRC_PATH)/server/recceiver/ $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) cp -r $(RS_SRC_PATH)/server/twisted/ $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) cp -r $(PY_CF_SRC_PATH)/channelfinder/ $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) $(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE) $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) $(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) $(INSTALL) -m 755 -b $(RS_SITE_TEMPLATE_PATH)/dropin.cache $(RS_INSTALL_LOCATION)/twisted/plugins/ - $(QUIET)$(SUDO) $(INSTALL_DATA) -b $(RS_SITE_TEMPLATE_PATH)/.versions $(RS_INSTALL_LOCATION)/ - $(QUIET)$(SUDO) chown -R $(RS_USERID):$(GROUPID) $(RS_INSTALL_LOCATION) - $(QUIET) rm -f $(RS_SITE_TEMPLATE_PATH)/.versions - -src_preinst: src_versions - $(QUIET)$(SUDO) bash $(RS_SITE_TEMPLATE_PATH)/recceiver.postinst "configure" "$(RS_USERID)" "$(GROUPID)" - $(QUIET)sed -e "s:@CF_PROPERTIES@:$(CF_PROPERTIES):g" \ - -e "s/@RS_ADDR_LIST@/$(RS_ADDR_LIST)/g" \ - < $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE_IN) > $(RS_SITE_TEMPLATE_PATH)/$(RS_CFG_FILE) - $(QUIET)sed -e "s|@CF_FULL_URL@|$(CF_FULL_URL)|g" \ - -e "s:@CF_USER@:$(CF_USER):g" \ - -e "s:@CF_PASSWD@:$(CF_PASSWD):g" \ - < $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf.in > $(RS_SITE_TEMPLATE_PATH)/channelfinderapi.conf - +.PHONY: rs_status rs_start rs_stop rs_restart rs_install rs_uninstall rs_preinst rs_postrm src_install src_uninstall install uninstall restart + +rs_status: sd_status + +rs_start: sd_start -src_versions: - $(QUIET)echo "Timestamps : $$(date +%Y%m%d-%H%M%S)/YYYYMMDD-HHMMSS" > $(RS_SITE_TEMPLATE_PATH)/.versions - $(QUIET)echo "- SRC1 URL : $(RS_SRC_GITURL)" >> $(RS_SITE_TEMPLATE_PATH)/.versions - $(QUIET)echo "- SRC1 VER : $(RS_SRC_TAG)" >> $(RS_SITE_TEMPLATE_PATH)/.versions - $(QUIET)echo "- SRC2 URL : $(PY_CF_SRC_GITURL)" >> $(RS_SITE_TEMPLATE_PATH)/.versions - $(QUIET)echo "- SRC2 VER : $(PY_CF_SRC_TAG)" >> $(RS_SITE_TEMPLATE_PATH)/.versions +rs_stop: sd_stop -src_postrm: - $(QUIET)$(SUDO) bash $(RS_SITE_TEMPLATE_PATH)/recceiver.postrm "purge" "$(RS_USERID)" +rs_restart: sd_restart + +# Pure source file installation, USRID/GROUPID must be defined +rs_install: conf + $(QUIET)$(SUDO) $(INSTALL) -d $(RS_INSTALL_LOCATION) -o $(RS_USERID) -g $(RS_GROUPID) + $(QUIET)$(SUDO) cp -r $(RS_SRC_PATH)/server/recceiver $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) cp -r $(RS_SRC_PATH)/server/twisted $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) cp -r $(PY_CF_SRC_PATH)/channelfinder $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) $(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(RECSYNC_CONF) $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) $(INSTALL) -m 400 -b $(RS_SITE_TEMPLATE_PATH)/$(CFAPI_CONF) $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) $(INSTALL) -m 755 -b $(RS_SITE_TEMPLATE_PATH)/dropin.cache $(RS_INSTALL_LOCATION)/twisted/plugins/ + $(QUIET)$(SUDO) $(INSTALL_DATA) -b $(RS_SITE_TEMPLATE_PATH)/.versions $(RS_INSTALL_LOCATION)/ + $(QUIET)$(SUDO) chown -R $(RS_USERID):$(RS_GROUPID) $(RS_INSTALL_LOCATION) + + +rs_uninstall: + $(QUIET)$(SUDO) rm -rf $(RS_INSTALL_LOCATION) + +# Linux Default USERID/GROUPID configure first, and call rs_install +src_install: rs_preinst rs_install + +src_uninstall: rs_uninstall rs_postrm + +rs_preinst: + $(QUIET)$(SUDO) bash $(RS_SITE_TEMPLATE_PATH)/recceiver.postinst "configure" "$(RS_USERID)" "$(RS_GROUPID)" + +rs_postrm: + $(QUIET)$(SUDO) bash $(RS_SITE_TEMPLATE_PATH)/recceiver.postrm "purge" "$(RS_USERID)" ## Install recsync : add user/group, install all, setup and enable service -install: src_install sd_install sd_enable +install: rs_preinst rs_install sd_install sd_enable $(QUIET)echo "----- Note that one should start it and check its status via " $(QUIET)echo "----- sudo systemctl start $(RS_SYSTEMD_FILENAME) or make sd_start" $(QUIET)echo "----- systemctl status $(RS_SYSTEMD_FILENAME) or make sd_status" ## Uninstall RecSync : remove user/group, stop, clean service, remove all -uninstall: sd_stop sd_disable sd_clean src_postrm +uninstall: sd_stop sd_disable sd_clean rs_postrm $(QUIET)$(SUDO) rm -rf $(RS_INSTALL_LOCATION) -reinstall: install +reinstall: conf install ## Restart all from scratch. -restart: uninstall reinstall sd_start sd_status - $(QUIET)echo "----- Note that one should start it again and check its status via " - $(QUIET)echo "----- sudo systemctl start $(RS_SYSTEMD_FILENAME) or make sd_start" - $(QUIET)echo "----- systemctl status $(RS_SYSTEMD_FILENAME) or make sd_status" +restart: uninstall reinstall rs_start rs_status + diff --git a/configure/RULES_PROPERTIES b/configure/RULES_PROPERTIES new file mode 100644 index 0000000..f8323b6 --- /dev/null +++ b/configure/RULES_PROPERTIES @@ -0,0 +1,66 @@ + +properties_RULES_NAMES:=recsync cfapi versions +conf_properties_RULES:=$(addprefix conf., $(properties_RULES_NAMES)) +show_properties_RULES:=$(addsuffix .show, $(conf_properties_RULES)) + +RULES_VARS+=conf.rsproperties conf.rsproperties.show + +.PHONY: conf conf.rsproperties conf.localconf + +conf: conf.rsproperties conf.versions + +conf.show: conf.rsproperties.show conf.versions.show + +conf.local: conf.localconf conf + +conf.localconf: + $(QUIET)echo "RS_INSTALL_LOCATION:=$(TOP)/recsync.local" > $(TOP)/configure/CONFIG_SITE.local + $(QUIET)echo "RS_USERID:=${USER}" >> $(TOP)/configure/CONFIG_SITE.local + $(QUIET)echo "RS_GROUPID:=1000" >> $(TOP)/configure/CONFIG_SITE.local + +conf.local.show: conf.show + cat -b $(TOP)/configure/CONFIG_SITE.local + +conf.rsproperties: $(conf_properties_RULES) + +conf.rsproperties.show: $(show_properties_RULES) + +conf.recsync: $(RECSYNC_CONF).in + $(QUIET)echo ">>> Generate $(basename $<) from $<" + $(QUIET)sed -e "s|@RS_CFG_LOGLEVEL@|$(RS_CFG_LOGLEVEL)|g" \ + -e "s|@RS_ADDR_LIST@|$(RS_ADDR_LIST)|g" \ + -e "s|@RS_BIND_ADDR@|$(RS_BIND_ADDR)|g" \ + -e "s|@RS_PROCS_CHAIN@|$(RS_PROCS_CHAIN)|g" \ + -e "s|@RS_ANNOUNCE_INTERVAL@|$(RS_ANNOUNCE_INTERVAL)|g" \ + -e "s|@RS_TCPTIMEOUT@|$(RS_TCPTIMEOUT)|g" \ + -e "s|@RS_COMMIT_INTERVAL@|$(RS_COMMIT_INTERVAL)|g" \ + -e "s|@RS_MAXACTIVE@|$(RS_MAXACTIVE)|g" \ + -e "s|@RS_CONF_INFOTAGS@|$(RS_CONF_INFOTAGS)|g" \ + -e "s|@RS_CONF_ENV_VARS@|$(RS_CONF_ENV_VARS)|g" \ + -e "s|@RS_CONF_ALIAS@|$(RS_CONF_ALIAS)|g" \ + -e "s|@RS_CONF_RECORDTYPE@|$(RS_CONF_RECORDTYPE)|g" \ + -e "s|@RS_CONF_RECORDDESC@|$(RS_CONF_RECORDDESC)|g" \ + < $< > $(basename $<) + +conf.recsync.show: $(RECSYNC_CONF).in + cat -b $(basename $<) + +conf.cfapi: $(CFAPI_CONF).in + $(QUIET)echo ">>> Generate $(basename $<) from $<" + $(QUIET)sed -e "s|@CF_FULL_URL@|$(CF_FULL_URL)|g" \ + -e "s|@CF_USER@|$(CF_USER)|g" \ + -e "s|@CF_PASSWD@|$(CF_PASSWD)|g" \ + < $< > $(basename $<) + +conf.cfapi.show: $(CFAPI_CONF).in + cat -b $(basename $<) + +conf.versions: + $(QUIET)echo "Timestamps : $$(date +%Y%m%d-%H%M%S)/YYYYMMDD-HHMMSS" > $(RS_SITE_TEMPLATE_PATH)/.versions + $(QUIET)echo "- SRC1 URL : $(RS_SRC_GITURL)" >> $(RS_SITE_TEMPLATE_PATH)/.versions + $(QUIET)echo "- SRC1 VER : $(RS_SRC_TAG)" >> $(RS_SITE_TEMPLATE_PATH)/.versions + $(QUIET)echo "- SRC2 URL : $(PY_CF_SRC_GITURL)" >> $(RS_SITE_TEMPLATE_PATH)/.versions + $(QUIET)echo "- SRC2 VER : $(PY_CF_SRC_TAG)" >> $(RS_SITE_TEMPLATE_PATH)/.versions + +conf.versions.show: + cat -b $(RS_SITE_TEMPLATE_PATH)/.versions diff --git a/configure/RULES_REQ b/configure/RULES_REQ new file mode 100644 index 0000000..b24aa9a --- /dev/null +++ b/configure/RULES_REQ @@ -0,0 +1,37 @@ + + +rs_RULES_NAMES:=p3mac p3deb +install_rs_RULES:=$(addprefix install., $(es_RULES_NAMES)) +setup_rs_RULES:=$(addprefix setup., $(es_RULES_NAMES)) +remove_rs_RULES:=$(addprefix remove., $(es_RULES_NAMES)) +show_rs_RULES:=$(addprefix show., $(es_RULES_NAMES)) + +.PHONY: + +#https://www.elastic.co/guide/en/elasticsearch/reference/current/release-notes-8.2.0.html + + +# Debian 11 + +setup.p3deb: install.p3deb + +setup.p3mac: install.p3mac + + +# macOS aarch64 +install.p3mac: + $(QUIET) brew install python@3.10 + $(QUIET) /opt/homebrew/bin/pip3 install twisted simplejson urllib3 requests + +show.p3mac: + $(QUIET) brew info python@3.10 + + +install.p3deb: + $(QUIET) sudo apt install -y python3 + $(QUIET) sudo pip3 install twisted simplejson urllib3 requests + +show.p3deb: + $(QUIET) apt info python3 + + diff --git a/configure/RULES_RUN b/configure/RULES_RUN new file mode 100644 index 0000000..857e715 --- /dev/null +++ b/configure/RULES_RUN @@ -0,0 +1,22 @@ +# +local_RULES_NAMES:=install run stop rm status conf conf.show +local_properties_RULES:=$(addprefix local., $(local_RULES_NAMES)) + +RS_PID_LOCAL:=$(TOP)/.rs_local_pid + +local.conf: conf.local + +local.conf.show: conf.local.show + +local.install: rs_install + +local.run: + $(QUIET) PYTHONPATH=$(RS_INSTALL_LOCATION) $(TWISTD_PATH)/twistd --logfile=$(RS_INSTALL_LOCATION)/recsync.log --rundir=$(RS_INSTALL_LOCATION) --pidfile=$(RS_PID_LOCAL) --reactor=poll recceiver -f $(RS_INSTALL_LOCATION)/$(RECSYNC_CONF) + +local.stop: + $(QUIET)-pkill -F $(RS_PID_LOCAL) + +local.rm: rs_uninstall + +local.status: + cat -b $(RS_INSTALL_LOCATION)/recsync.log diff --git a/configure/RULES_SYSTEMD b/configure/RULES_SYSTEMD new file mode 100644 index 0000000..17d303b --- /dev/null +++ b/configure/RULES_SYSTEMD @@ -0,0 +1,76 @@ +# +# +.PHONY: sd_install sd_status sd_start sd_stop sd_restart sd_clean sd_enable sd_disable +# +# + +systemd_RULES_NAMES:=systemd0 +conf_systemd_RULES:=$(addprefix conf., $(systemd_RULES_NAMES)) +show_systemd_RULES:=$(addsuffix .show, $(conf_systemd_RULES)) +install_systemd_RULES:=$(addprefix install., $(systemd_RULES_NAMES)) +show_install_systemd_RULES:=$(addsuffix .show, $(install_systemd_RULES)) + +sd_install: conf.systemd install.systemd + $(QUIET)$(SUDO) systemctl $(RS_SYSTEMD_USER) daemon-reload + +.PHONY: conf.systemd conf.systemd.show + +conf.systemd: $(conf_systemd_RULES) + +conf.systemd.show: $(show_systemd_RULES) + +install.systemd: $(install_systemd_RULES) + +install.systemd.show: $(show_install_systemd_RULES) + +conf.systemd0: $(RS_SYSTEMD_FILENAME).in + $(QUIET)echo ">>> Generate $(basename $<) from $<" + $(QUIET)echo ">>> $(RS_SYSTEMD_SERVICES)" + $(QUIET)sed -e "s|@DOCURL1@|$(DOCURL1)|g" \ + -e "s|@DOCURL2@|$(DOCURL2)|g" \ + -e 's|@SYSTEMD_SERVICES@|$(RS_SYSTEMD_SERVICES)|g' \ + -e "s|@USERID@|$(RS_USERID)|g" \ + -e "s|@GROUPID@|$(RS_GROUPID)|g" \ + -e "s|@RS_INSTALL_LOCATION@|$(RS_INSTALL_LOCATION)|g" \ + -e "s|@TWISTD_PATH@|$(TWISTD_PATH)|g" \ + -e "s|@RECSYNC_CONF@|$(RECSYNC_CONF)|g" \ + < $< > $(basename $<) + +conf.systemd0.show: $(RS_SYSTEMD_FILENAME).in + @cat -b $(basename $<) + +install.systemd0: $(RS_SYSTEMD_FILENAME).in + $(QUIET)$(SUDO) $(INSTALL_DATA) -b $(basename $<) $(SYSTEMD_PATH)/ + +install.systemd0.show: + $(QUIET)cat -b $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME) +# +# +sd_status: + $(QUIET) systemctl status $(RS_SYSTEMD_USER) -l $(RS_SYSTEMD_FILENAME) | cat -b + +# +sd_start: + $(QUIET)$(SUDO) systemctl start $(RS_SYSTEMD_USER) $(RS_SYSTEMD_FILENAME) +# +# We ignore its error +sd_stop: + -$(QUIET)$(SUDO) systemctl stop $(RS_SYSTEMD_USER) $(RS_SYSTEMD_FILENAME) +# +# +sd_restart: + $(QUIET)$(SUDO) systemctl restart $(RS_SYSTEMD_USER) $(RS_SYSTEMD_FILENAME) +# +# We ignore its error +sd_clean: + $(if $(wildcard $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)), $(QUIET)$(SUDO) rm -f $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)) +# +# +sd_enable: + $(if $(wildcard $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)), $(SUDO) systemctl enable $(RS_SYSTEMD_USER) $(RS_SYSTEMD_FILENAME)) +# +# +sd_disable: + $(if $(wildcard $(SYSTEMD_PATH)/$(RS_SYSTEMD_FILENAME)), $(SUDO) systemctl disable $(RS_SYSTEMD_USER) $(RS_SYSTEMD_FILENAME)) +# +# diff --git a/configure/RULES_VARS b/configure/RULES_VARS index 47bbc81..85b4ca3 100644 --- a/configure/RULES_VARS +++ b/configure/RULES_VARS @@ -1,9 +1,16 @@ +RULES_VARS+=$(foreach v, $(filter %_RULES,$(.VARIABLES)), $(v)) +RULES_VARS+=$(foreach v, $(filter %_RULES_NAMES,$(.VARIABLES)), $(v)) + VARS_EXCLUDES+=.SHELLSTATUS -VARS_EXCLUDES+=$(filter INIT_SRC%, $(.VARIABLES)) -VARS_EXCLUDES+=$(filter SRC%_URL, $(.VARIABLES)) -VARS_EXCLUDES+=$(filter SRC%_NAME, $(.VARIABLES)) -VARS_EXCLUDES+=SITE_TEMPLATE_PATH -#VARS_EXCLUDES+=CF_% +VARS_EXCLUDES+=INIT_SRC +VARS_EXCLUDES+=FILTER +VARS_EXCLUDES+=LEVEL +VARS_EXCLUDES+=$(filter JAR_%, $(.VARIABLES)) +VARS_EXCLUDES+=$(RULES_VARS) +VARS_EXCLUDES+=%_RULES_VARS +VARS_EXCLUDES+=RULES_VARS +VARS_EXCLUDES+=a_service_BUIDER buildrules_BUILDER + VARS_EXCLUDES+=AS_% VARS_EXCLUDES+=OG_% VARS_EXCLUDES+=PS_% @@ -15,11 +22,15 @@ VARS_EXCLUDES+=CF_USER VARS_EXCLUDES+=CF_SRC_URL VARS_EXCLUDES+=CF_PRTO VARS_EXCLUDES+=CF_URL -VARS_EXCLUDES+=CF_FULL_URL +VARS_EXCLUDES+=LSOPTS -LEVEL?=1 +.PHONY: $(RULES_VARS) + +LEVEL?=1 FILTER?=1 +LSOPTS?="-lta" + ifeq "$(FILTER)" "1" SRC_VARIABLES:=$(sort $(filter-out $(VARS_EXCLUDES) VARS_EXCLUDES,$(.VARIABLES))) @@ -27,8 +38,6 @@ else SRC_VARIABLES:=$(filter $(FILTER)%, $(sort $(filter-out $(VARS_EXCLUDES) VARS_EXCLUDES,$(.VARIABLES)))) endif -SRC_VARIABLES+=CF_PROPERTIES - .PHONY : env vars header env: vars @@ -52,13 +61,24 @@ print-%: $(QUIET)echo $* = $($*) $(QUIET)echo $*\'s origin is $(origin $*) +ls.%: + $(QUIET) ls $(LSOPTS) $($*) + +tree.%: + $(QUIET) tree -aL $(LEVEL) $($*) + +cat.%: + $(QUIET) cat -b $($*) + FORCE: +.PHONY : exist + exist: ifeq (, $(shell which tree)) $(if $(wildcard $(RS_INSTALL_LOCATION)), @ ls -d $(RS_INSTALL_LOCATION) && find $(RS_INSTALL_LOCATION)/ -maxdepth $(LEVEL) | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/:---\1/") else - $(if $(wildcard $(RS_INSTALL_LOCATION)), tree -aL $(LEVEL) $(RS_INSTALL_LOCATION), $(QUIET)echo "No $(RS_INSTALL_LOCATION)") + $(if $(wildcard $(RS_INSTALL_LOCATION)), tree -pugaL $(LEVEL) $(RS_INSTALL_LOCATION), $(QUIET)echo "No $(RS_INSTALL_LOCATION)") endif @@ -66,4 +86,3 @@ endif .NOTPARALLEL: -VARS_EXCLUDES+=FILTER diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 120000 index 45cc04d..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -Dockerfile.alpine \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..12c55bd --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,89 @@ +# +# author : Jeong Han Lee +# email : jeonghan.lee@gmail.com +# date : Thu Sep 22 21:40:08 PDT 2022 +# version : 0.0.3 + +## builder : 28.4MB +FROM alpine:3.16 AS builder +ENV WorkPath /home/RecSync-env +ARG RS_SERVER_PORT=5075 +ARG RS_PORT_BROADCAST=5076 +ARG RS_INSTALL_LOCATION=/opt/recsync +ARG CF_PORT_HTTP=8080 +ARG RS_BIND_PORT=45722 + +# We can check the package availbilities through docker run -t -i --entrypoint /bin/sh alpine:3.16 +RUN apk --no-cache add bash git make tree + +WORKDIR $WorkPath +COPY . . +RUN echo "CF_PORT:=${CF_PORT_HTTP}" > configure/CONFIG_COMMON.local +RUN echo "RS_INSTALL_LOCATION:=${RS_INSTALL_LOCATION}" > configure/CONFIG_SITE.local +RUN make distclean && \ + make init && \ + make install.docker + +## Multi-Stages build : 124MB (buster-slim : 166MB) +FROM alpine:3.16 +LABEL maintainer="Jeong Han Lee " + +ARG BUILD_DATE +ARG BUILD_VERSION +ARG RS_SERVER_PORT=5075 +ARG RS_PORT_BROADCAST=5076 +ARG RS_INSTALL_LOCATION=/opt/recsync +ARG CF_PORT_HTTP=8080 +ARG RS_BIND_PORT=45722 +ARG TZ=America/Los_Angeles + +# Labels. +LABEL org.label-schema.schema-version="1.0" +LABEL org.label-schema.build-date=$BUILD_DATE +LABEL org.label-schema.name="alscontrols/recsync" +LABEL org.label-schema.description="EPICS RecSync Server (RecCeiver) Docker Image" +LABEL org.label-schema.url="https://github.com/ChannelFinder/RecSync-env/" +LABEL org.label-schema.version=$BUILD_VERSION +LABEL org.label-schema.docker.cmd="docker run --network=host --detach --rm --name=recsync alscontrols/recsync:latest" + +### RecCeiver PORT / Installation location configuration. +ENV RS_SERVER_PORT $RS_SERVER_PORT +ENV RS_PORT_BROADCAST $RS_PORT_BROADCAST +ENV RS_INSTALL_LOCATION $RS_INSTALL_LOCATION +ENV CF_PORT_HTTP $CF_PORT_HTTP +ENV RS_BIND_PORT $RS_BIND_PORT +ENV PYTHONPATH $RS_INSTALL_LOCATION +# +# +### YOUR TIME ZONE +ENV TZ $TZ +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +### Install minimal packages for RecSync with alpine +## Python 3.8.3-r0 in alpine 3.12, we can reduce the image size of 85.2MB, but it doesn't work due to +## imcompatiblities in py3-requests +## RUN apk add --no-cache bash py3-twisted py3-simplejson py3-urllib3 py3-setuptools py3-requests +### Even if Python2, apk install a lot of Python3 packages, so we reduce the size only 43MB +RUN apk add --no-cache bash py3-twisted py3-simplejson py3-urllib3 py3-requests py3-setuptools tzdata + +WORKDIR ${RS_INSTALL_LOCATION} +COPY --from=builder $RS_INSTALL_LOCATION . +COPY --from=builder $RS_INSTALL_LOCATION/dropin.cache ./twisted/plugins/ +#RUN rm -f $RS_INSTALL_LOCATION/dropin.cache +## +# CF Port : http +EXPOSE $CF_PORT_HTTP/tcp +EXPOSE $CF_PORT_HTTP/udp +# RecCeiver Broadcast Port +EXPOSE $RS_PORT_BROADCAST/udp +# RecCeiver Server Port +EXPOSE $RS_SERVER_PORT/udp +# +EXPOSE $RS_BIND_PORT/tcp +EXPOSE $RS_BIND_PORT/udp +# +COPY ./docker/scripts/entrypoint.sh /entrypoint.sh +# First run is necessary, because of the following error +# /usr/bin/twistd: The specified reactor cannot be used, failed with error: reactor already installed. +# The latest version do not need this. RUN /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine deleted file mode 100644 index 86907b5..0000000 --- a/docker/Dockerfile.alpine +++ /dev/null @@ -1,89 +0,0 @@ -# -# author : Jeong Han Lee -# email : jeonghan.lee@gmail.com -# date : Wednesday, July 1 15:39:00 PDT 2020 -# version : 0.0.2 - -## builder : 28.4MB -FROM alpine:3.12 AS builder -ENV WorkPath /home/RecSyn-env - -ARG RS_SERVER_PORT=5075 -ARG RS_PORT_BROADCAST=5076 -ARG RS_INSTALL_LOCATION=/opt/recsync -ARG CF_PORT_HTTP=8080 -ARG RS_BIND_PORT=45722 - -RUN apk --no-cache add bash git make - -WORKDIR $WorkPath -COPY . . -RUN echo "CF_PORT:=${CF_PORT_HTTP}" > configure/CONFIG_COMMON.local -RUN echo "RS_INSTALL_LOCATION:=${RS_INSTALL_LOCATION}" > configure/CONFIG_SITE.local -RUN make distclean && \ - make init && \ - make install.docker - -## Multi-Stages build : 124MB (buster-slim : 166MB) -FROM alpine:3.12 -LABEL maintainer="Jeong Han Lee " - -ARG BUILD_DATE -ARG BUILD_VERSION -ARG RS_SERVER_PORT=5075 -ARG RS_PORT_BROADCAST=5076 -ARG RS_INSTALL_LOCATION=/opt/recsync -ARG CF_PORT_HTTP=8080 -ARG RS_BIND_PORT=45722 -ARG TZ=America/Los_Angeles - -# Labels. -LABEL org.label-schema.schema-version="1.0" -LABEL org.label-schema.build-date=$BUILD_DATE -LABEL org.label-schema.name="jeonghanlee/recsync" -LABEL org.label-schema.description="EPICS RecSync Server (RecCeiver) Docker Image" -LABEL org.label-schema.url="https://github.com/ChannelFinder/RecSync-env/" -LABEL org.label-schema.version=$BUILD_VERSION -LABEL org.label-schema.docker.cmd="docker run --network=host --detach --rm --name=recsync jeonghanlee/recsync:tagname" - -### RecCeiver PORT / Installation location configuration. -ENV RS_SERVER_PORT $RS_SERVER_PORT -ENV RS_PORT_BROADCAST $RS_PORT_BROADCAST -ENV RS_INSTALL_LOCATION $RS_INSTALL_LOCATION -ENV CF_PORT_HTTP $CF_PORT_HTTP -ENV RS_BIND_PORT $RS_BIND_PORT -ENV PYTHONPATH $RS_INSTALL_LOCATION -# -# -### YOUR TIME ZONE -ENV TZ $TZ -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -### Install minimal packages for RecSync with alpine -## Python 3.8.3-r0 in alpine 3.12, we can reduce the image size of 85.2MB, but it doesn't work due to -## imcompatiblities in py3-requests -## RUN apk add --no-cache bash py3-twisted py3-simplejson py3-urllib3 py3-setuptools py3-requests -### Even if Python2, apk install a lot of Python3 packages, so we reduce the size only 43MB -RUN apk add --no-cache bash py-twisted py-simplejson py-urllib3 py2-setuptools py-requests tzdata - -WORKDIR ${RS_INSTALL_LOCATION} -COPY --from=builder $RS_INSTALL_LOCATION . -COPY --from=builder $RS_INSTALL_LOCATION/dropin.cache ./twisted/plugins/ -#RUN rm -f $RS_INSTALL_LOCATION/dropin.cache -## -# CF Port : http -EXPOSE $CF_PORT_HTTP/tcp -EXPOSE $CF_PORT_HTTP/udp -# RecCeiver Broadcast Port -EXPOSE $RS_PORT_BROADCAST/udp -# RecCeiver Server Port -EXPOSE $RS_SERVER_PORT/udp -# -EXPOSE $RS_BIND_PORT/tcp -EXPOSE $RS_BIND_PORT/udp -# -COPY ./docker/scripts/entrypoint.sh /entrypoint.sh -# First run is necessary, because of the following error -# /usr/bin/twistd: The specified reactor cannot be used, failed with error: reactor already installed. -RUN /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/Dockerfile.bluster-slim b/docker/old/Dockerfile.bluster-slim similarity index 100% rename from docker/Dockerfile.bluster-slim rename to docker/old/Dockerfile.bluster-slim diff --git a/site-template/recceiver.postinst b/site-template/recceiver.postinst index 7876158..988cd2d 100644 --- a/site-template/recceiver.postinst +++ b/site-template/recceiver.postinst @@ -25,7 +25,7 @@ if [ "$1" = "configure" ]; then fi echo "Adding user ${USERID} with ${GROUPID}." useradd --system --home-dir / -g ${GROUPID} \ - --no-create-home --shell /usr/sbin/nologin ${USERID} > /dev/null 2>&1 + --no-create-home --shell /usr/sbin/nologin "${USERID}" > /dev/null 2>&1 else echo "${USERID} exists." fi diff --git a/site-template/recceiver.postrm b/site-template/recceiver.postrm index aebbf11..e14625d 100644 --- a/site-template/recceiver.postrm +++ b/site-template/recceiver.postrm @@ -16,7 +16,7 @@ if [ "$1" = "purge" ]; then USERID="$2" if grep -q "^${USERID}:" /etc/passwd; then echo "Removing user ${USERID} ... " - userdel ${USERID} || echo "WARNING: problem removing user ${USERID}" + userdel "${USERID}" || echo "WARNING: problem removing user ${USERID}" else echo "${USERID} doesn't exist" fi diff --git a/site-template/recsync.conf.in b/site-template/recsync.conf.in index c4248c2..d5603d1 100644 --- a/site-template/recsync.conf.in +++ b/site-template/recsync.conf.in @@ -1,7 +1,7 @@ [recceiver] # Logging detail level. Use python logging level name. -loglevel = WARN +loglevel = @RS_CFG_LOGLEVEL@ # list of broadcast address:port with comma ',' seperated. # a broadcast address in the same subnet where RecCeiver runs : 127.255.255.255 @@ -21,31 +21,40 @@ addrList = @RS_ADDR_LIST@ # Default uses wildcard address and a random port. # 45722 is the randomly selected port # -bind = 0.0.0.0:45722 +bind = @RS_BIND_ADDR@ # Processing chain -procs = cf +procs = @RS_PROCS_CHAIN@ # Time interval for sending recceiver advertisments -# announceInterval = 15.0 +announceInterval = @RS_ANNOUNCE_INTERVAL@ # Idle Timeout for TCP connections. -# tcptimeout = 15.0 +tcptimeout = @RS_TCPTIMEOUT@ # Time to wait before commiting updates # Doesn't effect IOC clients -# commitInterval = 5.0 +commitInterval = @RS_COMMIT_INTERVAL@ # Maximum concurrent "active" clients # to allow. -#maxActive = 20 +maxActive = @RS_MAXACTIVE@ # The channelFinder client is configuration information is # stored in channelfinderapi.conf as described in the client [cf] # a space-separated list of infotags to set as CF Properties -infotags = @CF_PROPERTIES@ -alias = on - +infotags = @RS_CONF_INFOTAGS@ +# List environment variables that should be written as channel finder properties +# +# Comma-separated list of VARIABLE:PropertyName, +# specifying which environment VARIABLEs to pass on to the channel finder +# and defining the corresponding PropertyName +# environment_vars=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory +# Turn on optional alias and recordType properties +environment_vars=@RS_CONF_ENV_VARS@ +alias = @RS_CONF_ALIAS@ +recordType = @RS_CONF_RECORDTYPE@ +recordDesc = @RS_CONF_RECORDDESC@ # EOF diff --git a/site-template/rs.service.in b/site-template/systemd/recsync.service.in similarity index 58% rename from site-template/rs.service.in rename to site-template/systemd/recsync.service.in index dccc545..60e7876 100644 --- a/site-template/rs.service.in +++ b/site-template/systemd/recsync.service.in @@ -1,20 +1,19 @@ [Unit] Description=RecSync Service -Documentation=https://github.com/ChannelFinder/recsync/tree/master/server -Documentation=https://github.com/ChannelFinder/pyCFClient -After=network.target channelfinder.service -Requires=channelfinder.service +Documentation=@DOCURL1@ +Documentation=@DOCURL2@ +After=network.target @SYSTEMD_SERVICES@ +Requires=@SYSTEMD_SERVICES@ [Service] - # # Twistd also has the options, but we use the systemd one instead. # -User=_USERID_ -Group=_GROUPID_ +User=@USERID@ +Group=@GROUPID@ # Everything in a local, so we have to tell where PYTHONPATH is -Environment="PYTHONPATH=_PYTHONPATH_" +Environment="PYTHONPATH=@RS_INSTALL_LOCATION@" # Due to User/Group permission, we cannot generate the recsync.log # in /var/log/ folder. So we put in into the recsync installation @@ -22,11 +21,11 @@ Environment="PYTHONPATH=_PYTHONPATH_" # generated. However, we don't need it, since systemd service will # take care of this. # -ExecStart=_TWISDPATH_/twistd --logfile=_PYTHONPATH_/recsync.log \ - --rundir _PYTHONPATH_ \ +ExecStart=@TWISTD_PATH@/twistd --logfile=@RS_INSTALL_LOCATION@/recsync.log \ + --rundir=@RS_INSTALL_LOCATION@ \ --pidfile= \ --reactor=poll \ - --nodaemon recceiver -f _PYTHONPATH_/_CONFIGFILE_ + --nodaemon recceiver -f @RS_INSTALL_LOCATION@/@RECSYNC_CONF@ Restart=always RestartSec=10s