Skip to content

Commit 9d4c3cf

Browse files
author
Template builder
committed
Creating template
0 parents  commit 9d4c3cf

File tree

18 files changed

+547
-0
lines changed

18 files changed

+547
-0
lines changed

.openshift/action_hooks/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
For information about action hooks supported by OpenShift, consult the documentation:
2+
3+
http://openshift.github.io/documentation/oo_user_guide.html#the-openshift-directory

.openshift/cron/README.cron

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Run scripts or jobs on a periodic basis
2+
=======================================
3+
Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly
4+
directories will be run on a scheduled basis (frequency is as indicated by the
5+
name of the directory) using run-parts.
6+
7+
run-parts ignores any files that are hidden or dotfiles (.*) or backup
8+
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved}
9+
10+
The presence of two specially named files jobs.deny and jobs.allow controls
11+
how run-parts executes your scripts/jobs.
12+
jobs.deny ===> Prevents specific scripts or jobs from being executed.
13+
jobs.allow ===> Only execute the named scripts or jobs (all other/non-named
14+
scripts that exist in this directory are ignored).
15+
16+
The principles of jobs.deny and jobs.allow are the same as those of cron.deny
17+
and cron.allow and are described in detail at:
18+
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access
19+
20+
See: man crontab or above link for more details and see the the weekly/
21+
directory for an example.
22+
23+
PLEASE NOTE: The Cron cartridge must be installed in order to run the configured jobs.

.openshift/cron/daily/.gitignore

Whitespace-only changes.

.openshift/cron/hourly/.gitignore

Whitespace-only changes.

.openshift/cron/minutely/.gitignore

Whitespace-only changes.

.openshift/cron/monthly/.gitignore

Whitespace-only changes.

.openshift/cron/weekly/README

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Run scripts or jobs on a weekly basis
2+
=====================================
3+
Any scripts or jobs added to this directory will be run on a scheduled basis
4+
(weekly) using run-parts.
5+
6+
run-parts ignores any files that are hidden or dotfiles (.*) or backup
7+
files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles
8+
the files named jobs.deny and jobs.allow specially.
9+
10+
In this specific example, the chronograph script is the only script or job file
11+
executed on a weekly basis (due to white-listing it in jobs.allow). And the
12+
README and chrono.dat file are ignored either as a result of being black-listed
13+
in jobs.deny or because they are NOT white-listed in the jobs.allow file.
14+
15+
For more details, please see ../README.cron file.
16+

.openshift/cron/weekly/chrono.dat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Time And Relative D...n In Execution (Open)Shift!

.openshift/cron/weekly/chronograph

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "`date`: `cat $(dirname \"$0\")/chrono.dat`"

.openshift/cron/weekly/jobs.allow

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Script or job files listed in here (one entry per line) will be
3+
# executed on a weekly-basis.
4+
#
5+
# Example: The chronograph script will be executed weekly but the README
6+
# and chrono.dat files in this directory will be ignored.
7+
#
8+
# The README file is actually ignored due to the entry in the
9+
# jobs.deny which is checked before jobs.allow (this file).
10+
#
11+
chronograph
12+

.openshift/cron/weekly/jobs.deny

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Any script or job files listed in here (one entry per line) will NOT be
3+
# executed (read as ignored by run-parts).
4+
#
5+
6+
README
7+

.openshift/markers/.gitkeep

Whitespace-only changes.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The OpenShift `nodejs` cartridge documentation can be found at:
2+
3+
https://github.com/openshift/origin-server/tree/master/cartridges/openshift-origin-cartridge-nodejs/README.md

deplist.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# ***************************************************************************
3+
#
4+
# Note: This file has been deprecated and exists for backward compatibility.
5+
# Please use package.json to add dependencies to the Node modules
6+
# your application requires.
7+
#
8+
# ***************************************************************************
9+
#
10+
11+
#
12+
# For a list of globally installed modules - see file: npm_global_module_list.
13+
#

index.html

+272
Large diffs are not rendered by default.

node_modules/.gitkeep

Whitespace-only changes.

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "OpenShift-Sample-App",
3+
"version": "1.0.0",
4+
"description": "OpenShift Sample Application",
5+
"keywords": [
6+
"OpenShift",
7+
"Node.js",
8+
"application",
9+
"openshift"
10+
],
11+
"author": {
12+
"name": "OpenShift",
13+
"email": "[email protected]",
14+
"url": "http://www.openshift.com/"
15+
},
16+
"homepage": "http://www.openshift.com/",
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/openshift/origin-server"
20+
},
21+
22+
"engines": {
23+
"node": ">= 0.6.0",
24+
"npm": ">= 1.0.0"
25+
},
26+
27+
"dependencies": {
28+
"express": "~3.4.4"
29+
},
30+
"devDependencies": {},
31+
"bundleDependencies": [],
32+
33+
"private": true,
34+
"main": "server.js"
35+
}

server.js

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/env node
2+
// OpenShift sample Node application
3+
var express = require('express');
4+
var fs = require('fs');
5+
6+
7+
/**
8+
* Define the sample application.
9+
*/
10+
var SampleApp = function() {
11+
12+
// Scope.
13+
var self = this;
14+
15+
16+
/* ================================================================ */
17+
/* Helper functions. */
18+
/* ================================================================ */
19+
20+
/**
21+
* Set up server IP address and port # using env variables/defaults.
22+
*/
23+
self.setupVariables = function() {
24+
// Set the environment variables we need.
25+
self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
26+
self.port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
27+
28+
if (typeof self.ipaddress === "undefined") {
29+
// Log errors on OpenShift but continue w/ 127.0.0.1 - this
30+
// allows us to run/test the app locally.
31+
console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
32+
self.ipaddress = "127.0.0.1";
33+
};
34+
};
35+
36+
37+
/**
38+
* Populate the cache.
39+
*/
40+
self.populateCache = function() {
41+
if (typeof self.zcache === "undefined") {
42+
self.zcache = { 'index.html': '' };
43+
}
44+
45+
// Local cache for static content.
46+
self.zcache['index.html'] = fs.readFileSync('./index.html');
47+
};
48+
49+
50+
/**
51+
* Retrieve entry (content) from cache.
52+
* @param {string} key Key identifying content to retrieve from cache.
53+
*/
54+
self.cache_get = function(key) { return self.zcache[key]; };
55+
56+
57+
/**
58+
* terminator === the termination handler
59+
* Terminate server on receipt of the specified signal.
60+
* @param {string} sig Signal to terminate on.
61+
*/
62+
self.terminator = function(sig){
63+
if (typeof sig === "string") {
64+
console.log('%s: Received %s - terminating sample app ...',
65+
Date(Date.now()), sig);
66+
process.exit(1);
67+
}
68+
console.log('%s: Node server stopped.', Date(Date.now()) );
69+
};
70+
71+
72+
/**
73+
* Setup termination handlers (for exit and a list of signals).
74+
*/
75+
self.setupTerminationHandlers = function(){
76+
// Process on exit and signals.
77+
process.on('exit', function() { self.terminator(); });
78+
79+
// Removed 'SIGPIPE' from the list - bugz 852598.
80+
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
81+
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
82+
].forEach(function(element, index, array) {
83+
process.on(element, function() { self.terminator(element); });
84+
});
85+
};
86+
87+
88+
/* ================================================================ */
89+
/* App server functions (main app logic here). */
90+
/* ================================================================ */
91+
92+
/**
93+
* Create the routing table entries + handlers for the application.
94+
*/
95+
self.createRoutes = function() {
96+
self.routes = { };
97+
98+
self.routes['/asciimo'] = function(req, res) {
99+
var link = "http://i.imgur.com/kmbjB.png";
100+
res.send("<html><body><img src='" + link + "'></body></html>");
101+
};
102+
103+
self.routes['/'] = function(req, res) {
104+
res.setHeader('Content-Type', 'text/html');
105+
res.send(self.cache_get('index.html') );
106+
};
107+
};
108+
109+
110+
/**
111+
* Initialize the server (express) and create the routes and register
112+
* the handlers.
113+
*/
114+
self.initializeServer = function() {
115+
self.createRoutes();
116+
self.app = express.createServer();
117+
118+
// Add handlers for the app (from the routes).
119+
for (var r in self.routes) {
120+
self.app.get(r, self.routes[r]);
121+
}
122+
};
123+
124+
125+
/**
126+
* Initializes the sample application.
127+
*/
128+
self.initialize = function() {
129+
self.setupVariables();
130+
self.populateCache();
131+
self.setupTerminationHandlers();
132+
133+
// Create the express server and routes.
134+
self.initializeServer();
135+
};
136+
137+
138+
/**
139+
* Start the server (starts up the sample application).
140+
*/
141+
self.start = function() {
142+
// Start the app on the specific interface (and port).
143+
self.app.listen(self.port, self.ipaddress, function() {
144+
console.log('%s: Node server started on %s:%d ...',
145+
Date(Date.now() ), self.ipaddress, self.port);
146+
});
147+
};
148+
149+
}; /* Sample Application. */
150+
151+
152+
153+
/**
154+
* main(): Main code.
155+
*/
156+
var zapp = new SampleApp();
157+
zapp.initialize();
158+
zapp.start();
159+

0 commit comments

Comments
 (0)