Automatic restart of 1C service on Windows Server with clearing of session cache

Good day, colleagues. Category: 1C: Enterprise server administration.

I would like to start my article with the types of testing used in the 1C:Enterprise product to check the information system (IS) for technological quality and scalability. In the 1C world, two types of testing are used for this:

· performance testing
(there is a separate one article about the integrated performance assessment using the APDEX method)

· And stress testing
(this is when the execution of specific operations is simulated programmatically in the tested IS and the number of threads for their execution is systematically increased until the IS fails or its performance decreases to unacceptable values).

There is a testing methodology for such types of testing, but there is no one to implement it, there are no requirements, etc.

Why does this happen? An expert on technological issues on an implementation project is expensive, and even if there is one, it is not always possible to obtain from the customer clear requirements on the composition of key operations in order to conduct a thorough analysis of the product being implemented.

The lack of real tests of the developed information system for technological quality and scalability results in regular freezes (freezing of the program for some time or until the 1C service is restarted on the server) when users are simultaneously working in a productive environment.

Most often, the cause of freezes is not in incorrectly selected infrastructure parameters (number of processors, amount of RAM, fast or slow disks, etc.), but in bad code in the 1C language, which requires refactoring by an expert on technology issues based on research, for example, as described in the article about APDEX.

If you look for such an expert, it will take more than one month, and refactoring will take a month or more (depending on the employee’s experience and the scale of the disaster).

All this time you have to live somehow.

Often the problem can be stabilized by configuring the 1C cluster to restart work processes using the 1C cluster itself, the process is described in the instructions on the portal its.1c.ru.

The solution with setting up a cluster is not always suitable, because the setting allows you to restart work processes:

– by timer;

– when the specified volume of RAM is exceeded.

Timer restart is inconvenient from the user's point of view: each time the restart occurs, the application's user interface seems to freeze without any identification marks, causing confusion among users.

Restarting when the specified amount of RAM is exceeded does not solve the problem of terminating problematic work processes, since the problem does not always lie in them. Perhaps such a volume is quite acceptable based on the business logic of the application, for example, when performing mass work according to regulations.

When for some reason you can't manage with cluster settings, there is a fairly effective way – regularly restart the 1C service with clearing the session data cache. The storage directory can be found out from the 1C service startup parameters, after the -d key you should specify the service directory, for example:

C:\Program Files\1cv8\8.3.22.2283\bin\ragent.exe" -srvc -agent -regport 1541 -port 1540 -range 1560:1591 -d "C:\Program Files\1cv8\srvinfo" -debug

For a server started with the -regport 1541 option, the session data directory will be located in the “reg_1541” directory and will start with “snccntx”:

"C:\Program Files\1cv8\srvinfo\reg_1541\snccntx<ИдентификаторГлавногоМенеджераКластера>",

The restart must be performed outside of working hours (of course!).

You can, of course, ask the administrator to do this manually every day, but not everyone will agree to this.

Windows does not have any out-of-the-box means of restarting services on a timer, much less clearing the session cache.

The solution may be a cmd or powershell script and the OS's built-in task scheduler `taskschd.msc`, configured to execute this script.

Why did I decide to write this script? The query “Automatic restart of the 1C service on Windows Server” only returned solutions on the Internet with a pause of a fixed time between stopping the service and starting it. This method can work as long as it is known how long it takes for the working processes to complete correctly after the command to stop the service is given. That is, if we consider the option of waiting for the correct completion of processes, it is worth waiting as long as necessary, and not a fixed time specified in the script. Therefore, I included in the script a check for the presence of active processes in the OS memory with names that correspond to the 1C service processes, namely: “rmngr.exe”, “rphost.exe”, “ragent.exe”.

I am attaching the script itself:

#We specify the name of the 1C server service and stop it

$serviceName = '1C:Enterprise 8.3 Server Agent (x86-64)'
stop-service -name $serviceName -force

#Waiting for processes to complete
Do { $Processes= Get-Process| Where {($_.Name -eq “rphost”) -or ($_.Name -eq “rmngr”) -or ($_.Name -eq “ragent”)}| select name, starttime}
Until($Processes.Count -eq 0)

#Calculate the directory for storing session data
$o = Get-WmiObject win32_service | ?{$_.Name -like $serviceName} | select-object
$ss = $o.PathName.SubString($o.PathName.LastIndexOf(“-d “))
$sss = $ss.SubString($ss.IndexOf(“”””)+1)
$ssss=$sss.SubString(0,$sss.IndexOf(“”””))
$regport= $o.PathName.SubString($o.PathName.LastINdexOf(“regport”)+8,4)
$ServiceDataDir = $ssss+'\reg_'+$regport+'\'
$SessionDataDir = Get-ChildItem -Path $ServiceDataDir -Filter snccntx*

#Delete session data
Remove-Item -recurse $ServiceDataDir$SessionDataDir

#Launching the 1C server service
start-service -name $serviceName

,

'1C:Enterprise 8.3 Server Agent (x86-64)' is the service name as it is specified in the registry editor branch.

There are two ways:

1. Using the registry editor. You can open it as follows: press the key combination Win+R, in the “Open” field type the command regidit, the registry editor will open, where the service name is the name of the folder in the branch (highlighted in bold):

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\1C:Enterprise 8.3 Server Agent (x86-64)

2. Using the services console

Press the key combination Win+R, then type the command: services.msc

In the list of services that opens, we find the 1C service, open its card, the name, this is the value opposite “Service Name” (“Service Name” in the Russian interface).

To run the script, you need to save it to a text file and assign the file extension .ps1. Next, place this file in the directory from which it will be run, for example, %appdata%.

You can open the task scheduler like this:

1. Press the key combination Win+R, then type the command: taskschd.msc.

2. Find the Microsoft folder, right-click on it and select “create basic task”.

3. Fill in a name that is understandable to you, reflecting the essence of the operation being performed, for example, restart1cserviceClearCache. It is not necessary to fill in the description, but since the server may be serviced by other people in the future, you can write something like “restart the 1c service on schedule”. Believe me, your colleagues will remember you with a kind word for a clear presentation of the task:).

4. Specify the time and frequency of execution at your discretion.

5. Set the action to “Start a program”

6. In the “Program or script” field, specify the powershell program (my path is as follows: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe),

as a parameter (field “Add arguments (optional)”) we specify the path to the file with the script through the `-File` key: -File "%appdata%\restart1cserviceClearCache.ps1".

Click “OK”.

Your scheduled task to restart the service with clearing the cache is ready, all that remains is to check its operation.

If you have a test server where there are no working users, set up the task on it first.

To check the functionality, open the session data directory with Explorer so that the creation dates of the files in it are visible. "C:\Program Files\1cv8\srvinfo\reg_1541\snccntx* and powershell editor.

In the powershell editor, enter the command:

Get-Process| Where {($_.Name -eq "rphost") -or ($_.Name -eq "rmngr")}| select name, starttime (*)

The result of this command is a table with the start date of the 1C service processes, for example:

Name StartTime
—- ———
rmngr 06.08.2024 18:33:47
rphost 06.08.2024 18:34:51
rphost 06.08.2024 18:33:50

Do not close the editor.

In the task scheduler, hover over the task you created, right-click, and then select “Run”.

Once completed, go to powershell editor and repeat the command

once again. If you see new StartTime values ​​for processes, then the restart was successful, it remains to check whether the cache has been cleared. "C:\Program Files\1cv8\srvinfo\reg_1541\snccntx*We look at the creation dates of files in the directory

. If they match the new StartTime values, then the script worked successfully.

That's all, thanks for your attention 🙂

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *