The install.sh is run to install the projects on each application instance to complete either the deployment of a new release or the provisioning of a new instance. Since the configuration of the necessary steps is to be done by the project, the install.sh must be part of the source code. |
The install.sh is run to install the projects on each application instance to complete either the deployment of a new release or the provisioning of a new instance. Since the configuration of the necessary steps is to be done by the project, the install.sh must be part of the source code.
To install by install.sh include the following steps:
Configure the application with the appropriate endpoints of the environment
Installation of crons
Execute necessary PHP commands
The steps can be adapted as desired to the requirements of individual projects.
The install.sh is run as www-data user. All file operations are therefore executed in the context of the web server in order to avoid access problems.
The install.sh must exit successfully (exitcode 0), otherwise the deployment will be canceled for the affected instance. This is why you should append " || exit $?" for all commands that are critical to the deployment (usually all of them), thereby exiting the deployment with the errorcode of the failed command. If this is not specified, the deployment or the provisioning continues even in the event of an unsuccessful command, making it much harder to debug.
The execution of the install.sh always takes place in the root directory of the repository
Each new instance will run the install.sh and flush your cache. So if autoscaling is starting new instance each of them will flush the cache, which works against the autoscaling which was triggered by high cpu load. Instead use deployment hooks for flushing caches.
Each instance during deployment will create a dump which will result in multiple dumps at the same time and or several dumps during autoscaling. Instead use deployment hooks for creating snapshots/dumps.
The install.sh is run on each instance during deployment and on each new instance that is created via autoscaling. If you create cronjobs without “run-once-per-role” each instance will have the same cronjob. So your cronjob will be executed multiple times which might cause harm to your application.
In all examples you will notice that we use some form of template (.dist) and replace the application config with this file after all placeholders have been replaced in the template. This is most resilient way to create application configs. As you can have a config file for local testing in your release and the Root360 deployment just overwrites it via install.sh. So you can use the same release for local testing and for the Root360 Platform. |
An example install.sh might look like this
#! /bin/bash # inject environment variables (e.g. db/redis/ses endpoints) to .env envsubst < .env.dist > .env || exit $? # install CRON if role "backend" is installed if [[ "${ROLE}" == "backend" ]] then # cron example echo "* * * * * cd /var/www/ && /usr/bin/php cron.php > /dev/null 2>&1" >> project-crontab # cron example with custom logging echo "* * * * * date >> /var/log/application/cron.log && cd /var/www/ && /usr/bin/php cron.php >> /var/log/application/cron.log 2>&1" >> project-crontab # cron example to register dynamic application log files stored in a dedicated log folder echo "* * * * * /usr/local/bin/check-log-registration /var/www/${ROLE}/logs/" >> project-crontab # cron example to run a command on only one instance per role echo "* * * * * /usr/local/bin/run-once-per-role.sh 'web' /var/www/web/public/bin/artisan cron:start" >> project-crontab crontab project-crontab || exit $? rm project-crontab fi # register custom application log file register-log -k "/var/www/${ROLE}/log_dir/custom_application.log" |
.env.dist
install.sh
|
dist.env.php
install.sh
|
dist.env.php
install.sh
|
See Scripts Snippets for an explanation of the used scripts register-log
, check-log-registration
and run-once-per-role.sh
.
envsubst
The envsubst
program will replace placeholder variables with the values from the appropriate environment variables for the role. The result is written into the configuration file used. In the example, a template configuration file .env.dist
is used to provide the placeholders. The environment variables for each project can be taken by executing sudo get-application-env
on the respective application instance.
|
The example shows the possibility to install a CRON. This installation is installed in the example only for the "backend" role. With this methodology, they allow all commands to be applied to different roles.
For Shopware, for example, you may want the attributes to be regenerated. The following command should be added:
php -d bin / console sw: generate: attributes || exit $? |
Pick one level and also add as tag to page
INTERMEDIATE