mirror of
https://github.com/cytopia/devilbox.git
synced 2024-12-18 20:37:55 +00:00
Add global autostart example
This commit is contained in:
parent
1dfa98446b
commit
4c45a7e33d
46
autostart/run-node-js-projects.sh-example
Executable file
46
autostart/run-node-js-projects.sh-example
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This is a generic example to startup your NodeJS projects with
|
||||
# pm2 (https://github.com/Unitech/pm2)
|
||||
#
|
||||
# Important: As everything is run by the root user, you must explicitly direct the
|
||||
# commands to the devilbox user.
|
||||
#
|
||||
|
||||
|
||||
|
||||
# Add the full paths of your Nodejs projects startup files into this array
|
||||
# Each project separated by a newline and enclosed in double quotes. (No commas!)
|
||||
# Paths are internal paths inside the PHP container.
|
||||
NODE_PROJECTS=(
|
||||
#"/shared/httpd/my-rhost/js/index.js"
|
||||
#"/shared/httpd/my-node-hello-world/name/run.js"
|
||||
#"/shared/httpd/another-node-project/javascript/run.js"
|
||||
)
|
||||
|
||||
|
||||
# Check if any projects have been defined
|
||||
if [ ${#NODE_PROJECTS[@]} -eq 0 ]; then
|
||||
echo "No projects defined. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# This loops over the paths, separates base directory and filename and will run it in the background
|
||||
# as the user devilbox. There shouldn't be any need to change anything here.
|
||||
for item in ${NODE_PROJECTS[*]}; do
|
||||
NODE_PATH="$( dirname "${item}" )"
|
||||
NODE_FILE="$( basename "${item}" )"
|
||||
|
||||
if [ ! -d "${NODE_PATH}" ]; then
|
||||
>&2 echo "[Warning], skipping startup, directory does not exist: ${NODE_PATH}"
|
||||
continue;
|
||||
fi
|
||||
if [ ! -f "${NODE_PATH}/${NODE_FILE}" ]; then
|
||||
>&2 echo "[Warning], skipping startup, file does not exist: ${NODE_PATH}/${NODE_FILE}"
|
||||
continue;
|
||||
fi
|
||||
|
||||
echo "su -c \"cd ${NODE_PATH}; pm2 start ${NODE_FILE}\" -l devilbox"
|
||||
su -c "cd ${NODE_PATH}; pm2 start ${NODE_FILE}" -l devilbox
|
||||
done
|
Loading…
Reference in New Issue
Block a user