@ set LOGFILE = "log.% DATE% _% TIME: ~ 0.2% -% TIME: ~ 3.2% -% TIME: ~ 6.2% .txt"
for / f "tokens = 1-4 delims =:" %% a in ( 'echo% time: ~ 0.8%' ) do set mytime = %% a_ %% b_ %% c
@ rem INSTALL or REMOVE
set ACTION = % 1
@ rem Format: < ComputerName > < InstanceName > or just IP
@ rem If neither the -U parameter nor the -P parameter is specified, the sqlcmd program tries to connect using the Microsoft Windows authentication mode.
@ rem This uses the Windows user account that started the sqlcmd program.
set url_db = "(local)"
@ rem Fill in these parameters, y - if we create a global database for the kernel
@ set WorkWhisKernel = % 2
@ set KernelDbName = Kernel
@ set KernelUserName = Kernel
@ set KernelUserPassw = Kernel
@ rem Recovery model for the database. FULL values available | BULK_LOGGED | SIMPLE
@ set KernelRecovery_mode = SIMPLE
@ rem Fill in these parameters, y - if we create a database for the channel
@ set WorkWhisChannel = % 3
@ set ChannelDbName = Channel
@ set ChannelDbCount = 10
@ set ChannelUserName = Channel
@ set ChannelUserPassw = Channel
@ rem Recovery model for the database. FULL values available | BULK_LOGGED | SIMPLE
@ set ChannelRecovery_mode = SIMPLE
@ rem Use the "_" character to separate the database name and its number. For example test_1 or test1
@ set Use_underline = y
@ rem Database Version for Channel
@ set ChannelVersion = mssql.Channel_5.4.3.2
@ rem Fill in these parameters, y - if we create a database for Bridge
@ set WorkWhisBridge = % 4
@ set BridgeDbName = Bridge
@ set BridgeUserName = Bridge
@ set BridgeUserPassw = Bridge
@ rem Recovery model for the database. FULL values available | BULK_LOGGED | SIMPLE
@ set BridgeRecovery_mode = SIMPLE
@ rem Database version for Bridge
@ set BridgeVersion = mssql.Bridge_1.1.3
if "% WorkWhisI_k%" == "y" (
if "% ACTION%" == "INSTALL" (
@ rem Create a global database for Kernel and the user and its
sqlcmd -S % url_db % -i Kernel.sql >> % LOGFILE %
)
if "% ACTION%" == "REMOVE" (
@ rem Delete the DB informer_kernel and its user
sqlcmd -S % url_db % -i KernelDel.sql >> % LOGFILE %
)
)
- Create a login for the database
CREATE LOGIN $ ( KernelUserName )
WITH PASSWORD = '$ (KernelUserPassw)' , CHECK_POLICY = OFF;
GO
--We create a database
USE master;
CREATE DATABASE $ ( KernelDbName ) ;
GO
- Set DB recovery mode
ALTER DATABASE $ ( KernelDbName ) SET RECOVERY $ ( KernelRecovery_mode )
GO
--Create a user for the database
USE $ ( KernelDbName ) ;
CREATE USER $ ( KernelUserName ) FOR LOGIN $ ( KernelUserName )
WITH DEFAULT_SCHEMA = dbo;
GO
- assign a role to the user
USE $ ( KernelDbName ) ;
EXEC sp_addrolemember 'db_owner' , '$ (KernelUserName)'
GO
for / L %% i in ( 1 , 1 , % ChannelDbCount % ) do (
if "% Use_underline%" == "y" (
@ set ChannelDbNameCounter = % ChannelDbName % _ %% i
) else (
@ set ChannelDbNameCounter = % ChannelDbName %%% i
)
% ChannelDbNameCounter %
@ rem Create a database cp_service
sqlcmd -S % url_db % -i Channel.sql >> % LOGFILE %
@ rem Create a database structure for cp_service
sqlcmd -S % url_db % -i % ChannelVersion % .sql >> % LOGFILE %
)
@ rem Number of Channels
SET ChannelDbCount = 10
@ rem Startup Type < boot | system | auto | demand | disabled | error >
SET run_type = demand
@ rem Service dependencies ( separated by / ( forward slash ) )
SET depend = MSSQLSERVER
for / L %% i in ( 1 , 1 , % ChannelDbCount % ) do (
@ rem install the service Channel. To install a component as a service, its internal implementation is used.
ruby Channel %% i.exe --install
@ rem for the service set 3 reboot with an interval of 1 min. if a fatal error has occurred
sc failure Channel %% i reset = 240 actions = restart / 60000 / restart / 60000 / restart / 600000
@ rem startup type of service < boot | system | auto | demand | disabled | error > and dependencies < Dependencies ( separated by / ( forward slash ) ) >
sc config Channel %% i start = % run_type % depend = % depend %
)
We start the installed services:
for / L %% i in ( 1 , 1 , % ChannelDbCount % ) do (
sc start Channel %% i
)
@ rem Run our main script with parameters to create databases
DbManage.bat INSTALL % 1 % 2 % 3
@ rem Install Services
InstallServices.bat
@ rem Run all services
StartServices.bat
@ rem Stop services if they are running.
StopServices.bat
@ rem Making a groove so that all services have time to stop
@ rem This method may not work in non-server Windows
timeout / t 10
@ rem Delete old services
RemoveServices.bat
@ rem Run the main script with the parameters for removal
start DbManage.bat REMOVE % 1 % 2 % 3
Source: https://habr.com/ru/post/138162/
All Articles