├── .openshift ├── action_hooks │ ├── deploy │ ├── post_start_nodejs │ ├── pre_restart_nodejs │ └── pre_stop_nodejs ├── lib │ └── onbb_utils.sh ├── markers │ └── use_npm └── tools │ ├── ensure-package-scripts.js │ ├── test-ssl.js │ └── wait-for-nodebb-to-start.js ├── README.markdown ├── openshift-app.js └── patches └── openshift-0.6.1.diff /.openshift/action_hooks/deploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 3 | source "${OPENSHIFT_REPO_DIR}.openshift/lib/onbb_utils.sh" 4 | 5 | # 6 | # Run NodeBB setup passing through all its output 7 | # 8 | function onbb_setup_nodebb () { 9 | echo "Running setup" 10 | 11 | # Remember current working directory and switch to repo directory 12 | local d=`pwd` 13 | cd $OPENSHIFT_REPO_DIR 14 | 15 | # Generate name 16 | local name=$OPENSHIFT_APP_NAME 17 | 18 | # Generate password 19 | local pass=`tr -cd '[:alnum:]' < /dev/urandom | fold -w16 | head -n1 | fold -w4 | paste -sd\- -` 20 | 21 | # Generate NodeBB secret 22 | local secret=`uuidgen -r` 23 | 24 | # Try to get e-mail, if not found, use fake address 25 | local email="$NODEBB_ADMIN_EMAIL" 26 | if [ "$email" = "" ] ; then 27 | email="$name@127.0.0.1" 28 | fi 29 | 30 | # Prepare JSON 31 | local json='{"secret": "'$secret'", "admin:username": "'$name'", "admin:email": "'$email'", "admin:password": "'$pass'", "admin:password:confirm": "'$pass'"}' 32 | 33 | # Run setup and redirect output to file, so we can search it later 34 | local LOGFILE="logs/openshift-nodebb-setup.log" 35 | node app --setup "$json" 2>&1 | tee $LOGFILE 36 | 37 | # Success marker 38 | local failed=1 39 | 40 | # Check result by looking for specific text 41 | # Would be better if NodeBB's setup would exit with code 42 | # but it does not, so we use this fragile workaround. 43 | if cat $LOGFILE | grep -q "NodeBB Setup Completed" ; then 44 | # Success 45 | failed=0 46 | 47 | if cat $LOGFILE | grep -q "running initial user setup" ; then 48 | # Created new admin user and finished 49 | onbb_echo_result_of_setup_success $name $pass $email 50 | else 51 | # Finished upgrade (admin user already existed) 52 | onbb_echo_result_of_setup_success 53 | fi 54 | 55 | # Remove log file 56 | rm $LOGFILE 57 | else 58 | if cat $LOGFILE | grep -q "There was a problem completing NodeBB\|NodeBB Setup Aborted\|Error: listen EADDRINUSE" ; then 59 | # Failed 60 | onbb_echo_result_of_setup_failed $LOGFILE "There was a problem completing NodeBB setup." 61 | else 62 | # Possibly failed 63 | onbb_echo_result_of_setup_failed $LOGFILE 64 | fi 65 | fi 66 | 67 | # Switch back to previous directory 68 | cd "$d" 69 | 70 | # Return error when failed 71 | if [ $failed -eq 1 ] ; then 72 | return 1 73 | fi 74 | } 75 | 76 | # 77 | # Prepare everything and run setup 78 | # 79 | function onbb_deploy () { 80 | # Get version number 81 | local version=$(onbb_get_nodebb_version) 82 | 83 | echo "Stopping NodeBB processes" 84 | onbb_wait_until_stopped 3 || return 1 85 | 86 | echo "Configuring NodeBB $version for OpenShift" 87 | 88 | onbb_setup_sourcecode $version || return 1 89 | onbb_setup_environment || return 1 90 | onbb_setup_nodebb || return 1 91 | } 92 | 93 | # Exit with error if something went wrong - that will prevent rest of the deployment process from erroring even more. 94 | onbb_deploy || exit 1 95 | -------------------------------------------------------------------------------- /.openshift/action_hooks/post_start_nodejs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 3 | source "${OPENSHIFT_REPO_DIR}.openshift/lib/onbb_utils.sh" 4 | 5 | # Hide stdout, keep stderr, wait, output result 6 | onbb_wait_until_ready 120 >/dev/null || (onbb_echo_result_of_start_failed && exit 1) || exit 1 7 | onbb_echo_result_of_start_success -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_restart_nodejs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 3 | source "${OPENSHIFT_REPO_DIR}.openshift/lib/onbb_utils.sh" 4 | 5 | # Make sure NodeBB is stopped 6 | onbb_wait_until_stopped 3 || exit 1 -------------------------------------------------------------------------------- /.openshift/action_hooks/pre_stop_nodejs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 3 | source "${OPENSHIFT_REPO_DIR}.openshift/lib/onbb_utils.sh" 4 | 5 | # Make sure NodeBB is stopped 6 | onbb_wait_until_stopped 3 || exit 1 -------------------------------------------------------------------------------- /.openshift/lib/onbb_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 4 | 5 | # 6 | # Echo NodeBB version number from package.json file 7 | # 8 | function onbb_get_nodebb_version () { 9 | cat "${OPENSHIFT_REPO_DIR}package.json" | grep version | sed -s 's/[^0-9\.]//g' 10 | } 11 | 12 | # 13 | # Echo URL found in config.json 14 | # 15 | function onbb_get_url_from_config () { 16 | cat "${OPENSHIFT_REPO_DIR}config.json" | sed -nr '/.*"url":\s*"(.*)".*/{s%.*:\s*"(https?://[^\/]+)/?".*%\1%p;}' 17 | } 18 | 19 | # 20 | # Print information about failed NodeBB setup. 21 | # 22 | # @param {string} [logfile=log/openshift-nodebb-setup.log] Path to NodeBB logfile 23 | # @param {string} [reason] Possible reason as a short one-liner, defaults to "unknown" 24 | # 25 | function onbb_echo_result_of_setup_failed () { 26 | local logfile=$1 27 | local reason=$2 28 | local message="Setup failed." 29 | 30 | if [ "$logfile" = "" ] ; then 31 | logfile="logs/openshift-nodebb-setup.log" 32 | fi 33 | 34 | if [ "$reason" = "" ] ; then 35 | message="Setup possibly failed - unknown result." 36 | reason="There was a problem completing NodeBB setup." 37 | fi 38 | 39 | client_result "" 40 | client_result ".-============================================-." 41 | client_result ". Setup failed." 42 | client_result "." 43 | client_result ". $reason" 44 | client_result "." 45 | client_result ". Check logfile for more information:" 46 | client_result ". $logfile" 47 | client_result "^-============================================-^" 48 | client_result "" 49 | } 50 | 51 | # 52 | # Print information about successfull NodeBB setup. 53 | # 54 | # @param {string} [name] Only if new admin account was created 55 | # @param {string} [password] Only if new admin account was created 56 | # @param {string} [email] Only if new admin account was created 57 | # 58 | function onbb_echo_result_of_setup_success () { 59 | local name=$1 60 | local pass=$2 61 | local email=$3 62 | 63 | if [ "$name" = "" -o "$pass" = "" -o "$email" = "" ] ; then 64 | client_result "" 65 | client_result ".-============================================-." 66 | client_result ". Setup finished." 67 | client_result "." 68 | client_result ". Please wait for NodeBB to start." 69 | client_result "^-============================================-^" 70 | client_result "" 71 | else 72 | client_result "" 73 | client_result ".-============================================-." 74 | client_result ". Setup finished." 75 | client_result "." 76 | client_result ". New administrator user has been created:" 77 | client_result "." 78 | client_result ". email : $email" 79 | client_result ". login : $name" 80 | client_result ". password: $pass" 81 | client_result "." 82 | client_result ". Please wait for NodeBB to start." 83 | client_result "." 84 | client_result ". WARNING: Be sure to change admin password" 85 | client_result ". after first log in!" 86 | client_result "^-============================================-^" 87 | client_result "" 88 | fi 89 | } 90 | 91 | # 92 | # Print information about failed start of NodeBB. 93 | # 94 | # @param {string} [logfile=log/output.log] Path to NodeBB logfile 95 | # 96 | function onbb_echo_result_of_start_failed () { 97 | local logfile=$1 98 | 99 | if [ "$logfile" = "" ] ; then 100 | logfile="logs/output.log" 101 | fi 102 | 103 | client_result "" 104 | client_result ".-============================================-." 105 | client_result ". NodeBB failed to start for some reason." 106 | client_result "." 107 | client_result ". Check logfile for more information:" 108 | client_result ". logs/output.log" 109 | client_result "^-============================================-^" 110 | client_result "" 111 | } 112 | 113 | # 114 | # Print information about NodeBB started and ready. 115 | # 116 | # @param {string} [url] URL of NodeBB instance, defaults to the one found in config.json 117 | # 118 | function onbb_echo_result_of_start_success () { 119 | local url=$1 120 | 121 | if [ "$url" = "" ] ; then 122 | url=$(onbb_get_url_from_config) 123 | fi 124 | 125 | client_result "" 126 | client_result ".-============================================-." 127 | client_result ". NodeBB is ready." 128 | client_result "." 129 | client_result ". You can visit it at:" 130 | client_result ". $url" 131 | client_result "." 132 | client_result ". You can log in to it at:" 133 | client_result ". $url/login" 134 | client_result "^-============================================-^" 135 | client_result "" 136 | } 137 | 138 | # 139 | # Setup NODEBB_FQDN, preferring OPENSHIFT_APP_DNS_ALIAS, then OPENSHIFT_APP_DNS, or fail. 140 | # 141 | function onbb_setup_fqdn () { 142 | local FQDN="$OPENSHIFT_APP_DNS_ALIAS" 143 | 144 | if [ "$FQDN" = "" ] ; then 145 | FQDN="$OPENSHIFT_APP_DNS" 146 | fi 147 | 148 | if [ "$FQDN" = "" ] ; then 149 | return 1 150 | fi 151 | 152 | export NODEBB_FQDN="$FODN" 153 | } 154 | 155 | # 156 | # Setup NODEBB_ADMIN_EMAIL from NODEBB_ADMIN_EMAIL, or from OPENSHIFT_LOGIN, or as OPENSHIFT_APP_NAME@NODEBB_FQDN, or fail. 157 | # 158 | function onbb_setup_email () { 159 | local email="$NODEBB_ADMIN_EMAIL" 160 | 161 | if [ "$email" = "" ] ; then 162 | email="$OPENSHIFT_LOGIN" 163 | fi 164 | 165 | if [ "$email" = "" -a "$NODEBB_FQDN" != "" ] ; then 166 | email="$OPENSHIFT_APP_NAME@$NODEBB_FQDN" 167 | fi 168 | 169 | if [ "$email" = "" ] ; then 170 | return 1 171 | fi 172 | 173 | export NODEBB_ADMIN_EMAIL="$email" 174 | } 175 | 176 | # 177 | # Find and apply all patches matching NodeBB version number. 178 | # 179 | # @param [version] defaults to $(onbb_get_nodebb_version) 180 | # 181 | function onbb_setup_sourcecode () { 182 | local version=$1 183 | 184 | local d=`pwd` 185 | cd "$OPENSHIFT_REPO_DIR" 186 | 187 | if [ "$version" = "" ] ; then 188 | version=$(onbb_get_nodebb_version) 189 | fi 190 | 191 | local patches=`ls patches/openshift-$version*.diff 2>/dev/null` 192 | if [ "$patches" != "" ] ; then 193 | # Apply patches for selected version 194 | for changeset in $patches ; do 195 | echo "Applying changeset "$changeset 196 | local rejected=$changeset".rejected" 197 | patch -N --no-backup-if-mismatch -s -r $rejected -p1 < $changeset 198 | if [ -f "$rejected" ] ; then 199 | echo "Changeset $changeset was rejected. Check $rejected to see what parts of it could not be applied" 200 | fi 201 | done 202 | fi 203 | 204 | cd "$d" 205 | } 206 | 207 | # 208 | # Setup directories and ensure everything is set up ok 209 | # 210 | function onbb_setup_environment () { 211 | local d=`pwd` 212 | cd "$OPENSHIFT_REPO_DIR" 213 | 214 | # Make sure, that `npm start` will run `nodebb start`, so NodeBB can restart itself and use correct logs 215 | .openshift/tools/ensure-package-scripts.js || return 1 216 | 217 | # Make sure NODEBB_FQDN is set 218 | onbb_setup_fqdn || return 1 219 | 220 | # Make sure NODEBB_ADMIN_EMAIL is set 221 | onbb_setup_email || return 1 222 | 223 | # Make sure, that node.env, if it exists, will know to run nodebb 224 | # This is needed only for legacy support and only on OpenShift's default nodejs-0.10 cartridge 225 | local envFile="${OPENSHIFT_NODEJS_DIR}configuration/node.env" 226 | if [ -f $envFile ] ; then 227 | echo "Patching $envFile" 228 | sed -i 's/server.js/nodebb/g' "$envFile" 229 | sed -i 's/app.js/nodebb/g' "$envFile" 230 | fi 231 | 232 | # Override app.js 233 | # We have to move original and replace it with our "wrapper" 234 | # because NodeBB calls hardcoded "app.js" in some cases 235 | # and we do not want to modify code in too many places. 236 | if [ -f "openshift-app.js" ] ; then 237 | echo "Overriding app.js" 238 | mv app.js _app.js 239 | mv openshift-app.js app.js 240 | fi 241 | 242 | local NODEBB_DATA_DIR="${OPENSHIFT_DATA_DIR}nodebb" 243 | 244 | # Make sure there is persistent data directory 245 | mkdir -p "$NODEBB_DATA_DIR" 246 | 247 | # Symlink public/uploads to $OPENSHIFT_DATA_DIR/nodebb/public-uploads 248 | local uploadsDir="$NODEBB_DATA_DIR/public-uploads" 249 | if [ `readlink -f $uploadsDir` != `readlink -f public/uploads` ] ; then 250 | echo "Pointing uploads directory to $uploadsDir" 251 | cp -a public/uploads "$uploadsDir" 252 | rm -rf public/uploads 253 | ln -s "$uploadsDir" public/uploads 254 | fi 255 | 256 | # Symlink logs to $OPENSHIFT_DATA_DIR/nodebb/logs 257 | local logsDir="$NODEBB_DATA_DIR/logs" 258 | if [ `readlink -f $logsDir` != `readlink -f logs` ] ; then 259 | echo "Pointing logs directory to $logsDir" 260 | cp -a logs "$logsDir" 261 | rm -rf logs 262 | ln -s "$logsDir" logs 263 | fi 264 | 265 | # Symlink config.json to $OPENSHIFT_DATA_DIR/nodebb/config.json 266 | local configFilePath="$NODEBB_DATA_DIR/config.json" 267 | if [ `readlink -f $configFilePath` != `readlink -f config.json` ] ; then 268 | echo "Pointing config.json to $configFilePath" 269 | if [ -f config.json ] ; then 270 | cp -a config.json "$configFilePath" 271 | fi 272 | if [ ! -f "$configFilePath" ] ; then 273 | # Create valid, "empty" config, so we can create symlink 274 | echo -n "{}" > "$configFilePath" 275 | fi 276 | rm -rf config.json 277 | ln -s "$configFilePath" config.json 278 | fi 279 | 280 | cd "$d" 281 | } 282 | 283 | # 284 | # Ensure that NodeBB is stopped. Wait until it is or time runs up 285 | # 286 | # @param {number} [timeout=2] In seconds 287 | # @param {number} [graceful=yes] "no" to just kill node processes 288 | # 289 | function onbb_wait_until_stopped () { 290 | local seconds=$1 291 | local graceful=$2 292 | 293 | if [ "$seconds" = "" ] ; then 294 | seconds=2 295 | fi 296 | 297 | if [ "$graceful" = "" ] ; then 298 | graceful="yes" 299 | fi 300 | 301 | # Find first PID of node process of current user 302 | local PID=`pgrep -u $OPENSHIFT_APP_UUID -x node -o` 303 | 304 | # Return early if it stopped already 305 | if [ "$PID" = "" ] ; then 306 | return 0 307 | fi 308 | 309 | # Return error if there is no time left 310 | if [ "$seconds" -le "0" ] ; then 311 | return 1 312 | fi 313 | 314 | # Stop it gracefully if we have more than a second of time left 315 | if [ "$seconds" -gt "1" -a "$graceful" = "yes" ] ; then 316 | local d=`pwd` 317 | cd "$OPENSHIFT_REPO_DIR" 318 | npm stop 2>/dev/null 319 | cd "$d" 320 | 321 | sleep 1 322 | 323 | onbb_wait_until_stopped $(echo "$seconds - 1" | bc) "no" || return 1 324 | return 0 325 | fi 326 | 327 | # KILL! 328 | kill "$PID" || return 1 329 | onbb_wait_until_stopped $(echo "$seconds - 1" | bc) "no" || return 1 330 | 331 | return 0 332 | } 333 | 334 | # 335 | # Watch NodeBB log until it says it is listening for connections. 336 | # 337 | # @param {number} [timeout=120] In seconds 338 | # 339 | function onbb_wait_until_ready () { 340 | local seconds=$1 341 | 342 | if [ "$seconds" = "" ] ; then 343 | # 2 minutes 344 | seconds=120 345 | fi 346 | 347 | local milliseconds=$(echo "$seconds * 1000" | bc) 348 | 349 | ${OPENSHIFT_REPO_DIR}.openshift/tools/wait-for-nodebb-to-start.js $milliseconds || return 1 350 | } -------------------------------------------------------------------------------- /.openshift/markers/use_npm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahwayakchih/openshift-nodebb/a81e549953f5d86db63972f180d9bcec19ee0580/.openshift/markers/use_npm -------------------------------------------------------------------------------- /.openshift/tools/ensure-package-scripts.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * This script will read package.json data and ensure that it has `scripts.start` and `scripts.stop` 5 | * set correctly. If it has to change anything, it will save updated package.json file. 6 | */ 7 | var fs = require('fs'); 8 | 9 | var packageFilePath = './package.json'; 10 | var package = JSON.parse(fs.readFileSync(packageFilePath)); 11 | 12 | var scriptStart = './nodebb start'; 13 | var scriptStop = './nodebb stop'; 14 | 15 | var needsSave = false; 16 | 17 | if (!package.scripts || package.scripts.start !== scriptStart || package.scripts.stop !== scriptStop) { 18 | needsSave = true; 19 | 20 | package.scripts.start = scriptStart; 21 | package.scripts.stop = scriptStop; 22 | } 23 | 24 | if (needsSave) { 25 | fs.writeFileSync(packageFilePath, JSON.stringify(package, null, ' ')); 26 | } 27 | -------------------------------------------------------------------------------- /.openshift/tools/test-ssl.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * This script will temporarily start webserver on HTTP and send request to it 5 | * through a specified domain using HTTPS to check if it works ok, e.g., 6 | * if certificate is valid, if connection is routed correctly, etc... 7 | */ 8 | var https = require('https'); 9 | var http = require('http'); 10 | var path = require('path'); 11 | 12 | /** 13 | * Start server for a time of single request, check if it responds with correct data. 14 | * Depend on Node to check SSL certificate validity. 15 | * 16 | * @param {!string} ip IP number to listen on 17 | * @param {!number} port Port number to listen on 18 | * @param {!string} hostname Domain name to request through HTTPS 19 | * @param {!Function} callback Will call with error or null as first argument 20 | */ 21 | function testSSL (ip, port, hostname, callback) { 22 | // OpenShift terminates SSL and passes request through regular HTTP. 23 | // So we need to setup HTTP server, and call it through HTTPS. 24 | var header = 'X-OpenShift-NodeBB-Test'; 25 | var token = "" + Math.random(); 26 | 27 | var server = http.createServer(function (req, res) { 28 | res.setHeader(header, token); 29 | res.writeHead(200, {'Content-Type': 'text/plain', 'Connection': 'close'}); 30 | res.end('OK'); 31 | }); 32 | 33 | var cleanup = function cleanup (err) { 34 | if (!server) { 35 | return; 36 | } 37 | 38 | server.close(callback.bind(null, err)); 39 | server = null; 40 | cleanup = null; 41 | }; 42 | 43 | server.listen(port, ip || null, null, function onListening () { 44 | https.get('https://' + hostname, function (res) { 45 | res.on('data', function () {}); 46 | cleanup(res.headers[header.toLowerCase()] !== token ? new Error('Wrong data returned') : null); 47 | }).on('error', cleanup); 48 | }); 49 | }; 50 | 51 | /* 52 | * Exports 53 | */ 54 | if (typeof module === 'object') { 55 | module.exports = testSSL; 56 | } 57 | 58 | // Exit if we're not called as a standalone application 59 | if (require.main !== module) { 60 | return; 61 | } 62 | 63 | // Get args passed from command line 64 | var argv = process.argv.slice(); 65 | 66 | /** 67 | * Domain name to be tested. 68 | * 69 | * @type {string} 70 | */ 71 | var testFQDN = argv.pop(); 72 | 73 | /** 74 | * Port number to be used for test 75 | * 76 | * @type {number} 77 | */ 78 | var testPORT = Math.min(Math.max(parseInt(argv.pop() || '', 10), 0), 65535); 79 | 80 | // If one of args is not valid, show usage info and exit. 81 | if (isNaN(testPORT) || !testFQDN) { 82 | var filename = path.basename(module.filename); 83 | console.log('USAGE: ' + filename + ' port hostname'); 84 | console.log('EXAMPLE: ' + filename + ' ' + (process.env.OPENSHIFT_NODEJS_PORT || 8080) + ' ' + (process.env.OPENSHIFT_APP_DNS || 'example.com')); 85 | return process.exit(1); 86 | } 87 | 88 | // Run test 89 | testSSL(process.env.OPENSHIFT_NODEJS_IP || null, testPORT, testFQDN, function (err) { 90 | if (err) { 91 | console.error(err); 92 | } 93 | 94 | process.exit(err ? 1 : 0); 95 | }); -------------------------------------------------------------------------------- /.openshift/tools/wait-for-nodebb-to-start.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * This script will read output of tails from logs until either: 5 | * 6 | * - line about NodeBB listening is found 7 | * - time runs out 8 | */ 9 | var spawn = require('child_process').spawn; 10 | var path = require('path'); 11 | 12 | var NODEBB_IS_RUNNING_REGEX = /NodeBB is now listening on:/; 13 | 14 | /** 15 | * Spawn `tail -f -n 0 logs/output.log` process and wait until output about NodeBB listening shows up 16 | * or time runs out. 17 | * 18 | * @param {number} [timeout=120000] Miliseconds before assuming failure 19 | * @param {Function} [callback] Will be called with error or null as first argument 20 | */ 21 | function waitForNodeBBToStart (timeout, callback) { 22 | var tail; 23 | var result = false; 24 | var startTime; 25 | 26 | if (!callback && timeout instanceof Function) { 27 | callback = timeout; 28 | timeout = null; 29 | } 30 | 31 | if (!timeout) { 32 | // 2 minutes 33 | timeout = 120000; 34 | } 35 | 36 | tail = spawn('tail', ['-F', '-n', '0', path.join(process.env.OPENSHIFT_REPO_DIR, 'logs/output.log')]); 37 | var logs = ''; 38 | var errors = ''; 39 | 40 | tail.stdout.on('data', function (data) { 41 | if (!tail) { 42 | return; 43 | } 44 | 45 | logs = (logs + data.toString('utf8')).replace(/[^\n]*\n/g, function (chunk) { 46 | console.log(chunk); 47 | 48 | if (NODEBB_IS_RUNNING_REGEX.test(chunk)) { 49 | result = true; 50 | } 51 | 52 | return ''; 53 | }); 54 | 55 | if (result) { 56 | tail.kill(); 57 | tail = null; 58 | } 59 | }); 60 | 61 | tail.stderr.on('data', function (data) { 62 | if (!tail) { 63 | return; 64 | } 65 | 66 | errors = (errors + data.toString('utf8')).replace(/[^\n]*\n/g, function (chunk) { 67 | console.error(chunk); 68 | return ''; 69 | }); 70 | }); 71 | 72 | tail.on('close', function (code, signal) { 73 | var err = null; 74 | 75 | if (!result) { 76 | if (errors.length) { 77 | console.error(errors); 78 | } 79 | 80 | if (Date.now() - startTime >= timeout) { 81 | err = new Error('Error: Timeout'); 82 | } 83 | else if (!code && signal) { 84 | err = new Error('Error: Killed with ' + signal); 85 | } 86 | else { 87 | err = new Error('Error: Exited with code: ' + code + ' and signal: ' + signal); 88 | } 89 | } 90 | 91 | callback(err); 92 | }); 93 | 94 | startTime = Date.now(); 95 | setTimeout(tail.kill.bind(tail), timeout); 96 | }; 97 | 98 | /* 99 | * Exports 100 | */ 101 | if (typeof module === 'object') { 102 | module.exports = waitForNodeBBToStart; 103 | } 104 | 105 | // Exit if we're not called as a standalone application 106 | if (require.main !== module) { 107 | return; 108 | } 109 | 110 | // Get args passed from command line 111 | var argv = process.argv.slice(); 112 | 113 | /** 114 | * Timeout in miliseconds 115 | * 116 | * @type {number} 117 | */ 118 | var timeout = parseInt(argv.pop(), 10) || null; 119 | 120 | // Start waiting 121 | waitForNodeBBToStart(timeout, function (err) { 122 | if (err) { 123 | console.error(err.message); 124 | } 125 | 126 | process.exit(err ? 1 : 0); 127 | }); -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | NodeBB in the OpenShift v2 cloud 2 | ================================ 3 | 4 | **NOT MAINTAINED:** [2018-03-15] this guide was created when OpenShift v2 was available, which is not longer true. New version of OpenShift changed a lot of things, and information found in this guide will not work with it. 5 | 6 | This document will guide you through the process of installing NodeBB (http://www.nodebb.org) in the OpenShift cloud (https://www.openshift.com/). It will also let you know how to keep NodeBB updated afterwards. 7 | 8 | Before continuing, you should know how to open and use command line on your system. This guide does not describe how to do that. 9 | 10 | 11 | ## Prerequisites 12 | 13 | First of all, you will need an OpenShift account. If you do not have one yet, now is the time to register at https://www.openshift.com/app/account/new. 14 | 15 | Next, install `rhc` application, as described at https://developers.openshift.com/en/managing-client-tools.html. Make sure to follow the steps described in the "Setting up Your Machine" section relevant for your operating system. 16 | 17 | After that, you should have working `rhc` and `git` available on your system. If you had to install `git`, or never used it before, make sure that you configured your identity, as described at: https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#Your-Identity. 18 | 19 | 20 | ## Installation 21 | 22 | To install NodeBB, follow these steps (they were tested using `bash` shell), without omitting any of them (unless stated otherwise), on your local system (NOT on the OpenShift side, through SSH). 23 | 24 | ### 1. Creating a new application 25 | 26 | Make sure that there is no local "nodebb" directory already there. If there is, either move it somewhere else or change its name. You can also use different name than "nodebb" for your application. In such case, be sure to replace the word "nodebb" (but only if it is all in small caps, and not part of another word) in every command mentioned in this guide. 27 | 28 | This will create the application in the OpenShift cloud. 29 | 30 | ```sh 31 | rhc app create --no-scaling nodebb https://raw.githubusercontent.com/icflorescu/openshift-cartridge-nodejs/master/metadata/manifest.yml NODE_VERSION_URL=https://semver.io/node/resolve/0.10 32 | ``` 33 | 34 | It should create your local copy of your OpenShift repository in a directory called "nodebb". If it does not, check if there were some errors in the output and maybe try again before continuing. Without that directory, rest of the steps will not work as they should. 35 | 36 | ### 2. Adding database cartridge 37 | 38 | NodeBB supports both Redis and MongoDB databases. It's up to you to decide which one to use. If you to not know anything about that, just select first one. 39 | 40 | To use MongoDB local to OpenShift server, run: 41 | 42 | ```sh 43 | rhc cartridge add https://raw.githubusercontent.com/icflorescu/openshift-cartridge-mongodb/master/metadata/manifest.yml -a nodebb 44 | ``` 45 | 46 | To use Redis local to OpenShift server, run: 47 | 48 | ```sh 49 | rhc cartridge add http://cartreflect-claytondev.rhcloud.com/github/transformatordesign/openshift-redis-cart -a nodebb 50 | ``` 51 | 52 | To use third party MongoDB Database-as-a-Service from MongoLab, go to https://marketplace.openshift.com/login, add MongoLab subscription and connect it to the nodebb application (read more about that at https://developers.openshift.com/en/marketplace-mongolab.html). 53 | 54 | Only one of them is needed, there is no point in adding more than one database. 55 | 56 | ### 3. Add NodeBB repository 57 | 58 | This will change current working directory to the one used for NodeBB. 59 | 60 | ```sh 61 | cd nodebb 62 | ``` 63 | 64 | This will attach remote NodeBB repository to your local repository. 65 | 66 | ```sh 67 | git remote add upstream -m master https://github.com/NodeBB/NodeBB.git 68 | ``` 69 | 70 | ### 4. Import NodeBB code to application 71 | 72 | This will clean up directory from example stuff that node js cartridge created. 73 | 74 | ```sh 75 | rm -rf `ls` .eslintrc && git commit -a -m 'Cleaned up for NodeBB' 76 | ``` 77 | 78 | This will import source code of NodeBB v0.9.x. To import different version instead, go to https://github.com/NodeBB/NodeBB, see what version branches are available and replace "v0.9.x" with selected version number. 79 | 80 | ```sh 81 | git pull --no-edit -s recursive -X theirs upstream v0.9.x 82 | ``` 83 | 84 | This guide was tested with `v0.6.x`, `v0.7.x`, `v0.8.x`, and `v0.9.x` branches. 85 | 86 | ### 5. Add OpenShift-NodeBB repository 87 | 88 | This will allow to import patches and action_hooks needed to use NodeBB without worrying too much about dynamic IP and/or port number changes or files uploaded by users disappearing. 89 | 90 | ```sh 91 | git remote add openshift -m master https://github.com/ahwayakchih/openshift-nodebb.git 92 | ``` 93 | 94 | ### 6. Import OpenShift-NodeBB 95 | 96 | This will import scripts and patches mentioned in previous step. 97 | 98 | ```sh 99 | git pull --no-edit -s recursive -X theirs openshift master 100 | ``` 101 | 102 | ### 7. Configure administrator e-mail 103 | 104 | This will set NodeBB administrator e-mail address to `youremail@example.com`. Please change it to the one you want to be used by your NodeBB installation. 105 | 106 | ```sh 107 | rhc env set NODEBB_ADMIN_EMAIL=youremail@example.com -a nodebb 108 | ``` 109 | 110 | ### 8. Push everything to application repository 111 | 112 | This will push everything to OpenShift servers, deploy and start NodeBB. 113 | 114 | ```sh 115 | git push origin master 116 | ``` 117 | 118 | ### 9. That's it! 119 | 120 | After a while, you should be able to see something like this near the end of a long text output from previous command: 121 | 122 | ``` 123 | .-============================================-. 124 | . Setup Finished. 125 | . 126 | . New administrator user has been created: 127 | . 128 | . email : youremail@example.com 129 | . login : nodebb 130 | . password: 9D7u-KAtN-76Kz-TCyX 131 | . 132 | . Please wait for NodeBB to start. 133 | . 134 | . WARNING: Be sure to change admin password 135 | . after first log in! 136 | ^-============================================-^ 137 | ``` 138 | 139 | And then: 140 | 141 | ``` 142 | .-============================================-. 143 | . NodeBB is ready. 144 | . 145 | . You can visit it at: 146 | . https://nodebb-youropenshiftusername.rhcloud.com/ 147 | . 148 | . You can log in to it at: 149 | . https://nodebb-youropenshiftusername.rhcloud.com/login 150 | ^-============================================-^ 151 | ``` 152 | 153 | Use that new admin login and password to log in to your new NodeBB installation, and change them to something suitable for you. 154 | 155 | 156 | ## Updates 157 | 158 | From now on, every time you want to update NodeBB, you can simply follow three steps. Follow them on your local system (NOT on the OpenShift side, through SSH). 159 | 160 | ### 1. Pull changes 161 | 162 | This will change current working directory to the one used for NodeBB. 163 | 164 | ```sh 165 | cd nodebb 166 | ``` 167 | 168 | Update NodeBB source code: 169 | 170 | ```sh 171 | git pull --no-edit -s recursive -X theirs upstream v0.9.x 172 | ``` 173 | 174 | You can jump to a new version by replacing "v0.9.x" with another branch name. Before you do that, run full update of your currently installed version, and only after that, repeat update process with new version. 175 | 176 | Keep in mind, however, that switching to a new version will work only for an uprade, e.g., from `v0.8.x` to `v0.9.x`. 177 | 178 | Update OpenShift-NodeBB patches: 179 | 180 | ```sh 181 | git pull --no-edit -s recursive -X theirs openshift master 182 | ``` 183 | 184 | ### 2. Push changes 185 | 186 | ```sh 187 | git push origin master 188 | ``` 189 | 190 | ### 3. That's it! 191 | 192 | After a while (sometimes quite a long while), you should be able to see something like this near the end of a long text output from previous command: 193 | 194 | ``` 195 | .-============================================-. 196 | . Setup Finished. 197 | . 198 | . Please wait for NodeBB to start. 199 | ^-============================================-^ 200 | ``` 201 | 202 | And then: 203 | 204 | ``` 205 | .-============================================-. 206 | . NodeBB is ready. 207 | . 208 | . You can visit it at: 209 | . https://nodebb-youropenshiftusername.rhcloud.com/ 210 | . 211 | . You can log in to it at: 212 | . https://nodebb-youropenshiftusername.rhcloud.com/login 213 | ^-============================================-^ 214 | ``` 215 | 216 | 217 | ## Plugins 218 | 219 | If you just want to test things and look around, you can simply install/enable plugins through administration pages. 220 | 221 | If you want to keep NodeBB running in the OpenShift cloud, you should add plugins through your repository instead. That is because OpenShift may erase all the files on server whenever you push changes to your repository. 222 | NodeBB can install plugins, but it will not add them to the "package.json" file, nor it will commit changes to your repository. 223 | 224 | To keep plugins installed and working between updates, you can install them using `npm`. Follow these steps on your local system (NOT on the OpenShift side, through SSH). 225 | 226 | ### 1. Install plugin locally 227 | 228 | This will change current working directory to the one used for NodeBB. 229 | 230 | ```sh 231 | cd nodebb 232 | ``` 233 | 234 | As an example, this will install "Question and Answer" plugin (https://github.com/psychobunny/nodebb-plugin-question-and-answer). 235 | 236 | ```sh 237 | npm install --production --save nodebb-plugin-question-and-answer 238 | ``` 239 | 240 | Plugin will be installed locally and information about it will be saved to the "package.json" file. 241 | 242 | Change the name of the module (`nodebb-plugin-question-and-answer` in the example above) to install plugin of your choice. Just remember to keep the `npm install --production --save ` part of the command intact. 243 | 244 | ### 2. Commit changes 245 | 246 | This will commit modifications to your local repository. 247 | 248 | ```sh 249 | git commit -a -m 'Added QA plugin' 250 | ``` 251 | 252 | Of course, instead of `Added QA plugin` you can write any other one-liner that explains what was changed. 253 | 254 | ### 3. Push changes 255 | 256 | ``` 257 | git push origin master 258 | ``` 259 | 260 | 261 | ## Custom domain name 262 | 263 | If you want to use your own domain name, instead of subdomain in domain provided by OpenShift, you can add alias to your application. 264 | There is only one ceveat: to use HTTPS with your own domain name, you have to upgrade your OpenShift plan. Otherwise there is no way to set up correct SSL certificate and you will keep bumping into problems. 265 | 266 | So in short, here is when you can use HTTPS: 267 | 268 | - OpenShift domain 269 | - Custom domain only on premium plan 270 | 271 | You can read more about that at https://developers.openshift.com/en/managing-domains-ssl.html 272 | 273 | There's no known way for NodeBB to work 100% correctly with both HTTPS and custom domain name on a free plan. CloudFlare does not seem to provide support for SSL websockets for anything below Enterprise plan. 274 | 275 | As usual, follow these steps on your local system (NOT on the OpenShift side, through SSH). 276 | 277 | ### 1. Add domain name to application 278 | 279 | ```sh 280 | rhc alias add nodebb example.com 281 | ``` 282 | 283 | Of course, instead of `example.com` enter your own domain name. 284 | 285 | ### 2. Add domain name to NodeBB 286 | 287 | This will make NodeBB installation work correctly with your custom domain name. 288 | 289 | ```sh 290 | rhc env set OPENSHIFT_APP_DNS_ALIAS=example.com -a nodebb 291 | ``` 292 | 293 | Again, use your own domain name in place of `example.com`. 294 | 295 | ### 3. Optional SSL 296 | 297 | If your account is on one of paid "premium" plans, you can add SSL certificate to enable valid usage of HTTPS with your custom domain name. 298 | You can get free, widely accepted certificates from https://letsencrypt.org/. 299 | 300 | Once you have a key and a certificate, this will add them to application: 301 | 302 | ```sh 303 | rhc alias update-cert nodebb example.com --certificate cert_file --private_key key_file 304 | ``` 305 | 306 | Use your own domain name in place of `example.com`, and correct files in place of `cert_file` and `key_file`. 307 | Read more about setting up SSL at https://developers.openshift.com/en/managing-domains-ssl.html#_command_line_rhc_3 308 | 309 | You can add certificates at some point in future. Just remember to restart application after that. 310 | 311 | ### 4. Restart NodeBB 312 | 313 | This will restart your NodeBB installation, so it can use updated configuration variables. 314 | 315 | ```sh 316 | rhc app restart nodebb 317 | ``` 318 | 319 | ### 5. Configure DNS 320 | 321 | Last thing to do is to configure DNS for your domain name to point to your OpenShift domain name. You can read more about that at https://developers.openshift.com/en/managing-domains-ssl.html#_step_2_configure_your_dns_host_records. 322 | 323 | Please note that some DNS changes may take up to 24 hours before propagating, so if your NodeBB site is not accessible through custom domain name, it may just be that you have to wait a bit before it starts working. 324 | 325 | If later you decide to change the domain name, simply repeat steps 1 to 5. 326 | 327 | 328 | ## Troubleshooting 329 | 330 | ### 1. Installation/Update error 331 | 332 | When something goes wrong with installation or update, you should see something like this near the end of a long text output: 333 | 334 | ``` 335 | .-============================================-. 336 | . Setup failed. 337 | . 338 | . There was a problem completing NodeBB setup. 339 | . 340 | . Check logfile for more information: 341 | . logs/openshift-nodebb-setup.log 342 | ^-============================================-^ 343 | ``` 344 | 345 | It may be either "Setup failed" or "NodeBB failed to start". 346 | 347 | Path to logfile is local to OpenShift server, so to check that file you can either log in to server through SSH or copy file to your local directory. 348 | 349 | This will copy log file from OpenShift server to your local directory. 350 | 351 | ```sh 352 | rhc scp nodebb download ./ app-root/repo/logs/openshift-nodebb-setup.log 353 | ``` 354 | 355 | Use whatever path was mentioned in error message in place of "logs/logs/openshift-nodebb-setup.log". 356 | 357 | Once you have the log file, you can either check it yourself or post an issue at https://github.com/ahwayakchih/openshift-nodebb/issues (describing the steps you made and copying and pasting content of the logfile). 358 | 359 | ### 2. Restart application 360 | 361 | From time to time something may go wrong while OpenShift tries to restart application, e.g., after its repository is updated. In such case, your NodeBB site may not work as it should. Sometimes that can be fixed with a simple command: 362 | 363 | ```sh 364 | rhc app restart 365 | ``` 366 | 367 | ### 3. Add missing "origin" remote 368 | 369 | It looks like sometimes, for reasons unknown at the moment of writing this text, remote "origin" is missing. In such case you can run: 370 | 371 | ```sh 372 | cd nodebb 373 | ``` 374 | 375 | and then: 376 | 377 | ```sh 378 | git remote add origin `rhc app show nodebb | grep -oh "ssh://\S\{1,\}\.rhcloud.com/~/git/\S*"` 379 | ``` 380 | 381 | This should configure remote "origin" in your local git repository to point to your git repository located on the OpenShift servers. 382 | 383 | ### 4. Remove custom domain name 384 | 385 | If you want to remove custom domain name, this will stop NodeBB from using it: 386 | 387 | ```sh 388 | rhc env unset OPENSHIFT_APP_DNS_ALIAS 389 | ``` 390 | 391 | If you did add certificate, this will remove it: 392 | 393 | ```sh 394 | rhc alias delete-cert nodebb example.com 395 | ``` 396 | 397 | Finally, this will stop OpenShift from using your domain name: 398 | 399 | ```sh 400 | rhc alias remove nodebb example.com 401 | ``` 402 | 403 | 404 | ## Acknowledgments 405 | 406 | This guide wouldn't be possible without instructions from 407 | https://github.com/NodeBB/nodebb-english/blob/master/installing/cloud/openshift.rst 408 | and OpenShift documentation and examples from 409 | https://developers.openshift.com/en/managing-action-hooks.html 410 | 411 | It also wouldn't be created if not for numerous questions and conversations with Sylwester Cyba from http://nhl.pl/. 412 | 413 | Part describing custom domain setup was created thanks to Benderwan (https://github.com/Benderwan) reporting problem and testing solutions (https://github.com/ahwayakchih/openshift-nodebb/issues/7). 414 | -------------------------------------------------------------------------------- /openshift-app.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is a wrapper around original app.js from NodeBB. 3 | * It sets up config overrides using values from OpenShift environment, 4 | * and then requires original app.js (now renamed to _app.js) to let 5 | * NodeBB continue it's magic. 6 | */ 7 | var nconf = require('nconf'); 8 | var url = require('url'); 9 | 10 | var testSSL = require('./.openshift/tools/test-ssl.js'); 11 | 12 | var IP = process.env.OPENSHIFT_NODEJS_IP || null; 13 | var PORT = process.env.OPENSHIFT_NODEJS_PORT || 8080; 14 | 15 | // Fully Qualified Domain Name 16 | var FQDN = process.env.OPENSHIFT_APP_DNS_ALIAS || process.env.OPENSHIFT_APP_DNS || false; 17 | 18 | // Check is SSL is working on selected domain name 19 | testSSL(IP, PORT, FQDN, function onTestSSLResult (err) { 20 | 'use strict'; 21 | 22 | // HTTPS or HTTP and WSS or WS 23 | var USE_SSL = err ? false : true; 24 | 25 | // Prepare config overrides 26 | var config = {}; 27 | 28 | // Port number 29 | if (PORT) { 30 | config.port = PORT; 31 | } 32 | 33 | // Bind to IP address 34 | if (IP) { 35 | config.bind_address = IP; 36 | } 37 | 38 | // Default domain name 39 | if (FQDN) { 40 | config.url = (USE_SSL ? 'https' : 'http') + '://' + FQDN; 41 | 42 | // OpenShift supports websockets but only on ports 8000 and 8443 43 | config['socket.io'] = config['socket.io'] || {}; 44 | 45 | if (USE_SSL) { 46 | config['socket.io'].address = 'wss://' + FQDN + ':8443'; 47 | } 48 | else { 49 | config['socket.io'].address = 'ws://' + FQDN + ':8000'; 50 | } 51 | } 52 | 53 | // MongoDB is preferred by default 54 | if (process.env.OPENSHIFT_MONGODB_DB_HOST || process.env.OPENSHIFT_MONGODB_IP || process.env.OPENSHIFT_MONGODB_DB_PASSWORD) { 55 | config.database = config.database || 'mongo'; 56 | config.mongo = config.mongo || {}; 57 | 58 | // OpenShift seems to create MongoDB datbase with the same name as the application name. 59 | config.mongo.database = process.env.OPENSHIFT_APP_NAME || 'nodebb'; 60 | 61 | if (process.env.OPENSHIFT_MONGODB_DB_HOST || process.env.OPENSHIFT_MONGODB_IP) { 62 | config.mongo.host = process.env.OPENSHIFT_MONGODB_DB_HOST || process.env.OPENSHIFT_MONGODB_IP; 63 | } 64 | if (process.env.OPENSHIFT_MONGODB_DB_PORT) { 65 | config.mongo.port = process.env.OPENSHIFT_MONGODB_DB_PORT; 66 | } 67 | if (process.env.OPENSHIFT_MONGODB_DB_USERNAME) { 68 | config.mongo.username = process.env.OPENSHIFT_MONGODB_DB_USERNAME; 69 | } 70 | if (process.env.OPENSHIFT_MONGODB_DB_PASSWORD) { 71 | config.mongo.password = process.env.OPENSHIFT_MONGODB_DB_PASSWORD; 72 | } 73 | } 74 | 75 | // MongoLab is preferred by default 76 | if (process.env.MONGOLAB_URI) { 77 | config.database = config.database || 'mongo'; 78 | config.mongo = config.mongo || {}; 79 | 80 | var mongolabURL = url.parse(process.env.MONGOLAB_URI); 81 | mongolabURL.auth = mongolabURL.auth.split(':'); 82 | 83 | config.mongo.host = mongolabURL.hostname; 84 | config.mongo.port = mongolabURL.port; 85 | config.mongo.username = mongolabURL.auth[0]; 86 | config.mongo.password = mongolabURL.auth[1]; 87 | config.mongo.database = mongolabURL.pathname.substring(1); 88 | } 89 | 90 | // Redis - by setting it up last, we make sure it will not override MongoDB as default database. 91 | // That allows us to have both databases, and will make NodeBB use redis for socket.io-session store. 92 | if (process.env.OPENSHIFT_REDIS_HOST || process.env.REDIS_PASSWORD) { 93 | config.database = config.database || 'redis'; 94 | config.redis = config.redis || {}; 95 | 96 | if (process.env.OPENSHIFT_REDIS_HOST) { 97 | config.redis.host = process.env.OPENSHIFT_REDIS_HOST; 98 | } 99 | if (process.env.OPENSHIFT_REDIS_PORT) { 100 | config.redis.port = process.env.OPENSHIFT_REDIS_PORT; 101 | } 102 | if (process.env.REDIS_PASSWORD) { 103 | config.redis.password = process.env.REDIS_PASSWORD; 104 | } 105 | } 106 | 107 | // Set overrides from OpenShift environment 108 | nconf.overrides(config); 109 | 110 | // Cleanup 111 | config = null; 112 | testSSL = null; 113 | IP = PORT = FQDN = null; 114 | 115 | // Continue booting NodeBB 116 | setImmediate(require.bind(null, './_app.js')); 117 | }); 118 | -------------------------------------------------------------------------------- /patches/openshift-0.6.1.diff: -------------------------------------------------------------------------------- 1 | diff --git a/app.js b/app.js 2 | index acb1a3b..d24175e 100644 3 | --- a/app.js 4 | +++ b/app.js 5 | @@ -21,7 +21,7 @@ 6 | /*global require, global, process*/ 7 | 8 | var nconf = require('nconf'); 9 | -nconf.argv().env(); 10 | +nconf.argv().env('__'); 11 | 12 | var fs = require('fs'), 13 | os = require('os'), 14 | diff --git a/src/database/mongo.js b/src/database/mongo.js 15 | index 0e69c12..a13cb5d 100644 16 | --- a/src/database/mongo.js 17 | +++ b/src/database/mongo.js 18 | @@ -22,12 +22,14 @@ 19 | }, 20 | { 21 | name: 'mongo:username', 22 | - description: 'MongoDB username' 23 | + description: 'MongoDB username', 24 | + 'default': nconf.get('mongo:username') || '' 25 | }, 26 | { 27 | name: 'mongo:password', 28 | description: 'Password of your MongoDB database', 29 | - hidden: true 30 | + hidden: true, 31 | + before: function(value) { value = value || nconf.get('mongo:password') || ''; return value; } 32 | }, 33 | { 34 | name: "mongo:database", 35 | diff --git a/src/database/redis.js b/src/database/redis.js 36 | index 727705c..156131a 100644 37 | --- a/src/database/redis.js 38 | +++ b/src/database/redis.js 39 | @@ -28,7 +28,8 @@ 40 | { 41 | name: 'redis:password', 42 | description: 'Password of your Redis database', 43 | - hidden: true 44 | + hidden: true, 45 | + before: function(value) { value = value || nconf.get('redis:password') || ''; return value; } 46 | }, 47 | { 48 | name: "redis:database", 49 | diff --git a/src/install.js b/src/install.js 50 | index 54fb075..a867252 100644 51 | --- a/src/install.js 52 | +++ b/src/install.js 53 | @@ -47,7 +47,7 @@ questions.main = [ 54 | questions.optional = [ 55 | { 56 | name: 'port', 57 | - default: 4567 58 | + default: nconf.get('port') || 4567 59 | } 60 | ]; 61 | 62 | --------------------------------------------------------------------------------