Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt | ||
---|---|---|
| ||
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. |
When is the install.sh executed?
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.
Background information
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.
For 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), you should append " || exit $?", thereby exiting the deployment if with the errorcode of the failed command returns with an error code. 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
What to avoid in your install.sh
Clearing you central cache
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.
Creating database dumps/snapshots
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.
Creating cronjobs without “run-once-per-role” on autoscaling systems
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.
Examples
Info |
---|
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. |
Generic example
An example install.sh might look like this
Code Block | ||
---|---|---|
| ||
#! /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" |
Shopware6 example for .env.dist and install.sh
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
.env.dist
install.sh
|
Magento2 Example for dist.env.php and install.sh
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
dist.env.php
install.sh
|
TYPO3 example for dist.env.php and install.sh
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
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
.
Explanation of 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.
|
Explanation of "Installing CRONs"
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.
Explanation of "Running Required PHP Commands"
For Shopware, for example, you may want the attributes to be regenerated. The following command should be added:
Code Block | ||
---|---|---|
| ||
php -d bin / console sw: generate: attributes || exit $? |
Related tutorials
Filter by label (Content by label) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Related components
Filter by label (Content by label) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Status | ||||
---|---|---|---|---|
|
Table of Contents | ||
---|---|---|
|
Filter by label (Content by label) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|