tpsgi.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. bn=$(basename $bind)
  12. to_bind=$(pwd)/$bn;
  13. if [[ -d $bind ]]; then
  14. echo "Bind $bind to $to_bind";
  15. mkdir -p $to_bind;
  16. [[ ! $(mountpoint -q $to_bind) ]] && mount --bind $bind $to_bind
  17. else
  18. echo "Refusing to bind nonexistant mountpoint $bind to $bn!"
  19. exit 1;
  20. fi;
  21. done
  22. # We should obey the PATH set by this user, whose homedir is right here, ideally.
  23. bin/tpsgi --listen run/tpsgi.sock --workers 20 --user "$USERNAME" --daemonize --pid run/tpsgi.pid --chroot $(pwd)
  24. # Wait until the socket file is ready
  25. until [ -e run/tpsgi.sock ]
  26. do
  27. echo "Waiting for sock to be ready..."
  28. sleep 1
  29. done
  30. # Fix ownership of socket so nginx can see it
  31. sudo chown $USERNAME:www-data run/tpsgi.sock
  32. sudo chmod 0770 run/tpsgi.sock
  33. echo "tPSGI running as PID "`cat run/tpsgi.pid`