various fixes
This commit is contained in:
parent
58ab870b2d
commit
d97b5e1047
|
@ -74,7 +74,7 @@ RUN apk add --no-cache pcre bash python3 && \
|
|||
chmod 660 /usr/share/bunkerweb/INTEGRATION
|
||||
|
||||
# Fix CVEs
|
||||
RUN apk add "openssl>=1.1.1q-r0" "curl>=7.83.1-r6" "libcurl>=7.83.1-r6" "git>=2.36.5-r0"
|
||||
RUN apk add "openssl>=1.1.1q-r0" "curl>=7.83.1-r6" "libcurl>=7.83.1-r6" "git>=2.36.5-r0" "libcrypto1.1>=1.1.1t-r1" "libssl1.1>=1.1.1t-r1"
|
||||
|
||||
VOLUME /data /etc/nginx
|
||||
|
||||
|
|
|
@ -16,24 +16,24 @@ function do_and_check_cmd() {
|
|||
}
|
||||
|
||||
#Start the nginx service if it is not already running
|
||||
if ! systemctl is-active nginx; then
|
||||
echo "Starting nginx service..."
|
||||
do_and_check_cmd systemctl start nginx
|
||||
fi
|
||||
# if ! systemctl is-active nginx; then
|
||||
# echo "Starting nginx service..."
|
||||
# do_and_check_cmd systemctl start nginx
|
||||
# fi
|
||||
|
||||
#Give all the permissions to the nginx user
|
||||
# Give all the permissions to the nginx user
|
||||
echo "Setting ownership for all necessary directories to nginx user and group..."
|
||||
do_and_check_cmd chown -R nginx:nginx /usr/share/bunkerweb /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb
|
||||
|
||||
#Start bunkerweb service as nginx user and enable it to start on boot
|
||||
# Auto start BW service on boot and start it now
|
||||
echo "Enabling and starting bunkerweb service..."
|
||||
do_and_check_cmd systemctl enable bunkerweb
|
||||
do_and_check_cmd systemctl start bunkerweb
|
||||
|
||||
#Start and enable bunkerweb-ui service
|
||||
echo "Enabling and starting bunkerweb-ui service..."
|
||||
do_and_check_cmd systemctl enable bunkerweb-ui
|
||||
do_and_check_cmd systemctl start bunkerweb-ui
|
||||
# Start and enable bunkerweb-ui service
|
||||
# echo "Enabling and starting bunkerweb-ui service..."
|
||||
# do_and_check_cmd systemctl enable bunkerweb-ui
|
||||
# do_and_check_cmd systemctl start bunkerweb-ui
|
||||
|
||||
# Copy old line from environment file to new one
|
||||
# Check if old environment file exists
|
||||
|
@ -46,9 +46,10 @@ if [ -f /var/tmp/variables.env ]; then
|
|||
# Remove old environment files
|
||||
echo "Removing old environment files..."
|
||||
do_and_check_cmd rm -f /var/tmp/variables.env
|
||||
do_and_check_cmd chown root:nginx /etc/bunkerweb/variables.env
|
||||
do_and_check_cmd chmod 740 /etc/bunkerweb/variables.env
|
||||
else
|
||||
echo "Old environment file not found!"
|
||||
exit 0
|
||||
echo "Old environment file not found. Skipping copy..."
|
||||
fi
|
||||
|
||||
# Copy old line from ui environment file to new one
|
||||
|
@ -62,9 +63,10 @@ if [ -f /var/tmp/ui.env ]; then
|
|||
# Remove old environment files
|
||||
echo "Removing old environment files..."
|
||||
do_and_check_cmd rm -f /var/tmp/ui.env
|
||||
do_and_check_cmd chown root:nginx /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chmod 740 /etc/bunkerweb/ui.env
|
||||
else
|
||||
echo "Old ui environment file not found!"
|
||||
exit 0
|
||||
echo "Old ui environment file not found. Skipping copy..."
|
||||
fi
|
||||
|
||||
# Check if old db.sqlite3 file exists
|
||||
|
@ -72,9 +74,10 @@ if [ -f /var/tmp/bunkerweb/db.sqlite3 ]; then
|
|||
echo "Old db.sqlite3 file found!"
|
||||
do_and_check_cmd cp /var/tmp/bunkerweb/db.sqlite3 /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd rm -f /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd chown root:nginx /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd chmod 760 /var/lib/bunkerweb/db.sqlite3
|
||||
else
|
||||
echo "Old db.sqlite3 file not found!"
|
||||
exit 0
|
||||
echo "Old database file not found. Skipping copy..."
|
||||
fi
|
||||
|
||||
echo "All services started and enabled successfully!"
|
||||
echo "Postinstall successful !"
|
|
@ -15,24 +15,93 @@ function display_help() {
|
|||
echo " reload: Reload the bunkerweb service."
|
||||
}
|
||||
|
||||
function stop_nginx() {
|
||||
pgrep nginx
|
||||
if [ $? -eq 0 ] ; then
|
||||
log "SYSTEMCTL" "ℹ️ " "Stopping nginx..."
|
||||
nginx -s stop
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while sending stop signal to nginx"
|
||||
fi
|
||||
fi
|
||||
count=0
|
||||
while [ 1 ] ; do
|
||||
pgrep nginx
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "ℹ️ " "nginx is stopped"
|
||||
break
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "Waiting for nginx to stop..."
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge 20 ] ; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $count -ge 20 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Timeout while waiting nginx to stop"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "nginx is stopped"
|
||||
}
|
||||
|
||||
function stop_scheduler() {
|
||||
if [ -f "/var/tmp/bunkerweb/scheduler.pid" ] ; then
|
||||
scheduler_pid=$(cat "/var/tmp/bunkerweb/scheduler.pid")
|
||||
log "SYSTEMCTL" "ℹ️ " "Stopping scheduler..."
|
||||
kill -SIGINT "$scheduler_pid"
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while sending stop signal to scheduler"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler already stopped"
|
||||
return 0
|
||||
fi
|
||||
count=0
|
||||
while [ -f "/var/tmp/bunkerweb/scheduler.pid" ] ; do
|
||||
sleep 1
|
||||
count=$(($count + 1))
|
||||
if [ $count -ge 10 ] ; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $count -ge 10 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Timeout while waiting scheduler to stop"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler is stopped"
|
||||
}
|
||||
|
||||
# Start the bunkerweb service
|
||||
function start() {
|
||||
|
||||
# Set the PYTHONPATH
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python
|
||||
|
||||
# Get the pid of nginx and put it in a file
|
||||
log "ENTRYPOINT" "ℹ️" "Getting nginx pid ..."
|
||||
nginx_pid=$(pgrep -x "nginx")
|
||||
echo $nginx_pid > /var/tmp/bunkerweb/nginx.pid
|
||||
|
||||
# Check if scheduler pid file exist and remove it if so
|
||||
# if [ -f /var/tmp/bunkerweb/scheduler.pid ] ; then
|
||||
# rm -f /var/tmp/bunkerweb/scheduler.pid
|
||||
# fi
|
||||
log "ENTRYPOINT" "ℹ️" "Starting BunkerWeb service ..."
|
||||
|
||||
# Setup and check /data folder
|
||||
/usr/share/bunkerweb/helpers/data.sh "ENTRYPOINT"
|
||||
|
||||
# Stop nginx if it's running
|
||||
stop_nginx
|
||||
|
||||
# Generate temp conf for jobs and start nginx
|
||||
if [ ! -f /var/tmp/bunkerweb/tmp.env] ; then
|
||||
echo -ne "IS_LOADING=yes\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nSERVER_NAME=\n" > /var/tmp/bunkerweb/tmp.env
|
||||
fi
|
||||
/usr/share/bunkerweb/gen/main.py --variables /var/tmp/bunkerweb/tmp.env
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "ENTRYPOINT" "❌" "Error while generating config from /var/tmp/bunkerweb/tmp.env"
|
||||
exit 1
|
||||
fi
|
||||
nginx
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "ENTRYPOINT" "❌" "Error while executing nginx"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create dummy variables.env
|
||||
if [ ! -f /etc/bunkerweb/variables.env ]; then
|
||||
echo -ne "# remove IS_LOADING=yes when your config is ready\nIS_LOADING=yes\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nSERVER_NAME=\n" > /etc/bunkerweb/variables.env
|
||||
|
@ -44,12 +113,13 @@ function start() {
|
|||
else
|
||||
/usr/share/bunkerweb/gen/save_config.py --variables /etc/bunkerweb/variables.env
|
||||
fi
|
||||
if [ "$?" -ne 0 ] ; then
|
||||
log "ENTRYPOINT" "❌" "Scheduler generator failed"
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "ENTRYPOINT" "❌" "save_config failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute jobs
|
||||
# Execute scheduler
|
||||
stop_scheduler
|
||||
log "ENTRYPOINT" "ℹ️ " "Executing scheduler ..."
|
||||
/usr/share/bunkerweb/scheduler/main.py --variables /etc/bunkerweb/variables.env
|
||||
if [ "$?" -ne 0 ] ; then
|
||||
|
@ -58,50 +128,22 @@ function start() {
|
|||
fi
|
||||
|
||||
log "ENTRYPOINT" "ℹ️ " "Scheduler stopped"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function stop() {
|
||||
ret=0
|
||||
|
||||
log "ENTRYPOINT" "ℹ️" "Stopping BunkerWeb service ..."
|
||||
|
||||
# Check if pid file exist and remove it if so
|
||||
pid_file_path="/var/tmp/bunkerweb/scheduler.pid"
|
||||
if [ -f "$pid_file_path" ]; then
|
||||
scheduler_pid=$(cat "$pid_file_path")
|
||||
log "ENTRYPOINT" "ℹ️" "Sending stop signal to scheduler with pid: $scheduler_pid"
|
||||
kill -SIGINT $scheduler_pid
|
||||
if [ "$?" -ne 0 ]; then
|
||||
log "ENTRYPOINT" "❌" "Failed to stop scheduler process with pid: $scheduler_pid"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "ENTRYPOINT" "❌" "Scheduler is not running"
|
||||
ret=1
|
||||
fi
|
||||
stop_nginx
|
||||
stop_scheduler
|
||||
|
||||
# Check if nginx is running and if so, stop it
|
||||
service="nginx"
|
||||
if pgrep -x "$service" > /dev/null; then
|
||||
log "ENTRYPOINT" "ℹ️" "Stopping $service service"
|
||||
nginx -s quit
|
||||
if [ "$?" -ne 0 ]; then
|
||||
log "ENTRYPOINT" "❌" "Failed to stop $service service"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "ENTRYPOINT" "❌" "$service is not running"
|
||||
ret=1
|
||||
fi
|
||||
|
||||
exit $ret
|
||||
log "ENTRYPOINT" "ℹ️" "BunkerWeb service stopped"
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
|
||||
log "ENTRYPOINT" "ℹ️" "Reloading BunkerWeb service ..."
|
||||
# Send signal to scheduler to reload
|
||||
|
||||
PID_FILE_PATH="/var/tmp/bunkerweb/scheduler.pid"
|
||||
if [ -f "$PID_FILE_PATH" ];
|
||||
then
|
||||
|
@ -118,6 +160,8 @@ function reload()
|
|||
log "ENTRYPOINT" "❌" "Scheduler is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "ENTRYPOINT" "ℹ️" "BunkerWeb service reloaded ..."
|
||||
}
|
||||
|
||||
# List of differents args
|
||||
|
|
Loading…
Reference in New Issue