def main()

in community/pbs/scripts/startup-script.py [0:0]


def main():
    # Disable SELinux
    subprocess.call(shlex.split('setenforce 0'))
    
    print "ARGUMENT STATIC_NODE_COUNT: @STATIC_NODE_COUNT@"
    

    #if ((INSTANCE_TYPE == "controller") and  not COMPUTE_PUBLIC_IPS):
    if (INSTANCE_TYPE == "controller"):
        # Setup a NAT gateway for the compute instances to get internet from.
        subprocess.call(shlex.split("sysctl -w net.ipv4.ip_forward=1"))
        subprocess.call(shlex.split("firewall-cmd --direct --add-rule ipv4 nat POSTROUTING 0 -o eth0 -j MASQUERADE"))
        subprocess.call(shlex.split("firewall-cmd --reload"))
        subprocess.call(shlex.split("echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf"))

    if INSTANCE_TYPE == "compute":
        while not have_internet():
            print "Waiting for internet connection"

    add_pbs_user()
    start_motd()

    print "Installing packages..."
    install_packages()

    if not os.path.exists(APPS_DIR + '/pbs'):
        os.makedirs(APPS_DIR + '/pbs')

    if INSTANCE_TYPE != "controller":
        mount_nfs_vols()

    if INSTANCE_TYPE == "controller":
        print "Installing PBS on controller node..."
        install_pbs()

        print "Installing PBS service scripts..."
        install_controller_service_scripts()

        print "Starting PBS process..."
        subprocess.call(shlex.split('/etc/init.d/pbs start'))

        print "Registering compute nodes ..."
        register_compute_nodes()

        # Export at the end to signal that everything is up
        subprocess.call(shlex.split('systemctl enable nfs-server'))
        subprocess.call(shlex.split('systemctl start nfs-server'))
        setup_nfs_exports()
        
    elif INSTANCE_TYPE == "compute":
        print "Installing PBS on compute node..."
        install_pbs()

        install_compute_service_scripts()
        subprocess.call(shlex.split('systemctl enable pbsd'))
        subprocess.call(shlex.split('systemctl start pbsd'))
        print "Installed additional components on compute node"

    end_motd()

    print "Setting up bash profile..."
    setup_bash_profile()
  
    print "Restarting PBS to get activate new configuration..."
    subprocess.call(shlex.split("/etc/init.d/pbs restart"))

    subprocess.call(["wall", "Completed PBS installation"])

    #test_pbs()

    print "Completed PBS installation on " + INSTANCE_TYPE