Skip to content

Commit

Permalink
feat(run): introduce configurable user to run scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jokesterfr committed Dec 7, 2023
1 parent 868c009 commit 40e3181
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ You can check this implementation anytime in [prestashop-version.json](./prestas
| INSTALL_MODULES_DIR | module directory containing zips to be installed with the PrestaShop CLI | no | empty string (example: `/ps-modules`) |
| INIT_SCRIPTS_DIR | script directory with executable files to be run prior to PrestaShop startup | no | `/tmp/init-scripts` |
| POST_SCRIPTS_DIR | script directory with executable files to be run after the PrestaShop startup | no | `/tmp/post-scripts` |
| INIT_SCRIPTS_USER | the user running the executable files to be run prior to PrestaShop startup | no | `www-data` |
| POST_SCRIPTS_USER | the user running the executable files to be run after the PrestaShop startup | no | `www-data` |
| INIT_ON_RESTART | if enabled the PS_DOMAIN auto search and dump fix will be replayed on container restart | no | `false` |
| DUMP_ON_RESTART | if enabled the dump restoration replayed on container restart | no | `false` |
| INSTALL_MODULES_ON_RESTART | if enabled zip modules will be reinstalled on container restart | no | `false` |
Expand Down
10 changes: 6 additions & 4 deletions assets/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ON_INSTALL_MODULES_FAILURE=${ON_INSTALL_MODULES_FAILURE:-fail}
MYSQL_VERSION=${MYSQL_VERSION:-5.7}
INIT_SCRIPTS_DIR=${INIT_SCRIPTS_DIR:-/tmp/init-scripts/}
POST_SCRIPTS_DIR=${POST_SCRIPTS_DIR:-/tmp/post-scripts/}
INIT_SCRIPTS_USER=${INIT_SCRIPTS_USER:-www-data}
POST_SCRIPTS_USER=${POST_SCRIPTS_USER:-www-data}

INIT_LOCK=/tmp/flashlight-init.lock
DUMP_LOCK=/tmp/flashlight-dump.lock
Expand Down Expand Up @@ -172,9 +174,9 @@ if [ -d "$INIT_SCRIPTS_DIR" ]; then
find "$INIT_SCRIPTS_DIR" -maxdepth 1 -executable -type f -print0 | sort -z | xargs -0 -n1 sh -c '
printf "\n--> Running $1...\n"
if [ "$ON_INIT_SCRIPT_FAILURE" = "continue" ]; then
(sudo -E -g www-data -u www-data -- $1) || { echo "x $1 execution failed. Skipping."; }
(sudo -E -g '"$INIT_SCRIPTS_USER"' -u '"$INIT_SCRIPTS_USER"' -- $1) || { echo "x $1 execution failed. Skipping."; }
else
(sudo -E -g www-data -u www-data -- $1) || { echo "x $1 execution failed. Sleep and exit."; sleep 10; exit 7; }
(sudo -E -g '"$INIT_SCRIPTS_USER"' -u '"$INIT_SCRIPTS_USER"' -- $1) || { echo "x $1 execution failed. Sleep and exit."; sleep 10; exit 7; }
fi
' sh | awk 'BEGIN{RS="\n";ORS="\n "}1';
printf "\n";
Expand Down Expand Up @@ -208,9 +210,9 @@ if [ -d "$POST_SCRIPTS_DIR" ]; then
find "$POST_SCRIPTS_DIR" -maxdepth 1 -executable -type f -print0 | sort -z | xargs -0 -n1 sh -c '
printf "\n--> Running $1...\n"
if [ "$ON_POST_SCRIPT_FAILURE" = "continue" ]; then
(sudo -E -g www-data -u www-data -- $1) || { echo "x $1 execution failed. Skipping."; }
(sudo -E -g '"$POST_SCRIPTS_USER"' -u '"$POST_SCRIPTS_USER"' -- $1) || { echo "x $1 execution failed. Skipping."; }
else
(sudo -E -g www-data -u www-data -- $1) || { echo "x $1 execution failed. Sleep and exit."; sleep 10; exit 8; }
(sudo -E -g '"$POST_SCRIPTS_USER"' -u '"$POST_SCRIPTS_USER"' -- $1) || { echo "x $1 execution failed. Sleep and exit."; sleep 10; exit 8; }
fi
' sh | awk 'BEGIN{RS="\n";ORS="\n "}1';
printf "\n";
Expand Down
1 change: 1 addition & 0 deletions examples/develop-prestashop/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
environment:
- PS_DOMAIN=localhost:8000
- INIT_SCRIPTS_DIR=/tmp/init-scripts
- INIT_SCRIPTS_USER=root
volumes:
- ..:/var/www/html:rw
- ./init-scripts:/tmp/init-scripts:ro
Expand Down

0 comments on commit 40e3181

Please sign in to comment.