Create ak-kill-9pserver.sh that kills ufs server
[akaros.git] / scripts / ak-scripts / ak-launch-9pserver.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2015 Google Inc.
4 # Kevin Klues <klueska@cs.berkeley.edu>
5 # See LICENSE for details.
6
7 function short_description() {
8         echo "Launch a Go 9pserver for Akaros"
9 }
10
11 function usage() {
12         echo "Usage:"
13         echo "    ${cmd} -h | --help"
14         echo "    ${cmd} [ --gopath=<gp> ]"
15         echo "    ${cmd//?/ } [ --akaros-9p-root=<mnt> ]"
16         echo "    ${cmd//?/ } [ --ufs-port=<port> ]"
17         echo "    ${cmd//?/ } [ --clear-mount ]"
18         echo "    ${cmd//?/ } [ --rebuild-server ]"
19         echo ""
20         echo "Options:"
21         echo "    -h --help               Display this screen and exit"
22         echo "    --gopath=<gp>           The path to the go workspace"
23         echo "                            [default: \$GOPATH]"
24         echo "    --akaros-9p-root=<mnt>  The location of the akaros 9p mount point"
25         echo "                            [default: \$AKAROS_9P_ROOT]"
26         echo "    --ufs-port=<port>       Port to connect the server on"
27         echo "                            [default: 1025]"
28         echo "    --clear-mount           Clear the 9p mount folder before mounting"
29         echo "    --rebuild-server        Download and rebuild the 9pserver"
30 }
31
32 function main() {
33         # Check the sanity of our incoming variables
34         check_vars gopath akaros_9p_root ufs_port clear_mount rebuild_server
35         check_dirs gopath akaros_9p_root
36
37         # Set up the go environment variables
38         eval $(go env)
39
40         # If we don't have a server at all, force a rebuild
41         if [ ! -f ${gopath}/bin/ufs ]; then
42                 rebuild_server=true
43         fi
44
45         # Get the latest 9p server which supports akaros
46         if [ ${rebuild_server} = true ]; then
47                 echo "Downloading and installing the latest supported 9p server"
48                 export GOOS=${GOHOSTOS}
49                 export GOARCH=${GOHOSTARCH}
50                 go get -d -u github.com/rminnich/go9p
51                 go get -d -u github.com/rminnich/go9p/ufs
52                 go install github.com/rminnich/go9p/ufs
53         fi
54
55         # Clear out the ${akaros_9p_root} directory
56         if [ ${clear_mount} = true ]; then
57                 echo "Clearing out ${akaros_9p_root}"
58                 rm -rf ${akaros_9p_root}
59         fi
60         mkdir -p ${akaros_9p_root}
61
62         # Kill any old instances of the ufs server on ${ufs_port}
63         ak kill-9pserver --ufs-port="${ufs_port}"
64
65         # Start a new ufs instance on ${ufs_port}
66         nohup ${gopath}/bin/ufs -akaros=true -addr=:${ufs_port} \
67                                 -root=${akaros_9p_root} >/dev/null 2>&1 &
68         echo "Started 9p server port=${ufs_port} root=${akaros_9p_root} (pid ${!})"
69 }