Skip to content
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

Deployment Errors on the new Amazon Linux 2023 #83

Open
luchtech opened this issue Aug 10, 2023 · 3 comments
Open

Deployment Errors on the new Amazon Linux 2023 #83

luchtech opened this issue Aug 10, 2023 · 3 comments

Comments

@luchtech
Copy link

Just found out earlier that I've been getting an error when I tried deploying a new Laravel application. When I checked the logs, it says something like this.

image

This is the current code which is causing the issue:

sudo amazon-linux-extras enable epel
sudo yum install -y epel-release
sudo yum -y update
sudo yum -y install supervisor
sudo systemctl start supervisord
sudo systemctl enable supervisord
sudo cp .platform/files/supervisor.ini /etc/supervisord.d/laravel.ini
sudo supervisorctl reread
sudo supervisorctl update

When I checked on Google, it says here that it was because I used the Amazon Linux 2023 image instead of AL2.
image

I hope you can update this to fix the issue.

@CoderPlusFromNowhere
Copy link

There is a lot of errors in Amazon Linux 2023.

nodejs cant install
php-redis cant install
supervisor cant install

@Rorymercer
Copy link

Couple of workarounds that worked for me, might be helpful for others on Amazon Linux 2023

Predis - Install via PECL

.platform/hooks/prebuild/install_phpredis.sh

#!/bin/sh

sudo pecl channel-update pecl.php.net
sudo pecl upgrade redis  #install redis with default configuration options to command line

#Move the redis config line automatically added to its own file, respecting any config there from previous deployments
sed -i -e '/extension="redis.so"/d' /etc/php.ini
sudo touch /etc/php.d/41-redis.ini
grep -qxF 'extension="redis.so"' /etc/php.d/41-redis.ini || echo 'extension="redis.so"' | sudo tee -a /etc/php.d/41-redis.ini

Supervisor

A bit tricker now that amazon-linux-extras has been removed. Installed via pip and then kept alive with systemd and an additional two configuration files (one for Supervisor one for Systemd)

.platform/hooks/prebuild/install_phpredis.sh

#AWS2023 PHP build Has python 3 without pip, install this first:
sudo python3 -m ensurepip --upgrade

#Install supervisor
sudo pip3 install supervisor

#Copy the configuration file
sudo cp .platform/files/supervisord.conf /etc/supervisord.conf

#Copy and enable the systemd service file
sudo cp .platform/files/supervisord.service /etc/systemd/system/supervisord.service
sudo systemctl daemon-reload

sudo mkdir /etc/supervisord
sudo cp .platform/files/supervisor.ini /etc/supervisord/laravel.ini

sudo systemctl enable supervisord
sudo systemctl start supervisord

sudo supervisorctl reread

sudo supervisorctl update

.platform/files/supervisord.conf

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
;
; Warning:
;  Paths throughout this example file use /tmp because it is available on most
;  systems.  You will likely need to change these to locations more appropriate
;  for your system.  Some systems periodically delete older files in /tmp.
;  Notably, if the socket file defined in the [unix_http_server] section below
;  is deleted, supervisorctl will be unable to connect to supervisord.

[unix_http_server]
file=/var/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

; Security Warning:
;  The inet HTTP server is not enabled by default.  The inet HTTP server is
;  enabled by uncommenting the [inet_http_server] section below.  The inet
;  HTTP server is intended for use within a trusted environment only.  It
;  should only be bound to localhost or only accessible from within an
;  isolated, trusted network.  The inet HTTP server does not support any
;  form of encryption.  The inet HTTP server does not use authentication
;  by default (see the username= and password= options to add authentication).
;  Never expose the inet HTTP server to the public internet.

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[supervisord]
logfile=/var/log/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/var/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
silent=false                 ; no logs to stdout if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
;umask=022                   ; process file creation umask; default 022
;user=supervisord            ; setuid to this UNIX account at startup; recommended if root
;identifier=supervisor       ; supervisord identifier, default is 'supervisor'
;directory=/tmp              ; default is not to cd during start
;nocleanup=true              ; don't clean up tempfiles at start; default false
;childlogdir=/tmp            ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false

; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work.  Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections.

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=unix:///var/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

[include]
files = supervisord/*.ini

.platform/files/supervisord.service

[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target

[Service]
#Uncomment the line below if you want to run it as a daemon
#Type=forking
ExecStart=/usr/local/bin/supervisord -n -c /etc/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/local/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=20s

[Install]
WantedBy=multi-user.target

I've used sudo throughout for consistency with these files, but I think they run as root by default on Amazon Linux.

Hope it's helpful!

@WalrusSoup
Copy link

Any risk in using systemd to do this since its already on-rack? Currently playing with these configurations to hit a sweet spot:

/.platform/files/app.service

[Unit]
Description=Queue Worker
After=network.target

[Service]
User=webapp
WorkingDirectory=/var/app/current
ExecStart=php artisan queue:work
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

/.platform/hooks/prebuild/configure_systemd.sh

sudo cp .platform/config/app.service /etc/systemd/system/[email protected]
sudo systemctl daemon-reload
// start 2 queue workers
sudo systemctl start [email protected]
sudo systemctl start [email protected]
sudo systemctl enable [email protected]
sudo systemctl enable [email protected]

.platform/hooks/postdeploy/restart_services.sh

sudo systemctl daemon-reload
sudo systemctl restart [email protected]
sudo systemctl restart [email protected]

Only issue is if the queue changes, you'd need to basically dump all the services and re-add them since it doesn't seem to just scan them at is.

Would love if someone familiar with systemd could chime in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants