public void terminate() {
        if (stopped.compareAndSet(false, true)) {
            System.out.printf("Stopping Red5 with args: %s%n", Arrays.toString(commandLineArgs));
            if (commandLineArgs == null || commandLineArgs.length < 2) {
                // there should be 40+ characters worth of args (port + token)
                // use the default port of 9999
                String port = "9999";
                if (commandLineArgs.length >= 1) {
                    port = commandLineArgs[0];
                }
                // read the token from the file
                String token = "cafebeef";
                try {
                    File tokenFile = Paths.get("shutdown.token").toFile();
                    RandomAccessFile raf = new RandomAccessFile(tokenFile, "r");
                    byte[] buf = new byte[36];
                    raf.readFully(buf);
                    token = new String(buf);
                    System.out.printf("Token loaded: %s%n", token);
                    raf.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // set the args
                commandLineArgs = new String[] { port, token };
            }
            // shutdown
            Shutdown.main(commandLineArgs);
            System.out.println("Red5 stopped");
        }
    }