HEX
Server: Apache/2.4.63 (Unix)
System: Linux Synopilou92 4.4.302+ #72806 SMP Mon Jul 21 23:16:00 CST 2025 x86_64
User: pilou92 (1026)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: //var/packages/Spreadsheet/scripts/start-stop-status
#!/bin/bash

. /var/packages/Spreadsheet/scripts/pkg_utils

StartNodejsServer()
{
	/var/packages/Spreadsheet/scripts/set-nodejs-env
	Control start pkg-synoffice-taskd
	Control start pkg-synoffice-spreadsheet-node &
	Control start pkg-synoffice-document-node &
	Control start pkg-synoffice-presentation-node &
	wait
}

StartAPIDeamon()
{
	Control start pkg-synoffice-apid
}

StopAPIDaemon()
{
	Control stop pkg-synoffice-apid
}

StartCleanerDaemon()
{
	if ! IsController ;then
		return
	fi
	Control start pkg-synoffice-cleanerd
}

StopCleanerDaemon()
{
	Control stop pkg-synoffice-cleanerd
}

StopNodejsServer()
{
	Control stop pkg-synoffice-spreadsheet-node &
	Control stop pkg-synoffice-document-node &
	Control stop pkg-synoffice-presentation-node &
	wait
	Control stop pkg-synoffice-taskd
}

GetPGBouncerPath()
{
	if SOFSIsSupport ;then
		echo "/run/synoffice/.s.PGSQL.6432"
	else
		echo "/run/synoffice/.s.PGSQL.5432"
	fi
}

StartPGBouncer()
{
	if IsController ;then
		$PSQL -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE \"synodrive\" to office"
		$PSQL -U postgres -d synodrive -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to office"
	fi
	UpdatePGBouncerConf
	ControlWait start pkg-synoffice-pgbouncer "test -S $(GetPGBouncerPath)"
}

StopPGBouncer()
{
	ControlWait stop pkg-synoffice-pgbouncer "test ! -S $(GetPGBouncerPath)"
}

UpdateOfficeSetting()
{
	if ! IsController ;then
		return
	fi
	$SETTING_BIN --set_default_conf memory="$(GetMemorySize)"
}

start()
{
	DriveStatus
	local ret=$?
	if [ $ret -eq 0 ]; then
		if IsController ;then
			# Migration Spreadsheet if drive isn't running in the install stage
			/var/packages/Spreadsheet/target/tools/migration_tool -o -l /var/packages/Spreadsheet/target/migration.log
		fi
	else
		echo ", SynologyDrive isn't started"
		GetString error start_drive > "$SYNOPKG_TEMP_LOGFILE"
		exit 1
	fi
	stop
	CreateAppDir
	CreateSQLiteTmpDir
	CreateWeb
	StartPGBouncer
	EnableSynoDrive
	CreateTables false
	StartAPIDeamon
	CreateSynologyDriveHookLink
	RegisterVolume
	StartNodejsServer
	StartClusterDaemon
	InstallNginxModule
	CreateNginxConf
	StartCleanerDaemon
	UpdateOfficeSetting
}

stop()
{
	if [ "$SYNOPKG_PKG_STATUS" = "UNINSTALL" ];then
		FlushFull
	fi
	StopCleanerDaemon
	StopNodejsServer
	RemoveNginxConf
	StopClusterDaemon
	StopAPIDaemon
	StopPGBouncer
	if [ "UPGRADE" != "$SYNOPKG_PKG_STATUS" ]; then
		RemoveSynologyDriveHookLink
	fi
	${COMMON_BIN} --clean
	CleanLockDir
	if [ "$SYNOPKG_PKG_STATUS" = "UNINSTALL" ];then
		RemoveSQLiteTmpDir
		rm -rf /run/synoffice/
	fi
}

case $1 in
	start)
		start
		exit 0
	;;
	stop)
		stop
		exit 0
	;;
	status)
		Status pkg-synoffice-pgbouncer
		pgbouncer_status=$?
		${SYNODRIVE_SETTING_BIN} --status ns=office
		synodrive_status=$?

		if [ -e "${PKG_APP_PATH}" ] && [ "${synodrive_status}" == 0 ] && [ "${pgbouncer_status}" == 0 ];then
			exit 0
		else
			exit 1
		fi
	;;
	log)
		exit 0
	;;
esac

exit 0