| #!/bin/sh |
| # SpaceCast init script. |
| . /etc/utils.sh |
| |
| # Set the stack size to 1MB (Default to 8M) to support more concurrent streams. |
| # When CGO is enabled, each blocking syscall (Read, Write) will call |
| # pthread_create to create a new thread, so stack size for 100 concurrent |
| # streams would be 800MB and the memory limit would be hit without this change. |
| ulimit -s 1024 |
| |
| APP="spacecast" |
| BINARY="/app/spacecast/appliance" |
| # TODO(b/30677133): disable cache skipping in 6.13 release. |
| # Revert this change in 6.14 or 6.15 release when all the metadata gets |
| # updated. |
| FLAGS="-logtostderr -ring_buffer_size=64MB -puller_skip_cached=false" |
| if [ -e /tmp/DEBUG ]; then |
| FLAGS="$FLAGS -debug=true" |
| fi |
| |
| running() { |
| [ -n "$(pgrep -f "$BINARY")" ] |
| } |
| |
| case "$1" in |
| start) |
| if running; then |
| echo "SpaceCast is already running!" |
| else |
| ( |
| # Check for critical software updates |
| wait-until-created /tmp/gpio/ledcontrol/update_check_complete |
| # Bootstrap |
| wait-until-created /tmp/gpio/bootstrap |
| # Service file |
| wait-until-created /config/service_file |
| babysit_start 10 "$APP" "$BINARY" "$FLAGS" |
| ) & |
| echo "SpaceCast started." |
| fi |
| ;; |
| stop) |
| pkill -f "$BINARY" |
| while running; do |
| echo "SpaceCast is in lameduck mode. Please wait..." |
| sleep 10 |
| done |
| echo "SpaceCast stopped." |
| ;; |
| restart|reload) |
| $0 stop;$0 start |
| ;; |
| *) |
| echo "Usage: $0 {start|stop|restart}" |
| exit 1 |
| esac |