Skip to content

Commit

Permalink
Fix tmp dir creation
Browse files Browse the repository at this point in the history
It is not enough to create tmp dirs (for pids and sockets) at install
time. Each process must ensure that they exist, if necessary, before
starting.
  • Loading branch information
dhelonious committed Dec 31, 2024
1 parent 87edada commit 3c2e74e
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion snap/hooks/install
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ update_snap_version_file

mkdir -pm 0750 "$SECRET_DIR"
chown root:$DAEMON_USER "$SECRET_DIR"
mkdir -pm 0777 "$PID_DIR" "$SOCK_DIR"
mkdir -p "$UPDATE_DIR" "$UPDATE_BACKUP_DIR" "$DEFAULT_BACKUP_DIR"
mkdir_for_daemon_user "$CERT_DIR"
mkdir_for_daemon_user "$DEFAULT_MEDIA_DIR"
Expand Down
1 change: 1 addition & 0 deletions src/nginx/bin/nginx.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if ! $(config_exists nginx nginx.conf); then
exit 0
fi

mkdir_pid
run_as_daemon_user mkdir -p "$NGINX_CACHE"

if $(certificate_exists); then
Expand Down
2 changes: 1 addition & 1 deletion src/nginx/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
user $DAEMON_USER;
daemon off;
worker_processes 1;
pid $PID_DIR/nginx.pid;
pid $NGINX_PID_FILE;
error_log $LOG_DIR/nginx.log;

events {
Expand Down
1 change: 1 addition & 0 deletions src/nginx/nginx.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export HTTPS_PORT="$(snapctl get ports.https)"
export SSL_CERT="$CERT_DIR/${DOMAIN}_ecc/fullchain.cer"
export SSL_CERT_KEY="$CERT_DIR/${DOMAIN}_ecc/${DOMAIN}.key"

export NGINX_PID_FILE="$PID_DIR/nginx.pid"
export NGINX_HOME="$SNAP_DATA/nginx"
export NGINX_DATA="$NGINX_HOME/data"
export NGINX_CONFIG="$NGINX_HOME/config"
Expand Down
2 changes: 2 additions & 0 deletions src/postgres/bin/postgres.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ while is_active postgres-upgrade; do
sleep 1
done

mkdir_pid
mkdir_sock
mkdir -p "$PG_SOCK_DIR"

sed -ie "s|^include_if_exists = .*|include_if_exists = '$(config_dir postgres)/postgresql.conf'|" "$PG_DATA/postgresql.conf"
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/config/postgresql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ max_connections = 100
shared_buffers = 128MB
ssl = off
huge_pages = off
external_pid_file = '$PID_DIR/postgres.pid'
external_pid_file = '$PG_PID_FILE'
log_destination = 'stderr'
logging_collector = off
shared_preload_libraries = 'pg_stat_statements'
Expand Down
1 change: 1 addition & 0 deletions src/postgres/postgres.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

update_paths postgres

export PG_PID_FILE="$PID_DIR/postgres.pid"
export PG_HOME="$SNAP_DATA/postgres"
export PG_DATA="$PG_HOME/data"
export PG_CONFIG="$PG_HOME/config"
Expand Down
1 change: 1 addition & 0 deletions src/redis/bin/redis.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if ! $(config_exists redis redis.conf); then
exit 0
fi

mkdir_pid
mkdir -p "$REDIS_DATA"

redis-server "$REDIS_CONFIG/redis.conf"
2 changes: 1 addition & 1 deletion src/redis/config/redis.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
daemonize no
pidfile $PID_DIR/redis.pid
pidfile $REDIS_PID_FILE
bind localhost
port $REDIS_PORT
timeout 0
Expand Down
1 change: 1 addition & 0 deletions src/redis/redis.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

update_paths redis

export REDIS_PID_FILE="$PID_DIR/redis.pid"
export REDIS_HOME="$SNAP_DATA/redis"
export REDIS_DATA="$REDIS_HOME/data"
export REDIS_CONFIG="$REDIS_HOME/config"
Expand Down
8 changes: 8 additions & 0 deletions src/snap/snap.env
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ mkdir_for_daemon_user() {
done
}

mkdir_pid() {
mkdir -pm 0777 "$PID_DIR"
}

mkdir_sock() {
mkdir -pm 0777 "$SOCK_DIR"
}

fix_daemon_user() {
if [ -e "$1" ]; then
chmod -fR g+rw "$1" || run_as_daemon_user chmod -fR g+rw "$1" || true
Expand Down

0 comments on commit 3c2e74e

Please sign in to comment.