From a0a1361888a3986d589720a7eb39d49c913154f2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 19 Jun 2019 03:51:59 +0300 Subject: Refactor pleroma_ctl copying to a generic function for copying files into the release dir --- rel/files/bin/pleroma_ctl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 rel/files/bin/pleroma_ctl (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl new file mode 100755 index 000000000..ac7339762 --- /dev/null +++ b/rel/files/bin/pleroma_ctl @@ -0,0 +1,26 @@ +#!/bin/sh +# XXX: This should be removed when elixir's releases get custom command support +if [ -z "$1" ] || [ "$1" = "help" ]; then + echo "Usage: $(basename "$0") COMMAND [ARGS] + + The known commands are: + + create Create database schema (needs to be executed only once) + migrate Execute database migrations (needs to be done after updates) + rollback [VERSION] Rollback database migrations (needs to be done before downgrading) + + and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is + equivalent to \`$(basename "$0") user COMMAND\` + + By default pleroma_ctl will try calling into a running instance to execute non migration-related commands, + if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable +" +else + SCRIPT=$(readlink -f "$0") + SCRIPTPATH=$(dirname "$SCRIPT") + if [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then + "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")' + else + "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$*"'")' + fi +fi -- cgit v1.2.3 From 66f2cdcdb07b358c53e4c8d4f01bfe80da5883a7 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 19 Jun 2019 14:53:16 +0300 Subject: pleroma_ctl: add an update command Closes #988 and #1004 --- rel/files/bin/pleroma_ctl | 100 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 4 deletions(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index ac7339762..671fd3860 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -1,13 +1,102 @@ #!/bin/sh # XXX: This should be removed when elixir's releases get custom command support + +detect_flavour() { + arch="$(arch)" + if [ "$arch" = "x86_64" ]; then + arch="amd64" + elif [ "$arch" = "armv7l" ]; then + arch="arm" + elif [ "$arch" = "aarch64" ]; then + arch="arm64" + else + echo "Unsupported arch: $arch" >&2 + exit 1 + fi + + if getconf GNU_LIBC_VERSION >/dev/null; then + libc_postfix="" + elif [ "$(ldd 2>&1 | head -c 9)" = "musl libc" ]; then + libc_postfix="-musl" + elif [ "$(find /lib/libc.musl* | wc -l)" ]; then + libc_postfix="-musl" + else + echo "Unsupported libc" >&2 + exit 1 + fi + + echo "$arch$libc_postfix" +} + +detect_branch() { + version="$(cut -d' ' -f2 <"$RELEASE_ROOT"/releases/start_erl.data)" + branch="$(echo "$version" | cut -d'-' -f 4)" + if [ "$branch" = "develop" ]; then + echo "develop" + elif [ "$branch" = "" ]; then + echo "master" + else + echo "Releases are built only for master and develop branches" >&2 + exit 1 + fi +} +update() { + set -e + RELEASE_ROOT=$(dirname "$SCRIPTPATH") + uri="${PLEROMA_CTL_URI:-https://git.pleroma.social}" + project_id="${PLEROMA_CTL_PROJECT_ID:-2}" + project_branch="$(detect_branch)" + flavour="${PLEROMA_CTL_ARCH:-$(detect_flavour)}" + echo "Detected flavour: $flavour" + tmp="${PLEROMA_CTL_TMP_DIR:-/tmp}" + artifact="$tmp/pleroma.zip" + full_uri="${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}" + echo "Downloading the artifact from ${full_uri} to ${artifact}" + curl "$full_uri" -o "${artifact}" + echo "Unpacking ${artifact} to ${tmp}" + unzip -q "$artifact" -d "$tmp" + echo "Copying files over to $RELEASE_ROOT" + if [ "$1" != "--no-rm" ]; then + rm -r "${RELEASE_ROOT:-?}"/* + fi + cp -rf "$tmp/release"/* "$RELEASE_ROOT" + echo "Removing temporary files" + rm -r "$tmp/release" + rm "$artifact" + echo "Done! Please refer to the changelog/release notes for changes and update instructions" + set +e +} + if [ -z "$1" ] || [ "$1" = "help" ]; then + # TODO: Just list the commands on `pleroma_ctl help` and output help for the individual command on `pleroma_ctl help $COMMAND` echo "Usage: $(basename "$0") COMMAND [ARGS] The known commands are: - create Create database schema (needs to be executed only once) - migrate Execute database migrations (needs to be done after updates) - rollback [VERSION] Rollback database migrations (needs to be done before downgrading) + create + Create database schema (needs to be executed only once) + + migrate + Execute database migrations (needs to be done after updates) + + rollback [VERSION] + Rollback database migrations (needs to be done before downgrading) + + update [OPTIONS] + Update the instance using the latest CI artifact for the current branch. + + The only supported option is --no-rm, when set the script won't delete the whole directory, but + just force copy over files from the new release. This wastes more space, but may be useful if + some files are stored inside of the release directories (although you really shouldn't store them + there), or if you want to be able to quickly revert a broken update. + + The script will try to detect your architecture and ABI automatically, but if it is wrong, you can + overwrite it by setting PLEROMA_CTL_ARCH to the desired architecture. + + By default the artifact will be downloaded from https://git.pleroma.social for pleroma/pleroma (project id: 2) + to /tmp/, you can overwrite these settings by setting PLEROMA_CTL_URI, PLEROMA_CTL_PROJECT_ID and PLEROMA_CTL_TMP_DIR + respectievly. + and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is equivalent to \`$(basename "$0") user COMMAND\` @@ -18,7 +107,10 @@ if [ -z "$1" ] || [ "$1" = "help" ]; then else SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") - if [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then + + if [ "$1" = "update" ]; then + update "$2" + elif [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")' else "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$*"'")' -- cgit v1.2.3 From 2571e07fbae39728c6edacaab484e44975200b33 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 19 Jun 2019 14:59:12 +0300 Subject: pleroma_ctl: Rename arch to flavour because it also includes the libc --- rel/files/bin/pleroma_ctl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index 671fd3860..03b7e57bb 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -46,7 +46,7 @@ update() { uri="${PLEROMA_CTL_URI:-https://git.pleroma.social}" project_id="${PLEROMA_CTL_PROJECT_ID:-2}" project_branch="$(detect_branch)" - flavour="${PLEROMA_CTL_ARCH:-$(detect_flavour)}" + flavour="${PLEROMA_CTL_FLAVOUR:-$(detect_flavour)}" echo "Detected flavour: $flavour" tmp="${PLEROMA_CTL_TMP_DIR:-/tmp}" artifact="$tmp/pleroma.zip" @@ -90,8 +90,8 @@ if [ -z "$1" ] || [ "$1" = "help" ]; then some files are stored inside of the release directories (although you really shouldn't store them there), or if you want to be able to quickly revert a broken update. - The script will try to detect your architecture and ABI automatically, but if it is wrong, you can - overwrite it by setting PLEROMA_CTL_ARCH to the desired architecture. + The script will try to detect your architecture and ABI and set a flavour automatically, + but if it is wrong, you can overwrite it by setting PLEROMA_CTL_FLAVOUR to the desired flavour. By default the artifact will be downloaded from https://git.pleroma.social for pleroma/pleroma (project id: 2) to /tmp/, you can overwrite these settings by setting PLEROMA_CTL_URI, PLEROMA_CTL_PROJECT_ID and PLEROMA_CTL_TMP_DIR -- cgit v1.2.3 From 0e31d195af89551e58070390f74e917c5d1ce0fc Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 20 Jun 2019 08:12:56 +0000 Subject: Apply suggestion to rel/files/bin/pleroma_ctl --- rel/files/bin/pleroma_ctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index 03b7e57bb..62368115e 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -95,7 +95,7 @@ if [ -z "$1" ] || [ "$1" = "help" ]; then By default the artifact will be downloaded from https://git.pleroma.social for pleroma/pleroma (project id: 2) to /tmp/, you can overwrite these settings by setting PLEROMA_CTL_URI, PLEROMA_CTL_PROJECT_ID and PLEROMA_CTL_TMP_DIR - respectievly. + respectively. and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is -- cgit v1.2.3 From e3e8a7dc0e0f3d3abde90c93a0650e7188d13b12 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 20 Jun 2019 18:27:17 +0300 Subject: Disable rpc for instance gen --- rel/files/bin/pleroma_ctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index 62368115e..b0e1874a9 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -110,7 +110,7 @@ else if [ "$1" = "update" ]; then update "$2" - elif [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then + elif [ "$1" = "migrate" ] || [ "$1" = "rollback" ] || [ "$1" = "create" ] || [ "$1 $2" = "instance gen" ] || [ -n "$PLEROMA_CTL_RPC_DISABLED" ]; then "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$*"'")' else "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$*"'")' -- cgit v1.2.3 From 38a803a1f86b459d193aa234d00b1af3895edab1 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 05:00:41 +0300 Subject: Add a systemd service for OTP releases --- rel/files/installation/pleroma.service | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 rel/files/installation/pleroma.service (limited to 'rel/files') diff --git a/rel/files/installation/pleroma.service b/rel/files/installation/pleroma.service new file mode 100644 index 000000000..e47cf58dc --- /dev/null +++ b/rel/files/installation/pleroma.service @@ -0,0 +1,36 @@ +[Unit] +Description=Pleroma social network +After=network.target postgresql.service nginx.service + +[Service] +KillMode=process +Restart=on-failure + +; Name of the user that runs the Pleroma service. +User=pleroma + +; Make sure that all paths fit your installation. +; Path to the home directory of the user running the Pleroma service. +Environment="HOME=/opt/pleroma" +; Path to the folder containing the Pleroma installation. +WorkingDirectory=/opt/pleroma +; Path to the Pleroma binary. +ExecStart=/opt/pleroma/bin/pleroma start +ExecStop=/opt/pleroma/bin/pleroma stop + +; Some security directives. +; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops. +PrivateTmp=true +; The /home, /root, and /run/user folders can not be accessed by this service anymore. If your Pleroma user has its home folder in one of the restricted places, or use one of these folders as its working directory, you have to set this to false. +ProtectHome=true +; Mount /usr, /boot, and /etc as read-only for processes invoked by this service. +ProtectSystem=full +; Sets up a new /dev mount for the process and only adds API pseudo devices like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled by default because it may not work on devices like the Raspberry Pi. +PrivateDevices=false +; Ensures that the service process and all its children can never gain new privileges through execve(). +NoNewPrivileges=true +; Drops the sysadmin capability from the daemon. +CapabilityBoundingSet=~CAP_SYS_ADMIN + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3 From 1d2332ce79c374f4958b5d554ea96d382e9806fb Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 05:20:36 +0300 Subject: Use uname -m instead of arch for more portability --- rel/files/bin/pleroma_ctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index b0e1874a9..9c67b209b 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -2,7 +2,7 @@ # XXX: This should be removed when elixir's releases get custom command support detect_flavour() { - arch="$(arch)" + arch="$(uname -m)" if [ "$arch" = "x86_64" ]; then arch="amd64" elif [ "$arch" = "armv7l" ]; then -- cgit v1.2.3 From bb40c33dd65aaeafaf3b74f4557deb75b0da8e93 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 22 Jun 2019 13:24:33 +0300 Subject: Add an OpenRC service for OTP releases --- rel/files/installation/init.d/pleroma | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 rel/files/installation/init.d/pleroma (limited to 'rel/files') diff --git a/rel/files/installation/init.d/pleroma b/rel/files/installation/init.d/pleroma new file mode 100755 index 000000000..de007c5e3 --- /dev/null +++ b/rel/files/installation/init.d/pleroma @@ -0,0 +1,18 @@ +#!/sbin/openrc-run + +# Requires OpenRC >= 0.35 +directory=/opt/pleroma + +command=/opt/pleroma/bin/pleroma +command_args="start" +command_user=pleroma +command_background=1 + +# Ask process to terminate within 30 seconds, otherwise kill it +retry="SIGTERM/30/SIGKILL/5" + +pidfile="/var/run/pleroma.pid" + +depend() { + need nginx postgresql +} -- cgit v1.2.3 From 5b76c3141f7945f76b8f3f84990cce8332152f71 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 24 Jun 2019 10:08:33 +0300 Subject: Use supervise-daemon(8) for the alpine service --- rel/files/installation/init.d/pleroma | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'rel/files') diff --git a/rel/files/installation/init.d/pleroma b/rel/files/installation/init.d/pleroma index de007c5e3..dea1db26c 100755 --- a/rel/files/installation/init.d/pleroma +++ b/rel/files/installation/init.d/pleroma @@ -1,5 +1,7 @@ #!/sbin/openrc-run +supervisor=supervise-daemon + # Requires OpenRC >= 0.35 directory=/opt/pleroma @@ -14,5 +16,6 @@ retry="SIGTERM/30/SIGKILL/5" pidfile="/var/run/pleroma.pid" depend() { - need nginx postgresql + want nginx + need postgresql } -- cgit v1.2.3 From 8c7d7cc9365e996c624d4bdb6c8d578687ff117f Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 2 Jul 2019 18:47:53 +0300 Subject: [#1048] Fixed version parsing in pleroma_ctl. Closes #1036. --- rel/files/bin/pleroma_ctl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'rel/files') diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index 9c67b209b..e731d20eb 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -30,12 +30,15 @@ detect_flavour() { detect_branch() { version="$(cut -d' ' -f2 <"$RELEASE_ROOT"/releases/start_erl.data)" - branch="$(echo "$version" | cut -d'-' -f 4)" + # Expected format: major.minor.patch_version(-number_of_commits_ahead_of_tag-gcommit_hash).branch + branch="$(echo "$version" | cut -d'.' -f 4)" if [ "$branch" = "develop" ]; then echo "develop" elif [ "$branch" = "" ]; then echo "master" else + # Note: branch name in version is of SemVer format and may only contain [0-9a-zA-Z-] symbols — + # if supporting releases for more branches, need to ensure they contain only these symbols. echo "Releases are built only for master and develop branches" >&2 exit 1 fi -- cgit v1.2.3