Kaynağa Gözat

Mount various dirs if needed by chroot

George Baugh 1 yıl önce
ebeveyn
işleme
8351fef51b
2 değiştirilmiş dosya ile 17 ekleme ve 1 silme
  1. 1 0
      lib/TPSGI.pm
  2. 16 1
      service/tpsgi.sh

+ 1 - 0
lib/TPSGI.pm

@@ -829,6 +829,7 @@ sub get_config {
         auth       => undef,
         domain     => '',
         user       => '',
+        binds      => [],
     );
     $ENV{HOME} ||= Cwd::getcwd();
     my $config_file = "$ENV{HOME}/.tpsgi.ini";

+ 16 - 1
service/tpsgi.sh

@@ -9,7 +9,22 @@ echo "tPSGI running as user $USERNAME"
 
 [[ -e run/tpsgi.pid ]] && sudo pkill -F run/tpsgi.pid
 
-# We should obey the PATH set by this user, whose homedir is right here, ideally. 
+# Bind the various dirs we need for chroot to work
+readarray -t BIND_DIRS <<< $(bin/tpsgi-config --binds)
+for bind in "${BIND_DIRS[@]}"; do
+    bn=$(basename $bind)
+    to_bind=$(pwd)/$bn;
+    if [[ -d $bind ]]; then
+        echo "Bind $bind to $to_bind";
+        mkdir -p $to_bind;
+        [[ ! $(mountpoint -q $to_bind) ]] && mount --bind $bind $to_bind
+    else
+        echo "Refusing to bind nonexistant mountpoint $bind to $bn!"
+        exit 1;
+    fi;
+done
+
+# We should obey the PATH set by this user, whose homedir is right here, ideally.
 bin/tpsgi --listen run/tpsgi.sock --workers 20 --user "$USERNAME" --daemonize --pid run/tpsgi.pid --chroot $(pwd)
 
 # Wait until the socket file is ready