Skip to content

Place the PHP version into a variable (#2307) #2308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ tools/__pycache__/
externals/
.env
.vagrant
api/docs/api-docs.html
api/docs/api-docs.html
*.code-workspace
1,321 changes: 627 additions & 694 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ This is a challenge faced by everyone who runs their own mail server, with or wi
Contributing and Development
----------------------------

Mail-in-a-Box is an open source project. Your contributions and pull requests are welcome. See [CONTRIBUTING](CONTRIBUTING.md) to get started.
Mail-in-a-Box is an open source project. Your contributions and pull requests are welcome. See [CONTRIBUTING](CONTRIBUTING.md) to get started.


The Acknowledgements
Expand Down
2 changes: 1 addition & 1 deletion conf/nginx-top.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
## your own --- please do not ask for help from us.

upstream php-fpm {
server unix:/var/run/php/php8.0-fpm.sock;
server unix:/var/run/php/php{{phpver}}-fpm.sock;
}

7 changes: 4 additions & 3 deletions management/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import rtyaml
from exclusiveprocess import Lock

from utils import load_environment, shell, wait_for_service
from utils import load_environment, shell, wait_for_service, get_php_version

def backup_status(env):
# If backups are dissbled, return no status.
Expand Down Expand Up @@ -262,6 +262,7 @@ def get_target_type(config):

def perform_backup(full_backup):
env = load_environment()
php_fpm = f"php{get_php_version()}-fpm"

# Create an global exclusive lock so that the backup script
# cannot be run more than one.
Expand Down Expand Up @@ -297,7 +298,7 @@ def service_command(service, command, quit=None):
if quit:
sys.exit(code)

service_command("php8.0-fpm", "stop", quit=True)
service_command(php_fpm, "stop", quit=True)
service_command("postfix", "stop", quit=True)
service_command("dovecot", "stop", quit=True)
service_command("postgrey", "stop", quit=True)
Expand Down Expand Up @@ -334,7 +335,7 @@ def service_command(service, command, quit=None):
service_command("postgrey", "start", quit=False)
service_command("dovecot", "start", quit=False)
service_command("postfix", "start", quit=False)
service_command("php8.0-fpm", "start", quit=False)
service_command(php_fpm, "start", quit=False)

# Remove old backups. This deletes all backup data no longer needed
# from more than 3 days ago.
Expand Down
4 changes: 4 additions & 0 deletions management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def wait_for_service(port, public, env, timeout):
return False
time.sleep(min(timeout/4, 1))

def get_php_version():
# Gets the version of PHP installed in the system.
return shell("check_output", ["/usr/bin/php", "-v"])[4:7]

if __name__ == "__main__":
from web_update import get_web_domains
env = load_environment()
Expand Down
3 changes: 2 additions & 1 deletion management/web_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mailconfig import get_mail_domains
from dns_update import get_custom_dns_config, get_dns_zones
from ssl_certificates import get_ssl_certificates, get_domain_ssl_files, check_certificate
from utils import shell, safe_domain_name, sort_domains
from utils import shell, safe_domain_name, sort_domains, get_php_version

def get_web_domains(env, include_www_redirects=True, include_auto=True, exclude_dns_elsewhere=True):
# What domains should we serve HTTP(S) for?
Expand Down Expand Up @@ -83,6 +83,7 @@ def read_conf(conf_fn):

# Build an nginx configuration file.
nginx_conf = read_conf("nginx-top.conf")
nginx_conf = re.sub("{{phpver}}", get_php_version(), nginx_conf)

# Load the templates.
template0 = read_conf("nginx.conf")
Expand Down
2 changes: 2 additions & 0 deletions setup/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# -o pipefail: don't ignore errors in the non-last command in a pipeline
set -euo pipefail

# This global variable pinpoints the PHP version for the whole MiaB app
# Upgrade it only with care and tests. Nextcloud versions depend on it.
PHP_VER=8.0

function hide_output {
Expand Down
2 changes: 1 addition & 1 deletion setup/web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ chmod a+r /var/lib/mailinabox/mozilla-autoconfig.xml

# Create a generic mta-sts.txt file which is exposed via the
# nginx configuration at /.well-known/mta-sts.txt
# more documentation is available on:
# more documentation is available on:
# https://www.uriports.com/blog/mta-sts-explained/
# default mode is "enforce". In /etc/mailinabox.conf change
# "MTA_STS_MODE=testing" which means "Messages will be delivered
Expand Down
4 changes: 2 additions & 2 deletions setup/zpush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ if [ $needs_update == 1 ]; then
mv /tmp/z-push/*/src /usr/local/lib/z-push
rm -rf /tmp/z-push.zip /tmp/z-push

# Create admin and top scripts with PHP_VER
# Create admin and top scripts with PHP_VER
rm -f /usr/sbin/z-push-{admin,top}
echo '#!/bin/bash' > /usr/sbin/z-push-admin
echo php$PHP_VER /usr/local/lib/z-push/z-push-admin.php '"$@"' >> /usr/sbin/z-push-admin
chmod 755 /usr/sbin/z-push-admin
echo '#!/bin/bash' > /usr/sbin/z-push-top
echo php$PHP_VER /usr/local/lib/z-push/z-push-top.php '"$@"' >> /usr/sbin/z-push-top
chmod 755 /usr/sbin/z-push-top

echo $VERSION > /usr/local/lib/z-push/version
fi

Expand Down
2 changes: 2 additions & 0 deletions tools/mail.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# This script has moved.
# Yet, keep it for some users still calling it (backward compatibility)
management/cli.py "$@"
4 changes: 2 additions & 2 deletions tools/owncloud-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if [ ! -f $1/config.php ]; then
fi

echo "Restoring backup from $1"
service php8.0-fpm stop
service php$PHP_VER-fpm stop

# remove the current ownCloud/Nextcloud installation
rm -rf /usr/local/lib/owncloud/
Expand All @@ -45,5 +45,5 @@ chown www-data:www-data $STORAGE_ROOT/owncloud/config.php

sudo -u www-data php$PHP_VER /usr/local/lib/owncloud/occ maintenance:mode --off

service php8.0-fpm start
service php$PHP_VER-fpm start
echo "Done"
6 changes: 3 additions & 3 deletions tools/owncloud-unlockadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

source /etc/mailinabox.conf # load global vars

ADMIN=$(./mail.py user admins | head -n 1)
Copy link
Contributor Author

@binarykitchen binarykitchen Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was actually just redirecting to management/cli.py, hence fixing the path.

But that file, mail.py, is still here, for backward compatibility.

test -z "$1" || ADMIN=$1
ADMIN=$(./management/cli.py user admins | head -n 1)
test -z "$1" || ADMIN=$1

echo I am going to unlock admin features for $ADMIN.
echo You can provide another user to unlock as the first argument of this script.
echo
echo WARNING: you could break mail-in-a-box when fiddling around with Nextcloud\'s admin interface
echo If in doubt, press CTRL-C to cancel.
echo
echo
echo Press enter to continue.
read

Expand Down