Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active November 6, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jmervine/5407622 to your computer and use it in GitHub Desktop.
Save jmervine/5407622 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# ensure default configuration location
test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx
# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
. /etc/default/nginx
fi
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
test_nginx_config() {
if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
return 0
else
$DAEMON -t $DAEMON_OPTS
return $?
fi
}
case "$1" in
start)
echo -n "Starting $DESC: "
test_nginx_config
# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
# Set the ulimits
ulimit $ULIMIT
fi
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
test_nginx_config
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
test_nginx_config
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
configtest|testconfig)
echo -n "Testing $DESC configuration: "
if test_nginx_config; then
echo "$NAME."
else
exit $?
fi
;;
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
exit 1
;;
esac
exit 0
#!/usr/bin/bash
#
# bash < <(curl -s https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)
set -x
cd /tmp
if ! test -d /usr/local/include/luajit-2.0; then
echo "Installing LuaJIT-2.0.1."
wget "http://luajit.org/download/LuaJIT-2.0.1.tar.gz"
tar -xzvf LuaJIT-2.0.1.tar.gz
cd LuaJIT-2.0.1
make
sudo make install
else
echo "Skipping LuaJIT-2.0.1, as it's already installed."
fi
mkdir ngx_devel_kit
cd ngx_devel_kit
wget "https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz"
tar -xzvf v0.2.18.tar.gz
NGX_DEV="/tmp/ngx_devel_kit/ngx_devel_kit-0.2.18"
cd /tmp
mkdir lua-nginx-module
cd lua-nginx-module
wget "https://github.com/chaoslawful/lua-nginx-module/archive/v0.7.21.tar.gz"
tar -xzvf v0.7.21.tar.gz
LUA_MOD="/tmp/lua-nginx-module/lua-nginx-module-0.7.21"
cd /tmp
wget 'http://nginx.org/download/nginx-1.2.8.tar.gz'
tar -xzvf nginx-1.2.8.tar.gz
cd ./nginx-1.2.8
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./configure --prefix=/opt/nginx \
--add-module=$NGX_DEV \
--add-module=$LUA_MOD
make -j2
sudo make install
unset LUAJIT_LIB
unset LUAJIT_INC
@cheneydeng
Copy link

hi, NO. 18 line of nginx_w_lua.bash should add "cd /tmp".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment