aboutsummaryrefslogtreecommitdiff
path: root/vo/votools/hub.cl
blob: 58a9a970f698f72e172a78428266a708d77040b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#{  HUB -- Start or stop the Hub

procedure hub (cmd)

string	cmd			{ prompt = "Command"			}
bool	bkg     = yes		{ prompt = "Run in background?"		}
bool	gui     = yes		{ prompt = "Run a GUI window?"		}
bool	verbose = no		{ prompt = "Verbose output?"		}

begin
    string action, command, ch
    bool   verb, do_gui, stat

    action   = cmd
    verb     = verbose
    do_gui   = gui
    command  =  "!" // osfn ("vo$java/app.hub")

    if (action == "start" || action == "on") {
        command = command // " -bg"
	if (!do_gui) {
	    command = command // " -no-gui"
	}
	;
        print (command) | cl(, >& "dev$null")

retry:
	i = 0
	stat = sampHubAccess ()
	for (i=0; stat == no; i = i + 1) {
	    if (verb)
		print ("Waiting for Hub to start ...")
	    sleep (1)

	    if (i > 60)		# only wait a minute to start
		break

	    stat = sampHubAccess ()
	}

	if (stat) {
	    samp on
	    if (verb)
	        print ("Hub and SAMP started")
	} else {
	    printf ("Cannot start or contact SAMP Hub.\n")
prompt:
	    printf ("Would you like to try again (y/n) ? ")

            ch = cl.ukey			# get reply
	    print ("")
            if (ch == "y") {
		goto retry
            } else if (substr(ch,1,4) == "\\015") {
                goto prompt
	    }
	}
	;

    } else if (action == "stop" || action == "off") {
	samp off
        command = command // " -kill"
        print (command) | cl(, >& "dev$null")


    } else if (action == "status") {
        command = command // " -status"
        print (command) | cl()
    }
end