- Print
- PDF
Init Script
- Print
- PDF
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:
Field | Description |
---|---|
① Menu name | Name of the menu currently being checked and the number of created scripts |
② Basic features | Features provided when you initially enter the Init Script menu
|
③ Post-creation features | Features provided after creating the script
|
④ Search window | Search scripts by script name |
⑤ Script list | List of created scripts
|
Create script
You can directly create a script that will be automatically run when creating servers.
The following describes how to create a script.
Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.
Click the Services > Compute > Server menus, in that order.
Click the Init Script menu.
Click the [Create script] button.
Specify the script name and the OS type, write the script, and then click the [Create script] button.
CautionDo 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.
- 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
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.
- Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.
- Click the Services > Compute > Server menus, in that order.
- Click the Init Script menu.
- Click to select the script to edit from the script list, and click the [Edit] button.
- After editing the content, click the [Edit script] button.
- 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.
- Click the environment you are using in the Region menu and Platform menu of NAVER Cloud Platform console.
- Click the Services > Compute > Server menus, in that order.
- Click the Init Script menu.
- Click to select the script to delete from the script list, and click the [Delete] button.
- 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.
- 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