tpsgi.sh 1.2 KB

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