Exakat\Tasks\CleanDb::restartNeo4j PHP Method

restartNeo4j() private method

private restartNeo4j ( )
    private function restartNeo4j()
    {
        display('Cleaning with restart');
        $this->config = $this->config;
        // preserve data/dbms/auth to preserve authentication
        if (file_exists($this->config->neo4j_folder . '/data/dbms/auth')) {
            $sshLoad = 'mv data/dbms/auth ../auth; rm -rf data; mkdir -p data/dbms; mv ../auth data/dbms/auth; mkdir -p data/log; mkdir -p data/scripts ';
        } else {
            $sshLoad = 'rm -rf data; mkdir -p data; mkdir -p data/log; mkdir -p data/scripts ';
        }
        // if neo4j-service.pid exists, we kill the process once
        if (file_exists($this->config->neo4j_folder . '/data/neo4j-service.pid')) {
            shell_exec('kill -9 $(cat ' . $this->config->neo4j_folder . '/data/neo4j-service.pid) 2>>/dev/null; ');
        }
        shell_exec('cd ' . $this->config->neo4j_folder . '; ' . $sshLoad);
        if (!file_exists($this->config->neo4j_folder . '/conf/')) {
            print "No conf folder in {$this->config->neo4j_folder}\n";
        } elseif (!file_exists($this->config->neo4j_folder . '/conf/neo4j-server.properties')) {
            print "No neo4j-server.properties file in {$this->config->neo4j_folder}/conf/\n";
        } else {
            $neo4j_config = file_get_contents($this->config->neo4j_folder . '/conf/neo4j-server.properties');
            if (preg_match('/org.neo4j.server.webserver.port *= *(\\d+)/m', $neo4j_config, $r)) {
                if ($r[1] != $this->config->neo4j_port) {
                    print "Warning : Exakat's port and Neo4j's port are not the same ({$r['1']} / {$this->config->neo4j_port})\n";
                }
            }
        }
        // checking that the server has indeed restarted
        if (Tasks::$semaphore !== null) {
            fclose(Tasks::$semaphore);
            $this->doRestart();
            Tasks::$semaphore = @stream_socket_server("udp://0.0.0.0:" . Tasks::$semaphorePort, $errno, $errstr, STREAM_SERVER_BIND);
        } else {
            $this->doRestart();
        }
        display('Database cleaned with restart');
        try {
            $res = $this->gremlin->serverInfo();
            display('Restarted Neo4j cleanly');
        } catch (Exception $e) {
            display('Didn\'t restart neo4j cleanly');
        }
        $this->gremlin->query("g.addV('delete', true)");
    }