Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
pm2 / usr / local / bin / pm2
Size: Mime:
#!/usr/bin/env bash

declare -r pm2_pid=~/.pm2/pm2.pid

if [ ! -f "${pm2_pid}" ]; then
	echo "pm2.service is not running, start pm2 by 'systemctl --user start pm2'"
	exit 2
fi

declare -r pid=$(head -c 10 "${pm2_pid}")
if [ ! -z "$pid" ] && ! ps -p "$pid" >/dev/null 2>&1; then
	echo "pm2.service PID file found but is not running, start pm2 by 'systemctl --user start pm2'"
	exit 3
fi

if [ "$1" == "kill" ]; then
	echo "pm2 is managed by systemd, stop pm2 by 'systemctl --user stop pm2'"
	exit 4
fi

if [ "$1" == "deepUpdate" ]; then
	echo "pm2 is installed by apt, use 'apt update', 'apt install pm2', 'pm2 update' to update pm2"
	exit 5
fi

if [ "$1" == "startup" ] || [ "$1" == "unstartup" ]; then
	echo -e "\033[0;33m*** pm2 is managed by systemd, use 'pm2 ${1}' with caution ***\033[0m"
fi

if [ "$1" == "updatePM2" ] || [ "$1" == "update" ]; then
	# [Tony 2020-11-18] Running 'pm2 update' alone when the process was started by systemd
	# may stuck after output '>>>>>>>>>> PM2 updated' using pm2 v4.5.0, therefore we need to stop
	# the systemd-started pm2 before performing update
	systemctl --user stop pm2
fi

umask 0022
PATH=/usr/local/lib/nodejs14/bin:/usr/local/lib/nodejs12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
	PM2_HOME=~/.pm2 \
	/usr/local/lib/pm2/node_modules/pm2/bin/pm2 "$@"
declare -ir return_code=$?

if [ "$1" == "updatePM2" ] || [ "$1" == "update" ]; then
	# [Tony 2021-09-08] After 'pm2 update', the daemon continues to run, therefore we
	# need to kill it before passing the process management to systemctl
	PATH=/usr/local/lib/nodejs14/bin:/usr/local/lib/nodejs12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
		PM2_HOME=~/.pm2 \
		/usr/local/lib/pm2/node_modules/pm2/bin/pm2 kill
	systemctl --user restart pm2
fi

exit $return_code