403Webshell
Server IP : 193.86.120.172  /  Your IP : 216.73.216.67
Web Server : Apache/2.4.63 (Unix)
System : Linux JServices 3.10.108 #86003 SMP Wed Oct 22 13:20:46 CST 2025 x86_64
User : kubec ( 1026)
PHP Version : 8.2.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/packages/SynologyApplicationService/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/packages/SynologyApplicationService/scripts/start-stop-status
#!/bin/sh

. /var/packages/SynologyApplicationService/scripts/utils
. /var/packages/SynologyApplicationService/scripts/db_functions

killDaemons()
{
	killall notification_send
	rm -f  /var/run/notification_send*
}

recreateDir()
{
	local dir=$1
	rm -rf "${dir}"
	prepareDir "${dir}"
}

prepareDir()
{
	local dir=$1
	mkdir -p "${dir}"
	chown SynologyApplicationService:SynologyApplicationService "${dir}"
	chmod 755 "${dir}"
}

checkAndRegenVapidSendKey()
{
	[ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ] && NODE_PACKAGE=Node.js_v12 || NODE_PACKAGE=Node.js_v20
	NODE_BIN="/var/packages/$NODE_PACKAGE/target/usr/local/bin/node"
	PUBLIC_KEY="/usr/syno/etc/packages/SynologyApplicationService/vapid/public.key"
	PRIVATE_KEY="/usr/syno/etc/packages/SynologyApplicationService/vapid/private.key"

	# if public key or private key not exists, re-gen keys & delete existing browser push pairs
	if [ ! -s $PUBLIC_KEY ] || [ ! -s $PRIVATE_KEY ]; then
		$NODE_BIN /var/packages/SynologyApplicationService/target/node_libs/GenVAPIDKey.js
		/bin/sqlite3 /usr/syno/etc/notification/notification_db_daemon.sqlite "DELETE FROM devices WHERE type = 'browser_webpush';"
	fi
}

chownPgbouncerSocketFile()
{
	SOCKET_FILE="/run/SynologyApplicationService/.s.PGSQL.6432"

	if [ -S $SOCKET_FILE ]; then
		chown SynologyApplicationService:root $SOCKET_FILE
	else
		return 1
	fi
}

startFn()
{
	SynoSetVolume
	# Check DB
	if IsSASServiceRunningNode; then
		if ! CreateSchema || ! UpdateSchema; then
			return 1
		fi
	fi

	if [ ! -d "/var/run/SynologyApplicationService" ]; then
		/bin/mkdir -p "/var/run/SynologyApplicationService"
	fi
	killDaemons
	if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
		if [ ! -d "/usr/local/etc/nginx/conf.d" ]; then
			/bin/mkdir -p "/usr/local/etc/nginx/conf.d"
		fi
		if [ -L "/usr/local/etc/nginx/conf.d/dsm.SynologyApplicationService.conf" ]; then
			rm /usr/local/etc/nginx/conf.d/dsm.SynologyApplicationService.conf
		fi
		ln -sf /var/packages/SynologyApplicationService/target/etc/www/dsm.SynologyApplicationService.conf /usr/local/etc/nginx/conf.d/dsm.SynologyApplicationService.conf
		/bin/nginx -s reload
	fi

	prepareDir "/run/SynologyApplicationService/tmp_download/"
	recreateDir "/var/packages/SynologyApplicationService/target/hook/"
	recreateDir "/var/packages/SynologyApplicationService/target/hook/profile_change/"

	SynoService status pgsql-adapter
	if (( $? != 0 )); then
		echo "PostgresSQL is not running" > "$SYNOPKG_TEMP_LOGFILE"
		return 1
	fi

	SynoService start pkg-SynologyApplicationService-pgbouncer "test -S /run/SynologyApplicationService/.s.PGSQL.6432"
	if (( $? != 0 )); then
		echo "Failed to start service [pgbouncer]" > "$SYNOPKG_TEMP_LOGFILE"
		return 1
	fi

	if FSDNIsSupported; then
		SynoService start pkg-SynologyApplicationService-haproxy
		if (( $? != 0 )); then
			echo "Failed to start service [haproxy]" > "$SYNOPKG_TEMP_LOGFILE"
			return 1
		fi

		SynoService start pkg-SynologyApplicationService-valkey_server
		if (( $? != 0 )); then
			echo "Failed to start service [valkey server]" > "$SYNOPKG_TEMP_LOGFILE"
			return 1
		fi
	fi

	# bug923: chown in ExecStartPost in systemd will probabilistically fail, run chown here for workaround
	chownPgbouncerSocketFile
	if (( $? != 0 )); then
		echo "Failed to chown pgbouncer socket file" > "$SYNOPKG_TEMP_LOGFILE"
		return 1
	fi

	if ! FSDNIsSupported || FSDNIsAdminNode; then
		SynoService start pkg-SynologyApplicationService-notification_send "test -S /var/run/notification_send.sock"
		if (( $? != 0 )); then
			echo "Failed to start service [notification send]" > "$SYNOPKG_TEMP_LOGFILE"
			return 1
		fi

		checkAndRegenVapidSendKey
		SynoService start pkg-SynologyApplicationService-VapidSendServer "test -S /var/run/vapid_send_server.sock"
		if (( $? != 0 )); then
			echo "Failed to start service [Vapid Send Server]" > "$SYNOPKG_TEMP_LOGFILE"
			return 1
		fi

		/usr/local/bin/synoscimprofile --migrate
		if [ -f /usr/syno/etc/packages/SynologyApplicationService/need_scim_generator_thumb ]; then
			/usr/local/bin/synoscimprofile --genthumb
			rm -f /usr/syno/etc/packages/SynologyApplicationService/need_scim_generator_thumb
		fi
	fi

	return 0
}

stopFn()
{
	if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
		if [ -f "/usr/local/etc/nginx/conf.d/dsm.SynologyApplicationService.conf" ]; then
			rm /usr/local/etc/nginx/conf.d/dsm.SynologyApplicationService.conf
		fi
		/bin/nginx -s reload
	fi

	SynoService stop pkg-SynologyApplicationService-notification_send
	SynoService stop pkg-SynologyApplicationService-pgbouncer
	SynoService stop pkg-SynologyApplicationService-VapidSendServer
	if FSDNIsSupported; then
		SynoService stop pkg-SynologyApplicationService-haproxy
		SynoService stop pkg-SynologyApplicationService-valkey_server
	fi

	killDaemons
	return 0
}

statusFn()
{
	SynoService status pkg-SynologyApplicationService-notification_send
	local notification_send_status=$?
	SynoService status pkg-SynologyApplicationService-pgbouncer
	local pgbouncer_status=$?

	if [ -f $PACKAGE_ENABLED ]; then
		if ! IsSASServiceRunningNode; then
			notification_send_status=0
		fi

		if [ ${notification_send_status} != 0 ] || [ ${pgbouncer_status} != 0 ]; then
			exit 1
		fi
		exit 0
	else
		if [ ${notification_send_status} == 0 ] || [ ${pgbouncer_status} == 0 ]; then
			exit 0
		fi
		exit 1
	fi
}

case $1 in
	start)
		if [ ! -f $PACKAGE_ENABLED ]; then
			exit 0;
		fi
		startFn
		exit $?
	;;
	stop)
		stopFn
		if (( $? != 0 )); then
			exit 1
		fi
		exit $?
	;;
	status)
		statusFn
		exit $?
	;;
	*)
		exit 0
	;;
esac

Youez - 2016 - github.com/yon3zu
LinuXploit