tpsgi.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. USERNAME=$(bin/tpsgi-config --user)
  3. [[ -z $USERNAME ]] && USERNAME=$USER
  4. echo "tPSGI running as user $USERNAME"
  5. EGID=$(id -nu)
  6. GROUP=$(bin/tpsgi-config --http_user)
  7. [[ -z $GROUP ]] && GROUP=$EGID
  8. echo "tPSGI running with EGID $GROUP";
  9. [[ -e run/tpsgi.pid ]] && sudo pkill -F run/tpsgi.pid
  10. # Bind the various dirs we need for chroot to work
  11. readarray -t BIND_DIRS <<< $(bin/tpsgi-config --binds)
  12. for bind in "${BIND_DIRS[@]}"; do
  13. if [[ -z $bind ]]; then
  14. continue;
  15. fi;
  16. bn=$(basename $bind)
  17. to_bind=$(pwd)/$bn;
  18. if [[ -d $bind ]]; then
  19. echo "Bind $bind to $to_bind";
  20. mkdir -p $to_bind;
  21. [[ ! $(mountpoint -q $to_bind) ]] && mount --bind $bind $to_bind
  22. else
  23. echo "Refusing to bind nonexistant mountpoint $bind to $bn!"
  24. exit 1;
  25. fi;
  26. done
  27. # We should obey the PATH set by this user, whose homedir is right here, ideally.
  28. bin/tpsgi --listen run/tpsgi.sock --workers 20 --user "$USERNAME" --group "$GROUP" --daemonize --pid run/tpsgi.pid --chroot $(pwd)
  29. if [ $? -ne 0 ]
  30. then
  31. echo "Could not start service!"
  32. exit 1;
  33. fi
  34. # Wait until the socket file is ready
  35. until [ -e run/tpsgi.sock ]
  36. do
  37. echo "Waiting for sock to be ready..."
  38. sleep 1
  39. done
  40. # Fix ownership of socket so nginx can see it
  41. sudo chown $USERNAME:www-data run/tpsgi.sock
  42. sudo chmod 0770 run/tpsgi.sock
  43. echo "tPSGI running as PID "`cat run/tpsgi.pid`