Select the Launch Command
You have total control over how you launch an application. You can launch directly by invoking the specific language command or use a shell script. The application is executed in a Linux container, so most of the rules that apply to running a command in Linux apply.
For Java, Node, PHP, Python, Ruby, Go, and .Net applications you can specify the launch command in the manifest.json
metadata file that you include with the application. See Creating the manifest.json File.
For more details, see the launch command for each language.
Java
The examples that follow are based on the following assumptions:
-
The home directory for your application is stored in the
$APP_HOME
environment variable. -
Your application execution code is stored in a JAR file named
app.jar
, which is located in$APP_HOME
. -
All required Java libraries are stored in the
lib
directory. Thelib
directory is included as part of the final archive as a subdirectory from the archive root directory. -
The
lib
directory contains the following JAR libraries:web.jar
,rest.jar
,media.jar
.
If the lib
directory isn’t included in the application JAR file, then you must specify the classpath so the JVM can find all the classes necessary to run the application.
Example 3-4 Setting the Classpath in the Manifest.mf File
Given these assumptions, this java command could launch your application.
java -jar app.jar
The JAR must include a Manifest.mf
file with the Main-Class
attribute set to the main class and the Class-Path
attribute set to the lib/web.jar lib/rest.jar lib/media.jar
directory.
Example 3-5 Setting the Classpath Using the -cp Option
You can use the -classpath
or -cp
option to specify the location of the main application JAR and the dependent JAR files. This option is incompatible with the –jar
option, so you execute the main class directly. For example:
java -cp $APP_HOME/app.jar:$APP_HOME/lib/* com.example.Main
Note that on Linux, the path separator is a colon, not a semicolon as on Windows.
Example 3-6 Using an Uber JAR
If the application is packaged as an uber JAR called uber-app.jar
, with all the dependencies available in the JAR, then an external classpath isn’t needed. The uber JAR must include a Manifest.mf
with the main class. To run the application:
java -jar uber-app.jar
Java EE
For a Java EE applications, a launch command is unnecessary. If it is present, then it is ignored.
Node
Configure the launch command in the manifest.json file, for example:
Example 3-7 Sample manifest.json File for a Node Application
{
"runtime":{
"majorVersion":"4"
},
"command": "node server.js",
"release": {},
"notes": ""
}
PHP
A PHP application typically doesn’t need a launch command. Unless another file is specified in the application URL, the index file opens first, whether the extension is .htm, .html,
or .php.
If you use a launch command because you need to run a script before starting your application, the last command in the script must be apache2–run.
PHP depends on the Apache HTTP server and Oracle Application Container Cloud Service doesn’t start your application automatically if a launch command is present.
Python
Configure the launch command in the manifest.json file, for example:
Example 3-8 Sample manifest.json File for a Python Application
{
"runtime": {
"majorVersion": "3.6.0"
},
"command": "python app.py",
"notes": "Simple REST Service"
}
Ruby
Configure the launch command in the manifest.json file, for example:
Example 3-9 Sample manifest.json File for a Ruby Application
{
"runtime":{
"majorVersion":"2.4.1"
},
"command": "ruby app.rb",
"mode": "rolling"
}
Go
Configure the launch command in the manifest.json file, for example:
Example 3-10 Sample manifest.json File for a Go Application
{
"runtime":{
"majorVersion":"1.8.3"
},
"command": "go run app.go",
"mode": "rolling"
}
.Net
Configure the launch command in the manifest.json file, for example:
Example 3-11 Sample manifest.json File for a .Net Application
{
"runtime":{
"majorVersion":"2.0.0-runtime"
},
"command": "dotnet publish/sample-app.dll"
}
Executing the Application with a Shell Script
As an alternative, you can execute your application using a shell script.
Example 3-12 Sample start.sh Script for a Python Application
#!/bin/sh
# Define PYTHONPATH as local modules folder
export PYTHONPATH=${APP_HOME}/modules
# Extract LIBAOI libs from Debian package (into ./lib/x86_64-linux-gnu)
dpkg-deb -R libaio1_0.3.110-1_amd64.deb ${APP_HOME}
# Finalize OCI installation by creating required softlink
ln -s ${APP_HOME}/lib/instantclient_12_2/libclntsh.so.12.1 ${APP_HOME}/lib/instantclient_12_2/libclntsh.so
# Add OCI and LIBAIO to shared library path
export LD_LIBRARY_PATH=${APP_HOME}/lib/instantclient_12_2:${APP_HOME}/lib/x86_64-linux-gnu
# Install Python packages into local modules folder
pip --no-cache-dir install -r requirements.txt -t ${PYTHONPATH} --upgrade
python ${APP_HOME}/app.py
Example 3-13 Sample manifest.json File for a Python Application
{
"runtime": {
"majorVersion": "3.6.0"
},
"command": "sh ./start.sh"
}