HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: //etc/init/nginx.conf
description "Nginx"
author "Development Infrastructure Team"
console log
reload signal SIGHUP

start on runlevel 1 and syno.share.ready and syno.network.ready and (started apparmor or stopped apparmor)
stop on runlevel [06]

nice -10
oom score -999

expect fork

respawn
respawn limit 5 10

pre-start script
	SZD_LOCAL_NGINX="/usr/local/etc/nginx"
	SZD_LOCAL_CONF_D="$SZD_LOCAL_NGINX/conf.d"
	SZD_LOCAL_SITES_ENABLED="$SZD_LOCAL_NGINX/sites-enabled"
	SZD_NGINX_TMP="/var/tmp/nginx"
	SZF_NGINX_UPSTART_ARG="/var/tmp/nginx/nginx-upstart-argument"

	MakeDirectory()
	{
		local path="$1"
		local mode="$2"
		local owner="$3"

		[ ! -d "$path" ] && /bin/mkdir -p "$path" || true
		/usr/bin/chmod "$mode"	"$path" || true
		/usr/bin/chown "$owner" "$path" || true
	}

	/usr/bin/rm -rf /var/services/tmp/nginx || true
	MakeDirectory /var/services/tmp/nginx 700 http:root

	/usr/bin/rm -rf /var/lib/nginx || true
	/bin/ln -s /var/services/tmp/nginx /var/lib/nginx || true

	MakeDirectory /var/log/nginx 750 http:root
	MakeDirectory $SZD_LOCAL_CONF_D 755 root:root
	MakeDirectory $SZD_LOCAL_SITES_ENABLED 755 root:root
	MakeDirectory $SZD_NGINX_TMP 755 root:root

	/usr/syno/bin/mkcert > /dev/null 2>&1
	/usr/syno/bin/cgi-keygen > /dev/null 2>&1 &

	for numbits in 2048 1024; do
		pem="/usr/syno/etc/ssl/dh${numbits}.pem"
		pem_default="/usr/syno/etc.defaults/ssl/dh${numbits}.pem"

		[ ! -e $pem ] && /usr/bin/cp -fp $pem_default $pem
	done

	/usr/bin/rm -f "$SZF_NGINX_UPSTART_ARG"
	/usr/bin/touch "$SZF_NGINX_UPSTART_ARG"
	/usr/bin/chmod 600 "$SZF_NGINX_UPSTART_ARG"

	/usr/bin/touch $SZD_LOCAL_CONF_D/{main,events}.conf || true

	if ! /usr/syno/bin/synow3tool --deploy-init; then
		/usr/bin/echo "startArg=\"-c /etc.defaults/nginx/nginx.conf.default\"" > "$SZF_NGINX_UPSTART_ARG"
	fi
end script

script
	. /var/tmp/nginx/nginx-upstart-argument
	exec /usr/bin/nginx $startArg -g 'pid /run/nginx.pid; daemon on; master_process on;'
end script

post-start script
	/usr/bin/rm -f /var/tmp/nginx/nginx-upstart-argument
end script

post-stop script
	/usr/bin/echo "Stop Nginx Server ......"
	[ -f /run/nginx.pid ] && /usr/bin/nginx -g 'pid /run/nginx.pid;' -s quit || true
	/bin/rm -f /etc/avahi/services/dsminfo.service
	/bin/rm -f /run/webstation_default.sock
end script