tpsgi.sh 1.2 KB

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