Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4133 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted
I've heard Wim Decorte and Steven Blackwell say to not enable the "Automatically start Database Server" option in the Admin Console, and to use an OS-level script that runs when the server starts instead. What I'm looking for is an example of that script, which could possibly start the database server if the computer did not crash, or restore from latest backup if it did crash, etc. Currently I do not have a script to do this, so I have to manually start the database server after every server restart. Before I start from scratch writing my own OS-level script, I was hoping someone is willing to share theirs, or at least ideas of how to write it.
 
I manage both Windows and Mac servers so scripts for either platform and any scripting language will be helpful.
Posted

The trick is to use the fmsadmin command line and that syntax is the same on Windows and Mac.  So the only challenge is in calling that fmsadmin command line from your favourite OS scripting language: shell script / AppleScript on OSX and batch file / VBscript / PowerShell on Windows.

 

Below is a sample VBscript that automates shutting down FMS in a safe way.  It should contain enough pointers to do the reverse.

' Author: Wim Decorte
' Version: 2.0
' Description: Uses the FileMaker Server command line to disconnect
'               all users And close all hosted files
' 
' This is a basic example.  This script is not meant as a finished product,
' its only purpose is as a learning & demo tool.
'
' This script does not have full Error handling.
' For instance, it will break if there are spaces in the FM file names.
' The script also does not handle infinite loops in disconnecting clients
' or closing files.
'
' This script is provided as is, without any implied warranty or support.

Const WshFinished = 1
q = Chr(34)  ' the " character, needed to wrap around paths with spaces


'--------------------------------------------------------------------------------------------
' Change these variables to match your setup

theAdminUser = ""
theAdminPW = ""
pathToSAtool = "C:Program FilesFileMakerFileMaker ServerDatabase Serverfmsadmin.exe"

'--------------------------------------------------------------------------------------------


SAT = "cmd /c " & q & pathToSAtool & q & " " ' watch the trailing space

callFMS = SAT
If Len(theAdminUser) > 0 Then
	callFMS = callFMS & " -u " & theAdminUser
End If
If Len(theAdminPW) > 0 Then
	callFMS = callFMS & " -p " & theAdminPW
End If

listClients = callFMS & " list clients"
disconnectClients = callFMS & " disconnect client -y"
listfiles = callFMS & " list files -s"
closeFiles = callFMS & " close file "
stopServer = callFMS & " stop server -y -t 15"

' hook into the Windows shell
Set sh = WScript.CreateObject("wscript.shell")

' get a list of all clients and force kick them off
clientIDs = getCurrentClients()
clientCount = UBound(clientIDs)

' loop through the clients and kick them off
If clientCount > 0 Then
		fullCommand = disconnectClients
		Set oExec = sh.Exec(fullCommand)
		' give FMS some time and then requery the list of clients
		Do Until oExec.Status = WshFinished
			WScript.Sleep 50
		Loop
		Do Until clientCount = 0
			WScript.Sleep 1000
			Debug.WriteLine "Waiting for clients to disconnect..."
			clientIDs = getCurrentClients()
			clientCount = UBound(clientIDs)
		Loop
End If

' get list of files and close them
fileIDs = getCurrentFiles()
fileCount = UBound(fileIDs)

' loop through the files and close them
If fileCount > 0 Then
	Do Until fileCount = 0
		fullCommand = closeFiles & fileIDs(0) & " -y"
		Set oExec = sh.Exec(fullCommand)
		' give FMS some time and then requery the list of files
		Do Until oExec.Status = WshFinished
			WScript.Sleep 50
		Loop
		fileIDs = getCurrentFiles()
		fileCount = UBound(fileIDs)

	Loop
End If

' all clients and files stopped
' shut down the database sever (does not stop the FMS service!)
fullCommand = stopServer
Set oExec = sh.Exec(fullCommand)
Do Until oExec.Status = WshFinished
	WScript.Sleep 50
Loop

' done, exit the script
Set sh = Nothing
WScript.Quit
' ------------------------------------------------------------------------------

Function getCurrentClients()

	tempCount = 0
	Dim tempArray()
	Set oExec = sh.Exec(listClients)
	
	' in case there are no clients...
	If oexec.StdOut.AtEndOfStream Then Redim temparray(0)
	
	' read the output of the command
	Do While Not oExec.StdOut.AtEndOfStream
		strText = oExec.StdOut.ReadLine()
		strText = Replace(strtext, vbTab, "")
		Do Until InStr(strtext, "  ") = 0
			strText = Replace (strtext, "  ", " ")
		Loop
		If InStr(strText, "Client ID User Name Computer Name Ext Privilege") > 0 OR _
			InStr(strText, "ommiORB") > 0 OR _
			InStr(strText, "IP Address Is invalid Or inaccessible") > 0 Then
			' do nothing
			Redim temparray(0)
		Else
			tempClient = Split(strtext, " ")
			tempCount = tempCount + 1
			Redim Preserve tempArray(tempCount)
			tempArray(tempCount-1) = tempClient(0)
		End If
	Loop
	
	getCurrentClients = tempArray

End Function

Function getCurrentFiles()

	tempCount = 0
	Dim tempArray()
	Set oExec = sh.Exec(listfiles)
	
	' in case there are no files...
	If oexec.StdOut.AtEndOfStream Then Redim temparray(0)
	
	' read the output of the command
	Do While Not oExec.StdOut.AtEndOfStream
		strText = oExec.StdOut.ReadLine()
		strText = Replace(strtext, vbTab, "")
		Do Until InStr(strtext, "  ") = 0
			strText = Replace (strtext, "  ", " ")
		Loop
		If InStr(strText, "ID File Clients Size Status Enabled Extended Privileges") > 0 OR _
			InStr(strText, "ommiORB") > 0 OR _
			InStr(strText, "IP Address Is invalid Or inaccessible") > 0 OR _
			Left(strtext, 2) = "ID" Then
			' do nothing
			Redim temparray(0)
		Else
			tempFile = Split(strtext, " ")
			status = LCase(tempFile(4))
			If status = "normal" Then
				tempCount = tempCount + 1
				Redim Preserve tempArray(tempCount)
				tempArray(tempCount - 1) = tempFile(1) & ".fp7"
			End If
		End If
	Loop
	
	getCurrentFiles = tempArray

End Function



  • Like 4
Posted

 

I've heard Wim Decorte and Steven Blackwell say to not enable the "Automatically start Database Server" option in the Admin Console, and to use an OS-level script that runs when the server starts instead.

 

 

I say it too. My reasoning is this: if the server goes down *unexpectedly* the files need to be checked. If you come in on Monday morning and the files are not available then you know the server went down some time over the weekend. If the server automatically opened them there is no clue that something has gone wrong.

 

I do not want the server opening the (possibly damaged) files up and users going back in a doing work with them. If they went down then they stay down until somebody checks them, possibly restores the previous backups and opens them back up.

 

Also of the server opens the files again then the backup schedules will run. This could possible delete the previous backups that you need to restore from.

  • Like 1
Posted

 

I've heard Wim Decorte and Steven Blackwell say to not enable the "Automatically start Database Server" option in the Admin Console, and to use an OS-level script that runs when the server starts instead. 

 

As usual Wim has provided an elegant solution.

 

I should state however is that my view is not to restart the server automatically by any means.

 

As Vaughan pointed out, if the server goes down, I would want to examine the files, and almost certainly restore from the last known good backup.

 

Interestingly, or coincidentally, this actually happened at a client site over the weekend, due to an error of the type New IT Services Provider.

 

I restored from backup, and all is well now.

 

Steven

  • Like 1
  • 2 weeks later...
Posted

Sorry for the delayed response - I followed this thread, so I expected to get an email when it got a reply, but I never got an email.

 

I agree with the reasoning behind not enabling the "Automatically start Database Server" option. However, I think my question was misunderstood. What I'm looking for is a startup script (runs when the server operating system starts), which will start the database server only if it was shut down properly.

 

Wim, thanks for providing a shutdown script - that will come in handy as well. You also alluded to the idea that the script could be reversed and modified as necessary to be turned into a startup script, but I don't quite understand that. Starting the database server itself is fairly straightforward, basically consisting of these two commands (for my installation, at least):

fmsadmin start server
fmsadmin start wpe

The part I'm not sure about is knowing when it's safe to automatically start the database server when the operating system starts.

 

Stephen, you've made your opinion very clear - that the database server should never be started automatically, regardless if it was previously shut down properly. Does everyone else share that opinion?

 

I should state that the reason I'm asking this question is that I thought I saw a thread here on the forums sometime within the last three years where Wim recommended the use of a startup script in lieu of the "Automatically start Database Server" option. I searched and searched for that thread, but could not find it, so I decided to ask.

Posted

 

 

Stephen, you've made your opinion very clear - that the database server should never be started automatically, regardless if it was previously shut down properly. Does everyone else share that opinion?

 

 

It's not an opinion, it is a best practice.

The best practice has become more important if the new progressive backups are in use.

 

Using a startup script at machine reboot is just the same as enabling auto-start in the console so it is not advisable.  A startup script is a good thing to have as part of a startup *procedure* for situations where you do not want IT administrators to become familiar with the FMS admin console.  That procedure however should also include checking the logs to verify that the last shutdown was graceful.  And monitoring the startup to see whether FMS opened the files without problems (no consistency checks).

Posted

I think I understand my confusion, now...

 

In an old thread (which I can't find), Wim mentioned a "startup script", which I took to mean: "a script that runs automatically when the server starts up", but what you meant as "a script that is run manually by a user after the server starts up".

 

So, that's the script I'm looking for, then. But I'm assuming if someone had a startup script they were willing to share, they would have shared it by now.

Posted

I think maybe not.  The term startup script usually refers to a script that executes when a FileMaker Pro file is opened, either hosted or stand-alone.  It has a new name now, something like OnFirstWindowOpen or some such.

 

Steven

This topic is 4133 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.