diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9148d550..7abaaae41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,9 +7,8 @@ on: pull_request: branches: - 'master' - - '0.9' - - '0.10' - - '0.10.*' + - '0.10-develop' + - '0.11-develop' env: GITHUB_TOKEN: ${{ secrets.COVERALLS_TOKEN }} diff --git a/misc/config/jasmind.environment b/misc/config/jasmind.environment new file mode 100644 index 000000000..be324ae88 --- /dev/null +++ b/misc/config/jasmind.environment @@ -0,0 +1,2 @@ +JCLI_USERNAME='jcliadmin' +JCLI_PASSWORD='jclipwd' diff --git a/misc/config/systemd/jasmin-celery.service b/misc/config/systemd/jasmin-celery.service index 4cca55aad..94ba6ba85 100644 --- a/misc/config/systemd/jasmin-celery.service +++ b/misc/config/systemd/jasmin-celery.service @@ -9,7 +9,7 @@ SyslogIdentifier=jasmin-celery PIDFile=/run/jasmin-celery.pid User=jasmin Group=jasmin -ExecStart=/bin/sh -c "celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3" +ExecStart=/bin/sh -c "/opt/jasmin-sms-gateway/venv/bin/celery -A jasmin.protocols.rest.tasks worker -l INFO -c 4 --autoscale=10,3" [Install] WantedBy=multi-user.target diff --git a/misc/config/systemd/jasmin-dlrd.service b/misc/config/systemd/jasmin-dlrd.service index c0e6f0e49..ab68f19cb 100644 --- a/misc/config/systemd/jasmin-dlrd.service +++ b/misc/config/systemd/jasmin-dlrd.service @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-dlrd PIDFile=/run/jasmin-dlrd.pid User=jasmin Group=jasmin -ExecStart=/usr/local/bin/dlrd.py +ExecStart=/opt/jasmin-sms-gateway/venv/bin/dlrd.py [Install] WantedBy=multi-user.target diff --git a/misc/config/systemd/jasmin-dlrlookupd.service b/misc/config/systemd/jasmin-dlrlookupd.service index 6e58dbf37..d7e8c70d0 100644 --- a/misc/config/systemd/jasmin-dlrlookupd.service +++ b/misc/config/systemd/jasmin-dlrlookupd.service @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-dlrlookupd PIDFile=/run/jasmin-dlrlookupd.pid User=jasmin Group=jasmin -ExecStart=/usr/local/bin/dlrlookupd.py +ExecStart=/opt/jasmin-sms-gateway/venv/bin/dlrlookupd.py [Install] WantedBy=multi-user.target diff --git a/misc/config/systemd/jasmin-interceptord.service b/misc/config/systemd/jasmin-interceptord.service index e9162bfa4..86314f0fd 100644 --- a/misc/config/systemd/jasmin-interceptord.service +++ b/misc/config/systemd/jasmin-interceptord.service @@ -9,7 +9,7 @@ SyslogIdentifier=interceptord PIDFile=/run/interceptord.pid User=jasmin Group=jasmin -ExecStart=/usr/local/bin/interceptord.py +ExecStart=/opt/jasmin-sms-gateway/venv/bin/interceptord.py [Install] WantedBy=multi-user.target diff --git a/misc/config/systemd/jasmin-restapi.service b/misc/config/systemd/jasmin-restapi.service index c209c7472..ae1fbe240 100644 --- a/misc/config/systemd/jasmin-restapi.service +++ b/misc/config/systemd/jasmin-restapi.service @@ -8,7 +8,7 @@ SyslogIdentifier=jasmin-restapi PIDFile=/run/jasmin-restapi.pid User=jasmin Group=jasmin -ExecStart=/bin/sh -c "twistd3 -n --pidfile=/tmp/twistd-web-restapi.pid web --wsgi=jasmin.protocols.rest.api" +ExecStart=/bin/sh -c "/opt/jasmin-sms-gateway/venv/bin/twistd -n --pidfile=/tmp/twistd-web-restapi.pid web --wsgi=jasmin.protocols.rest.api --listen=tcp:1402" [Install] WantedBy=multi-user.target diff --git a/misc/config/systemd/jasmind.service b/misc/config/systemd/jasmind.service index 21cbd73e9..e87d6ac26 100644 --- a/misc/config/systemd/jasmind.service +++ b/misc/config/systemd/jasmind.service @@ -8,7 +8,8 @@ SyslogIdentifier=jasmind PIDFile=/run/jasmind.pid User=jasmin Group=jasmin -ExecStart=/usr/local/bin/jasmind.py --username jcliadmin --password jclipwd +ExecStart=/opt/jasmin-sms-gateway/venv/bin/jasmind.py --enable-interceptor-client +EnvironmentFile=/etc/jasmin/jasmind.environment [Install] WantedBy=multi-user.target diff --git a/misc/packaging/scripts/common-postinstall.sh b/misc/packaging/scripts/common-postinstall.sh index 4f37e217d..3ad11f9e9 100755 --- a/misc/packaging/scripts/common-postinstall.sh +++ b/misc/packaging/scripts/common-postinstall.sh @@ -3,35 +3,57 @@ set -e JASMIN_USER="jasmin" JASMIN_GROUP="jasmin" +JASMIN_VENV_DIR="/opt/jasmin-sms-gateway" +JASMIN_CFG_STORAGE="/var/log/jasmin" +JASMIN_LOG_DIR="/etc/jasmin/store" PACKAGE_NAME="jasmin-sms-gateway" PYPI_NAME="jasmin" +function create_dir { + if [ ! -d ${1} ] + then + mkdir ${1} + chown -R "${JASMIN_USER}:${JASMIN_GROUP}" ${1} + fi +} + +# Provision user/group +getent group ${JASMIN_GROUP} || groupadd -r "${JASMIN_GROUP}" +grep -q "^${JASMIN_USER}:" /etc/passwd || useradd -r -g ${JASMIN_GROUP} \ + -d ${JASMIN_VENV_DIR} -s /sbin/nologin \ + -c "Jasmin SMS Gateway user" ${JASMIN_USER} + +# If there is any VENV from previous version, just remove it (configs are safe in /etc ) - we do not want any conflicts +if [ -d ${JASMIN_VENV_DIR} ] +then + rm -rf ${JASMIN_VENV_DIR} +fi + +# Create empty directories +create_dir ${JASMIN_CFG_STORAGE} +create_dir ${JASMIN_LOG_DIR} +create_dir ${JASMIN_VENV_DIR} + +# Find latest installed python version available on system +LATEST_PYTHON="$(find /usr/bin/ -maxdepth 1 -regex '.*python3\.[0-9]+' | sort --version-sort | tail -n 1)" +# LATEST_PYTHON="$(basename ${LATEST_PYTHON})" # Not needed + # Get installed package version and install the related pypi package(s) if [ "$(grep -Ei 'debian|buntu' /etc/*release)" ]; then - PACKAGE_VERSION=$(dpkg -s "$PACKAGE_NAME"|grep ^Version:|awk '{print $2}') - pip3 install "$PYPI_NAME"=="$PACKAGE_VERSION" -elif [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then - PACKAGE_VERSION=$(rpm -qi "$PACKAGE_NAME"|grep ^Version|awk {'print $3'}) - pip3 install "$PYPI_NAME"=="$PACKAGE_VERSION" + PACKAGE_VERSION=$(dpkg -s "${PACKAGE_NAME}"|grep ^Version:|awk -F '[- ]' '{print $2}' | sort --version-sort | tail -n 1) +elif [ "$(grep -Ei 'centos|rhel|fedora|almalinux' /etc/*release)" ]; then + PACKAGE_VERSION=$(rpm -qi "${PACKAGE_NAME}"|grep ^Version|awk {'print $3'} | sort --version-sort | tail -n 1) else echo "ERROR: Unsupported OS for this package." exit 1 fi -# Provision user/group -getent group $JASMIN_GROUP || groupadd -r "$JASMIN_GROUP" -grep -q "^${JASMIN_USER}:" /etc/passwd || useradd -r -g $JASMIN_GROUP \ - -d /usr/share/jasmin -s /sbin/nologin \ - -c "Jasmin SMS Gateway user" $JASMIN_USER - -# Create empty directories -mkdir /etc/jasmin/store -mkdir /var/log/jasmin - -# Change owner of required folders -chown -R "$JASMIN_USER:$JASMIN_GROUP" /etc/jasmin/store/ -chown -R "$JASMIN_USER:$JASMIN_GROUP" /var/log/jasmin +# Create VENV and install jasmin and all dependencies from pipy into that VENV +# sudo -u jasmin virtualenv -p ${LATEST_PYTHON} ${JASMIN_VENV_DIR}/venv +sudo -u "${JASMIN_USER}" ${LATEST_PYTHON} -m venv ${JASMIN_VENV_DIR}/venv +source ${JASMIN_VENV_DIR}/venv/bin/activate +sudo -u "${JASMIN_USER}" ${JASMIN_VENV_DIR}/venv/bin/pip install "${PYPI_NAME}"=="${PACKAGE_VERSION}" if [ "$1" = configure ]; then # Enable jasmind service @@ -39,8 +61,3 @@ if [ "$1" = configure ]; then /bin/systemctl enable jasmind fi -# python3-falcon package is not available in centos/rhel 8 -# this is a workaround -if [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then - pip3 install falcon==2.0.0 -fi diff --git a/misc/packaging/scripts/common-preremove.sh b/misc/packaging/scripts/common-preremove.sh index 295dee0dd..8b1fdee0f 100755 --- a/misc/packaging/scripts/common-preremove.sh +++ b/misc/packaging/scripts/common-preremove.sh @@ -2,16 +2,12 @@ set -e PYPI_NAME="jasmin" - -pip3 uninstall -y "$PYPI_NAME" +JASMIN_VENV_DIR="/opt/jasmin-sms-gateway/" # Stop and disable jasmind service /bin/systemctl stop jasmind /bin/systemctl disable jasmind /bin/systemctl daemon-reload -# python3-falcon package is not available in centos/rhel 8 -# this is a workaround -if [ "$(grep -Ei 'centos|rhel|fedora' /etc/*release)" ]; then - pip3 uninstall -y falcon==2.0.0 -fi +# Remove whole VENV whe jasmin lives +rm -rf "${JASMIN_VENV_DIR}" diff --git a/nfpm.yaml b/nfpm.yaml index d5dec1a84..54f4783f7 100644 --- a/nfpm.yaml +++ b/nfpm.yaml @@ -1,5 +1,5 @@ name: "jasmin-sms-gateway" -arch: "amd64" +arch: "all" platform: "linux" version: "v0.11.1" section: "default" @@ -35,16 +35,21 @@ provides: contents: - src: ./misc/config/jasmin.cfg dst: "/etc/jasmin/jasmin.cfg" - type: config + type: config|noreplace - src: ./misc/config/interceptor.cfg dst: "/etc/jasmin/interceptor.cfg" - type: config + type: config|noreplace - src: ./misc/config/dlr.cfg dst: "/etc/jasmin/dlr.cfg" - type: config + type: config|noreplace + - src: ./misc/config/jasmind.environment + dst: "/etc/jasmin/jasmind.environment" + type: config|noreplace + file_info: + mode: 0660 - src: ./misc/config/dlrlookupd.cfg dst: "/etc/jasmin/dlrlookupd.cfg" - type: config + type: config|noreplace - src: ./misc/config/resource/amqp0-9-1.xml dst: "/etc/jasmin/resource/amqp0-9-1.xml" type: config @@ -53,80 +58,34 @@ contents: type: config - src: ./misc/config/systemd/jasmind.service dst: "/usr/lib/systemd/system/jasmind.service" - type: config - src: ./misc/config/systemd/jasmin-celery.service dst: "/usr/lib/systemd/system/jasmin-celery.service" - type: config - src: ./misc/config/systemd/jasmin-dlrd.service dst: "/usr/lib/systemd/system/jasmin-dlrd.service" - type: config - src: ./misc/config/systemd/jasmin-dlrlookupd.service dst: "/usr/lib/systemd/system/jasmin-dlrlookupd.service" - type: config - src: ./misc/config/systemd/jasmin-interceptord.service dst: "/usr/lib/systemd/system/jasmin-interceptord.service" - type: config - src: ./misc/config/systemd/jasmin-restapi.service dst: "/usr/lib/systemd/system/jasmin-restapi.service" - type: config - - src: ./jasmin/bin/jasmind.py - dst: "/usr/local/bin/jasmind.py" - - src: ./jasmin/bin/interceptord.py - dst: "/usr/local/bin/interceptord.py" - - src: ./jasmin/bin/dlrd.py - dst: "/usr/local/bin/dlrd.py" - - src: ./jasmin/bin/dlrlookupd.py - dst: "/usr/local/bin/dlrlookupd.py" scripts: - postinstall: ./misc/packaging/scripts/common-postinstall.sh preremove: ./misc/packaging/scripts/common-preremove.sh +rpm: + scripts: + posttrans: ./misc/packaging/scripts/common-postinstall.sh overrides: deb: + scripts: + postinstall: ./misc/packaging/scripts/common-postinstall.sh depends: - python3 (>= 3.8) - adduser - - python3-twisted - - python3-dateutil - - python3-pyparsing - - python3-lockfile - - python3-requests - - python3-setuptools - - python3-mimeparse - - python3-celery - - python-celery-common - - python3-falcon - - python3-redis - - python3-amqp - - python3-tabulate - - python3-treq - # These dependencies come from Jookies package repository - - python3-jookies-messaging - - python3-txredisapi - - python3-txamqp3 - - python3-smpp-pdu3 - - python3-smpp-twisted3 + - python3-venv + - sudo + # All dependecies all installed to VENV via pip rpm: depends: - - epel-release - - python3 (>= 3.8) - - python3-twisted - - python3-dateutil - - python3-pyparsing - - python3-lockfile - - python3-requests - - python3-setuptools - - python3-mimeparse - - python3-celery - - python3-redis - - python3-amqp - - python3-tabulate - - python3-treq - # These dependencies come from Jookies package repository - - python3-jookies-messaging - - python3-txredisapi - - python3-txamqp3 - - python3-smpp-pdu3 - - python3-smpp-twisted3 - # There's no python3-falcon package for CentOS/RHEL 8 - # It will be handled by the pre/post scripts - #- python3-falcon + - python(abi) >= 3.8 + - sudo + # All dependecies all installed to VENV via pip + # Dependecy on epel-release removed - it's not needed on most RHEL version and you might have your own EPEL clone or another source for packages