_context-chruby-run 636 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. CONTEXT="$1"; shift
  3. RUBYVERSION="$1"; shift
  4. if [ "$CONTEXT" = "" ]; then
  5. echo " Internal error: /opt context is not set" >&2
  6. exit 4
  7. fi
  8. if [ "$RUBYVERSION" = "" ]; then
  9. echo " Internal error: Ruby version is not set" >&2
  10. exit 4
  11. fi
  12. SYS_MNT_NS="$(sudo readlink /proc/1/ns/mnt)"
  13. MY_MNT_NS="$(readlink /proc/self/ns/mnt)"
  14. if [ "$SYS_MNT_NS" = "$MY_MNT_NS" ]; then
  15. echo " Internal error: Wrong MNT namespace" >&2
  16. exit 4
  17. fi
  18. mount --bind /srv/share/nfs/opt/"$CONTEXT" /opt
  19. source /usr/local/share/chruby/chruby.sh
  20. chruby "$RUBYVERSION" &&
  21. runuser -u nobody -g "$CONTEXT" $@
  22. RC="$?"
  23. umount -l /opt
  24. exit $RC