Init Script
    • PDF

    Init Script

    • PDF

    Article summary

    Available in VPC

    Init Script describes the page configuration and script information of the Init Script menu, and describes how to create and manage scripts.

    Init Script is a feature that allows a prewritten script to be run automatically when creating a server. You can utilize this feature in various cases, including when creating multiple servers for the same purpose at once, when periodically creating servers in the same environment, and when management of initial server environment by purpose of use is required.

    Check script information

    You can check script information on the Init Script page.

    Init Script page

    From the NAVER Cloud Platform portal, click the Console > Services > Compute> Server > Init Script menus, in that order, to view the Init Script page.

    The Init Script page is laid out as follows:
    server-initscript-vpc_screen_en

    FieldDescription
    ① Menu nameName of the menu currently being checked and the number of created scripts
    ② Basic featuresFeatures provided when you initially enter the Init Script menu
    • [Create Init Script] button: click to Create script
    • [Learn more about the product] button: click to move to the Server introduction page
    • [Refresh] button: click to refresh the script list
    ③ Post-creation featuresFeatures provided after creating the script
    ④ Search windowSearch scripts by script name
    ⑤ Script listList of created scripts
    • Script name: name entered when creating script
    • Description: description of script Click the
      • [Edit] button to edit the description
    • View/Edit: [Shortcut] button to view and edit script information
    • OS type: OS type for installing script
    • Creation date and time: date and time of script creation
    • Last edited: date and time the script was last edited

    Create script

    You can directly create a script that will be automatically run when creating servers.
    The following describes how to create a script.

    1. Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.

    2. Click the Services > Compute > Server menus, in that order.

    3. Click the Init Script menu.

    4. Click the [Create script] button.

    5. Specify the script name and the OS type, write the script, and then click the [Create script] button.

      Caution

      Do not include content that may create security breaches in the script content. In the event of a problem caused by this, you may be held accountable.

      • You can enter between 3-100 characters of capital and lowercase letters, numbers, hyphens (-), and underbars (_) in the script name.
      • The content of the script can only be in English. You can't include Korean letters or annotations.
        • The scripts, such as Python, Perl, Shell, and so on can be used in Linux. In the first line, specify the path of the script you want to run in formats such as #!/bin/bash, #!/usr/bin/env python, #!bin/perl, and so on.
        • You can only use Visual Basic scripts in Windows.
    6. From the Init Script pop-up window, click the [OK] button.

      • The created script is displayed in the list.

    Edit script

    You can edit the OS type and content of the created scripts.
    The following describes how to edit the OS type and content of a script.

    1. Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.
    2. Click the Services > Compute > Server menus, in that order.
    3. Click the Init Script menu.
    4. Click to select the script to edit from the script list, and click the [Edit] button.
    5. After editing the content, click the [Edit script] button.
    6. From the Init Script pop-up window, click the [OK] button.
      • The edited information is saved.

    Delete script

    The following describes how to delete a created script.

    1. Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.
    2. Click the Services > Compute > Server menus, in that order.
    3. Click the Init Script menu.
    4. Click to select the script to delete from the script list, and click the [Delete] button.
    5. Check the details in the Delete script pop-up window, and then click the [OK] button.
      • The script is deleted and disappears from the list.

    Create server with script

    To automatically run the script in the server, you must specify the script in the settings information when creating the server.
    In the Set server (New console/Existing console) step, select the desired script in the Script item.

    Note
    • Scripts can't be used when creating a server or replica server using a server image.
    • Even if the server status is displayed as Running, the script installation may continue to be in progress. To see whether the installation is completed, check the progress status log.
      • Linux: /var/log/ncloud-init.log
      • Windows: C:\Program Files(X86)\NBP\ncloud-init\logs

    Script example

    See the following script examples:

    Linux server

    Here are scripts that can be used in a Linux server.

    Install Apache HTTP Server

    The script for installing Apache HTTP Server is as follows:

    Perl script example

    #!/usr/bin/perl –w
    
    $result = `yum update-to httpd`;
    
    if ($result =~ /but not installed/) {
      print "http available\n";
      if ($result =~ /httpd available/) {
        print "http not installed\n";
        $iresult = `yum -y install httpd`;
        if ($iresult =~ /Complete/) {
          print "http installed\n";
          open (WP, ">/var/www/html/index.html") || die "cannot open index.html\n";
          print WP `ifconfig eth0 | grep "inet addr" | awk \'{print \$2}\'`;
          close(WP);
          `chkconfig --level 345 httpd on`;
          `service httpd restart`;
        }
      }
      else {
        print "http NOT available\n";
      }
    }
    else {
      print "http already installed\n";
    }
    

    Shell script example

    #!/bin/sh
    
    result=`yum update-to httpd`
    
    if [[ $result =~ *"but not installed"* ]]
    then
       if [[ $result =~ *"httpd available"* ]]
       then
          echo 'http available'
          echo 'http not installed'
    
          $iresult=`yum -y install httpd`
    
          if [[ $iresult =~ *"Complete"* ]]
          then
             echo 'http installed'
             echo 'test' >> /var/www/html/index.html
    
             /sbin/chkconfig --level 345 httpd on
             /sbin/service httpd restart
          fi
       else
          echo 'http Not available'
       fi
    else
       echo 'http already installed'
    fi
    

    Windows server

    Here are scripts that can be used in a Windows server.

    Install Java JDK

    The script for installing Java JDK is as follows:

    Visual Basic script example

    LOG_DIRECTORY = "C:\Windows\Temp"
    DEFAULT_LOG_FILE_PATH = LOG_DIRECTORY + "\init-install.log"
    
    Set ws = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    ' logging (file & stdout)
    Function logInfo(str)
        WScript.Echo CStr(Now()) + " [INFO]: " + str
        Set objFile = objFSO.OpenTextFile(DEFAULT_LOG_FILE_PATH, 8, True)
        objFile.WriteLine CStr(Now()) + " [INFO]: " + str
        objFile.Close
    End Function
    
    tmp_jdk_download_path="C:\Windows\Temp\jdk.exe"
    jdk_installer_url="http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-windows-x64.exe"
    
    cmd="wget --no-check-certificate --no-cookies --header ""Cookie: oraclelicense=accept-securebackup-cookie"" " + jdk_installer_url + " -O " + tmp_jdk_download_path + " -c"
    
    
    ' download jdk
    ws.Run cmd,,TRUE
    
    WScript.Sleep 5000
    
    javaInstallCmdStr = "C:\Windows\Temp\jdk.exe /s /L C:\Windows\Temp\jdk-install.log"
    Set oExec1 = ws.Exec(javaInstallCmdStr)
    
    Do While oExec1.Status = 0
        loginfo "Info: Wait for install JDK to finish."
        WScript.Sleep 10000
    Loop
    

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.