Automate SQL 2012 policy management with powershell
Hello.
I´m trying to automate policy management via Powershell and I´m running into some problems. What I want to do is register a SQL 2012 server to a group in a CMS server and then import a pre defined policy into that server. The first part where I register
the client server is no problem but I cant figure out how to import the policy.
Has anyone else run into this problem?
Regards.
/Niklas
Of course!
First thing you need to do if it is not already done is to register the CMS server.
Set-Location "SQLSERVER:\SQLRegistration\Central Management Server Group"
New-Item -Name $CMSServer -ItemType registration -Value "server=$CMSServer;integrated security=true"
Second you want to register the client server into a CMS server group.
Set-Location "SQLSERVER:\SQLRegistration\Central Management Server Group\$CMSServer\SQL Server Group"
New-Item -Name $serverToRegister.Replace("\","`$") -ItemType registration -Value "server=$serverToRegister;integrated security=true"
When this is done I want to create my policy and schedule on all my target machines. I defined my policies directly in my powershell script so if
you want to import the exported policies you probably need to extract information from the XML files.
This example creates a schedule called hisec that executes daily at 1 am.
$createSchedulecommand = @"
DECLARE @start_date varchar(8) = convert(varchar(8), DATEADD(day,-1,GETDATE()), 112)
EXEC msdb.dbo.sp_add_schedule @schedule_name = N'hisec',
@enabled = 1, @freq_type = 4, @freq_interval = 1, @active_start_date = @start_date,
@active_start_time = 010000; "@
Invoke-Sqlcmd -Query $createSchedulecommand -ServerInstance $targetInstanceName -Database "msdb"
Next thing is to create my policy. This example checks if XPCmdShell is enabled.
$createPolicyCommand = @"
DECLARE @object_SET_id int
EXEC msdb.dbo.sp_syspolicy_add_object_SET
@object_SET_name=N'hisec_ObjectSET',
@facet=N'IServerSecurityFacet',
@object_SET_id=@object_SET_id OUTPUT;
DECLARE @target_SET_id int
EXEC msdb.dbo.sp_syspolicy_add_target_SET
@object_SET_name=N'hisec_ObjectSET',
@type_skeleton=N'Server',
@type=N'SERVER',
@enabled=True,
@target_SET_id=@target_SET_id OUTPUT;
GO
DECLARE @uid varchar(40)
SET @uid = (select schedule_uid from msdb..sysschedules where name = 'hisec')
DECLARE @policy_id int
EXEC msdb.dbo.sp_syspolicy_add_policy
@name=N'hisec',
@condition_name=N'ServerSecurity',
@policy_category=N'',
@description=N'',
@help_text=N'',
@help_link=N'',
@schedule_uid=@uid,
@EXECution_mode=4,
@is_enabled=True,
@policy_id=@policy_id OUTPUT,
@root_condition_name=N'',
@object_SET=N'hisec_ObjectSET';
GO
Invoke-Sqlcmd -Query $createPolicyCommand -ServerInstance $targetInstanceName
-Database "msdb"
Hope this can help you somehow.
Similar Messages
-
Server 2012 R2 Group policy management with older Domain servers
Hi Guys,
I need your expert assistance with a issue I'm facing.
We have a client that has 3 domain controllers. The Primary DC is running Server 2003 R2, another one is running Server 2008, and the last DC is running Server 2008 R2. The forest functional level is Server 2000 & the domain functional level is Server
2003.
Currently Group policy is processing using a central store across the 3 domain controllers.
We have installed a new Server 2012 R2 Terminal server and need to apply group policies to the Server to lock it down.
We have a separate Server 2012 R2 server (say SERVER1) that is also joined to the domain that I have added the group policy management feature to so it can remotely manage group policy.
It seems to be pulling the all the group policy details from the central store so I can't see any of the server 2012 related settings on
SERVER1.
Are we going about this the correct way? how would we best manage the Server 2012 policies? I was thinking either somehow making the specific TS group policy only load in a local policy or templates somehow..If you are using a central policy store, this is the expected (intended) behaviour.
You willl need to update the central store with the latest versions of the adm(x/l) files.
http://www.microsoft.com/en-us/download/details.aspx?id=36991
or grab them from a 2012(r2) instalaltion c:\Windows\PolicyDefinitions
MCP/MCSA/MCTS/MCITP -
SQL 2012 install fails with 'Object reference not set to an instance of an object.'
Hi, I'm trying to install SQL 2012 RTM Enterprise on a Windows 2008 R2 single node cluster.
The installer starts goes through some checks and then fails with the message 'Object reference not set to an instance of an object.' It happens while the small 'wait while...' dialog box is
showing, another window pops up briefly (I think the feature selection window - can't really tell as it doesn't draw before disappearing). Then the ‘Object reference not set’ message comes up.
From the summary log file..
Overall summary:
Final result:
Failed: see details below
Exit code (Decimal):
-2147467261
Exit facility code:
0
Exit error code:
16387
Exit message:
Object reference not set to an instance of an object.
Start time:
2012-09-26 08:52:53
End time:
2012-09-26 08:54:08
Requested action:
InstallFailoverCluster
Exception help link:
http://go.microsoft.com/fwlink?LinkId=20476&ProdName=Microsoft+SQL+Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=11.0.2100.60&EvtType=0x9AF1AE5E%400x44A889F9&EvtType=0x9AF1AE5E%400x44A889F9
Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented
Exception type: System.NullReferenceException
Message:
Object reference not set to an instance of an object.
Data:
HelpLink.EvtType = 0x9AF1AE5E@0x44A889F9
DisableWatson = true
Stack:
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.ShouldRuleRun(Rule rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.IsRuleSkipped(Rule rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRule(String ruleId, List`1 ruleProperties, XmlSchema ruleSchema, XmlElementParserFactory elementParser)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRules(IEnumerable`1 ruleIds)
at Microsoft.SqlServer.Configuration.InstallWizard.RunRuleProgressController.Initialize()
I have rebooted, tried different media, tried uninstalling the setup files and rerunning but always get the same result.
Any help would be gratefully accepted.
Thanks,
Bruce.Hi Alberto,
Whenever I am trying to install SQL 2012 with SP1 clustering, I am getting below error. Can you please advise on this.
Additional information are
Windows Servers Version and Edition - Windows 2012 Strandedition
SQL Server Version and Edition - SQL 2012 with SP1
All the machines are running on Hyper-V and Passed the cluster validation test successfully. there is no issue. The servers' (Nodes) names are;
DomainServerName - ACONDomainGroup (1gb ram allocated)
Node1 - AconNODE1W2K12STD (2.5gb ram allocated )
Node2 - AconNODE2W2K12STD (1.5 ram allocated allocated)
WindowsClusterName - AconWinCLTR
Below is Summary.txt Error
Update Source: MU
User Input Settings:
ACTION: InstallFailoverCluster
AGTDOMAINGROUP: <empty>
AGTSVCACCOUNT: <empty>
AGTSVCPASSWORD: <empty>
ASBACKUPDIR: Backup
ASCOLLATION: Latin1_General_CI_AS
ASCONFIGDIR: Config
ASDATADIR: Data
ASLOGDIR: Log
ASPROVIDERMSOLAP: 1
ASSERVERMODE: MULTIDIMENSIONAL
ASSVCACCOUNT: <empty>
ASSVCPASSWORD: <empty>
ASSVCSTARTUPTYPE: Automatic
ASSYSADMINACCOUNTS: <empty>
ASTEMPDIR: Temp
COMMFABRICENCRYPTION: 0
COMMFABRICNETWORKLEVEL: 0
COMMFABRICPORT: 0
CONFIGURATIONFILE:
ENU: true
ERRORREPORTING: false
FAILOVERCLUSTERDISKS: <empty>
FAILOVERCLUSTERGROUP:
FAILOVERCLUSTERIPADDRESSES: <empty>
FAILOVERCLUSTERNETWORKNAME: <empty>
FEATURES:
FILESTREAMLEVEL: 0
FILESTREAMSHARENAME: <empty>
FTSVCACCOUNT: <empty>
FTSVCPASSWORD: <empty>
HELP: false
IACCEPTSQLSERVERLICENSETERMS: false
INDICATEPROGRESS: false
INSTALLSHAREDDIR: C:\Program Files\Microsoft SQL Server\
INSTALLSHAREDWOWDIR: C:\Program Files (x86)\Microsoft SQL Server\
INSTALLSQLDATADIR: <empty>
INSTANCEDIR: C:\Program Files\Microsoft SQL Server\
INSTANCEID: <empty>
INSTANCENAME: <empty>
ISSVCACCOUNT: NT AUTHORITY\Network Service
ISSVCPASSWORD: <empty>
ISSVCSTARTUPTYPE: Automatic
MATRIXCMBRICKCOMMPORT: 0
MATRIXCMSERVERNAME: <empty>
MATRIXNAME: <empty>
PID: *****
QUIET: false
QUIETSIMPLE: false
RSINSTALLMODE: DefaultNativeMode
RSSHPINSTALLMODE: DefaultSharePointMode
RSSVCACCOUNT: <empty>
RSSVCPASSWORD: <empty>
RSSVCSTARTUPTYPE: Automatic
SAPWD: <empty>
SECURITYMODE: <empty>
SQLBACKUPDIR: <empty>
SQLCOLLATION: SQL_Latin1_General_CP1_CI_AS
SQLSVCACCOUNT: <empty>
SQLSVCPASSWORD: <empty>
SQLSYSADMINACCOUNTS: <empty>
SQLTEMPDBDIR: <empty>
SQLTEMPDBLOGDIR: <empty>
SQLUSERDBDIR: <empty>
SQLUSERDBLOGDIR: <empty>
SQMREPORTING: false
UIMODE: Normal
UpdateEnabled: true
UpdateSource: MU
X86: false
Configuration file: C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log\20140420_052344\ConfigurationFile.ini
Rules with failures:
Global rules:
There are no scenario-specific rules.
Rules report file: C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log\20140420_052344\SystemConfigurationCheck_Report.htm
Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented
Exception type: System.NullReferenceException
Message:
Object reference not set to an instance of an object.
HResult : 0x80004003
Data:
HelpLink.EvtType = 0x9AF1AE5E@0x44A889F9
DisableWatson = true
Stack:
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.ShouldRuleRun(Rule rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.IsRuleSkipped(Rule rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRule(String ruleId, List`1 ruleProperties, XmlSchema ruleSchema, XmlElementParserFactory elementParser)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRules(IEnumerable`1 ruleIds)
at Microsoft.SqlServer.Configuration.InstallWizard.RunRuleProgressController.Initialize() -
How to automate Sql Server Configuration Manager settings?
For example, I have just installed Sql Express 2012, and need to configure it for use over the local network. Usually I just manually open Sql Server Configuration Manager -- Sql Server Network Configuration -- <myinstance>, and enable TCP/IP on 1433.However,
I am not going to be available to do this on every customer's computer. I need to do these steps using a script or something. Is there a way to do this?Have a look at this stackexchange thread:
http://stackoverflow.com/questions/9138172/enable-tcp-ip-remote-connections-to-sql-server-express-already-installed-databas
There are two good options outlined there
1. install it with the /TCPENABLED=1 switch (in the original post)
2. Execute a wmi script post-install (in the answer)
Note: if you decide to use WMI the root path will be \root\Microsoft\SqlServer\ComputerManagement11 for 2012
I will have to support install time, and post install. Does TCPENABLED=1 also setup the 1433 port value in TCP/IP Properties - IP Addresses tab? -
SQL 2012 R2 - SSRS with the Report Server Web Service URL, can't access
Hello:
I am installing Dynamics CRM 2013. When I am on RS Configuration manager; I am running into the SSRS (SQL 2012 on Server 2012)SQL issue, can't access the
http://servername/:80/ReportsServer or
http://servername/:Reports web pages
The database server has SSRS native mode installed, it is using a domain account for the service credentials. This account also has permission to log on a service in the GPO
Account is a domain admin and is a local administrator
SQL server is 2012 R2 on Windows Server 2012. User base is less than 60 people and they have SharePoint 13 on the same SQL server. Server more than enough resources.
Any assistance would be appreciated.
Thanks..DanHi DCas1,
According to your description, you could not access
http://servername/:80/ReportsServer or http://servername/:Reports web pages from Reporting Services configuration manager, SSRS in configured in native mode and the account you used is a local administrator.
In Reporting Services, URLs are used to access the Report Server Web service and Report Manager. Before we can use either application, we need to configure at least one URL each for the Web service and Report Manager. If we are using the Reporting Services
Configuration tool to create or modify the URLs, we can accept the default values for a URL or specify custom values. When we create a report server URL, we must specify the following parts: Host name, port and Virtual directory. In order to improve the efficiency
of troubleshooting, I need to ask several questions:
Since the default URL is http://<computername>/reportserver, did you type the URLs manually? or the URLs configured in Reporting Services configuration manager are
http://servername/:80/ReportServer and
http://servername/:Reports?
Could you provide detailed information of error log(default location: %programfiles%\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\LogFiles)?
For more information about Configuring a URL, please refer to the following documents:
http://msdn.microsoft.com/en-us/library/ms159261(v=sql.110).aspx
http://msdn.microsoft.com/en-us/library/bb630447(v=sql.110).aspx
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu -
Use a SQL 2012 database server with Reporting Services 2008?
Hello, we have a SQL Server 2008 R2 Reporting Services Standard server with the reporting databases running on a SQL Server 2008 Standard database server. I would like to upgrade the database server to SQL Server 2012 before I upgrade the reporting server.
Can I run SQL Server 2008 R2 Reporting Services against a 2008-version database running on a SQL 2012 database server? Thanks for your help.
Hi Nicole
Thanks for your posting.
Are you asking if we can connect from SSRS 2008 r2 to a database sitting on SQL Server 2012. Am I right?, please ignore me if I misunderstood your question. If that is your question
then I think you will be able to using BIDS 2008, I have created A database on SQL Server 2012 and I use that database table inside my SSRS 2008 R2 dataset. I can even think that you can use a database of compatibility level of 2012(110) as well
Many thanks
Syed Qazafi Anjum -
SQL 2012 AlwaysOn AG with 3 Nodes
First, what would be the best option of quorum/quorum witness for my SQL 2012 AlwaysOn group?
I have setup the following:
SQL 2012 AlwaysOn with 3 nodes.
1 primary
2 secondaries - one of them is read-only (for reporting and backup)
Dynamics CRM and Reporting DBs are running on them.
How can I achieve the highest avalability and DR with my SQL? Do I even need to create the quorum witness? What kind of Quorum (majority nod with network share?)
Second, Is it good idea to run the backup on that read-only node? If I setup the maintenance plan on this 3rd read-only mode with full and transactional backups, I should be able to restore without any issues?
Third, I have another DB (SharePoint) that needs to be moved over to this SQL AlwaysOn AG but wondering if I can restore it in the secondary node to utilize the unused resources. Is that possible or not recommended?Are the replicas on the same network subnet? If they are, then, you already have a quorum with node majority (odd number of votes.) Since you are already paying for an additional license to run read-only workloads on your readable secondary, you can take
backups on this replica. Full database backups are in COPY_ONLY mode but you can take regular log backups which will truncate the log on the primary replica. In theory, you will be able to restore the backups taken from your readable secondary but you should
test (hence, why I mentioned "in theory.") I wouldn't move my SharePoint databases to this SQL Server Availability Group mainly because of the different requirements between the two - SharePoint and Dynamics CRM. MAXDOP =1, disabling index maintenance and
statistics updates on SharePoint databases, etc. are just a few of them. Besides, I doubt that the recovery objectives and service level agreements between those two applications are the same within your organization.
Edwin Sarmiento SQL Server MVP | Microsoft Certified Master
Blog |
Twitter | LinkedIn
SQL Server High Availability and Disaster Recover Deep Dive Course -
Executing a SQL 2012 SSIS project with DTExec using Protection Level "EncryptAllWithPassword"
I'm trying to execute a very basic SQL 2012 Project that only has 1 single package that contains a simply email task.
The project will run fine from command line using basic syntax.
dtexec /project "F:\SSIS\Projects\project1\bin\Project 1 Configuration\project1.ispac" /package "Main.dtsx"
Once I add the protection level of EncryptAllWithPassword to the project and the package things suddenly stop working. New command line syntax is.
dtexec /project "F:\SSIS\Projects\project1\bin\Project 1 Configuration\project1.ispac" /package "Main.dtsx" /P "Password"
I get the following output.
Microsoft (R) SQL Server Execute Package Utility
Version 11.0.2100.60 for 64-bit
Copyright (C) Microsoft Corporation. All rights reserved.
Started: 5:14:49 PM
Could not load project "F:\SSIS\Projects\project1\bin\Project 1 Configuration\project1.ispac" because of error 0x80131500.
Description: The encrypted data in project manifest failed to load. The project
manifest is corrupted or if the project is password protected, the specified password is incorrect.
Source: Microsoft.SqlServer.ManagedDTS
Started: 5:14:49 PM
Finished: 5:14:49 PM
Elapsed: 0.078 seconds
I'm confident my passwords are entered correctly in the two spots. Is there something I'm missing in my command line to use protection levels correctly. I have also built the project and deployed to SSISDB.
Thank youAdd the PassWord attribute as :
dtexec /project "F:\SSIS\Projects\project1\bin\Project
1 Configuration\project1.ispac" /package "Main.dtsx" /P "YourPassWord"
For more info :
http://technet.microsoft.com/en-us/library/ms138023(v=sql.105).aspx -
Hi All,
Could you please help me here? On my Laptop which is running on windows 8.1 Operation system, I enabled the Hyper-V client feature and setup the Windows Fail-over Clustering using Windows 2012 Standard Edition. So, there are three machines which are running
on the Hyper-V. Below are the machine details;
1st machine - Working as Domain controller and its name is "ACONDomainGroup" and allocated to
1GB RAM to use.
2nd machine - Working as Node1 and its name is "AconNODE1W2K12STD"
and allocated to 2.5GB RAM to use.
3rd machine - Working as Node1 and its name is "AconNODE1W2K12STD"
and allocated to 1.5GB RAM to use.
and the windows virtual cluster name is "AconWinCLTR". While I am doing the SQL Cluster Installation, I am getting below mentioned error. all systems have 4.5 .net installed. May you please guide me where and what i am missing to complete sql clustering.....
Update Source: MU
User Input Settings:
ACTION: InstallFailoverCluster
AGTDOMAINGROUP: <empty>
AGTSVCACCOUNT: <empty>
AGTSVCPASSWORD: <empty>
ASBACKUPDIR: Backup
ASCOLLATION: Latin1_General_CI_AS
ASCONFIGDIR: Config
ASDATADIR: Data
ASLOGDIR: Log
ASPROVIDERMSOLAP: 1
ASSERVERMODE: MULTIDIMENSIONAL
ASSVCACCOUNT: <empty>
ASSVCPASSWORD: <empty>
ASSVCSTARTUPTYPE: Automatic
ASSYSADMINACCOUNTS: <empty>
ASTEMPDIR: Temp
COMMFABRICENCRYPTION: 0
COMMFABRICNETWORKLEVEL: 0
COMMFABRICPORT: 0
CONFIGURATIONFILE:
ENU: true
ERRORREPORTING: false
FAILOVERCLUSTERDISKS: <empty>
FAILOVERCLUSTERGROUP:
FAILOVERCLUSTERIPADDRESSES: <empty>
FAILOVERCLUSTERNETWORKNAME: <empty>
FEATURES:
FILESTREAMLEVEL: 0
FILESTREAMSHARENAME: <empty>
FTSVCACCOUNT: <empty>
FTSVCPASSWORD: <empty>
HELP: false
IACCEPTSQLSERVERLICENSETERMS: false
INDICATEPROGRESS: false
INSTALLSHAREDDIR: C:\Program Files\Microsoft SQL
Server\
INSTALLSHAREDWOWDIR: C:\Program Files (x86)\Microsoft SQL Server\
INSTALLSQLDATADIR: <empty>
INSTANCEDIR: C:\Program Files\Microsoft
SQL Server\
INSTANCEID: <empty>
INSTANCENAME: <empty>
ISSVCACCOUNT: NT AUTHORITY\Network
Service
ISSVCPASSWORD: <empty>
ISSVCSTARTUPTYPE: Automatic
MATRIXCMBRICKCOMMPORT: 0
MATRIXCMSERVERNAME: <empty>
MATRIXNAME: <empty>
PID: *****
QUIET: false
QUIETSIMPLE: false
RSINSTALLMODE: DefaultNativeMode
RSSHPINSTALLMODE: DefaultSharePointMode
RSSVCACCOUNT: <empty>
RSSVCPASSWORD: <empty>
RSSVCSTARTUPTYPE: Automatic
SAPWD: <empty>
SECURITYMODE: <empty>
SQLBACKUPDIR: <empty>
SQLCOLLATION: SQL_Latin1_General_CP1_CI_AS
SQLSVCACCOUNT: <empty>
SQLSVCPASSWORD: <empty>
SQLSYSADMINACCOUNTS: <empty>
SQLTEMPDBDIR: <empty>
SQLTEMPDBLOGDIR: <empty>
SQLUSERDBDIR: <empty>
SQLUSERDBLOGDIR: <empty>
SQMREPORTING: false
UIMODE: Normal
UpdateEnabled: true
UpdateSource: MU
X86: false
Configuration file: C:\Program Files\Microsoft SQL Server\110\Setup
Bootstrap\Log\20140420_052344\ConfigurationFile.ini
Rules with failures:
Global rules:
There are no scenario-specific rules.
Rules report file: C:\Program Files\Microsoft SQL Server\110\Setup
Bootstrap\Log\20140420_052344\SystemConfigurationCheck_Report.htm
Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented
Exception type: System.NullReferenceException
Message:
Object reference not set to an instance of an object.
HResult : 0x80004003
Data:
HelpLink.EvtType = 0x9AF1AE5E@0x44A889F9
DisableWatson = true
Stack:
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.ShouldRuleRun(Rule
rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.IsRuleSkipped(Rule
rule)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRule(String
ruleId, List`1 ruleProperties, XmlSchema ruleSchema, XmlElementParserFactory elementParser)
at Microsoft.SqlServer.Configuration.RulesEngineExtension.RulesEngine.LoadRules(IEnumerable`1
ruleIds)
at Microsoft.SqlServer.Configuration.InstallWizard.RunRuleProgressController.Initialize()Dharmendra, the log details are incomplete are not sufficient enough for I guess anyone to help. Besides, from the details above, I can see that the Failover Cluster Disks are not selected:-
FAILOVERCLUSTERDISKS: <empty>
FAILOVERCLUSTERGROUP:
FAILOVERCLUSTERIPADDRESSES: <empty>
FAILOVERCLUSTERNETWORKNAME: <empty>
Please mark the answer as helpful if i have answered your query. Thanks and Regards, Kartar Rana -
Automatically starting Oracle Enterprise Manager with chkconfig
Folks,
While Oracle Linux 6 is out (6.2 actually), Oracle has yet to get everything 'working out of the box' with 6.2. Right now (June 2012) you've got to download patches from Oracle, the new way to start services in Linux 6, upstart, doesn't work with all Oracle features yet, etc. Update: You can still use chkconfig with OL6.
Because of the above, I've been using Oracle Linux 5.8. Linux 5 uses something called chkconfig to register services. You first need to put a script in the right directory: /etc/rc.d/init.d. Linux looks in this directory for scripts and runs those scripts with either a start or stop after them depending on if the system is coming up or going down. Technically this happens every time you change your runlevel (google Unix runlevels for more info), not just when the system goes up or down.
Here's a script that you can put in /etc/rc.d/init.d. I named mine oracleEM:
[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost init.d]# vi oracleEM
Enter i to enter insert mode and then enter the below (or just copy and paste it)
*#!/bin/sh*
*#chkconfig: 2345 80 05*
*#description: Oracle Enterprise Manager*
ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORA_OWNER=oracle
ORA_SID=orcl
*# We're checking to see if ps returns 1 or 2 results for pmon_orcl*
*# If there are two, Oracle is running, one we are just seeing our grep*
ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)
*if [ ! -f $ORA_HOME/bin/emctl ]*
then
echo "Enterprise Manager startup: cannot start"
exit
fi
case "$1" in
*"start")*
*if [ $ORACLE_STATUS -lt 2 ]*
then
echo "Waiting for Oracle instance $ORA_SID to start before starting Enterprise Manager"
fi
*while [ $ORACLE_STATUS -lt 2 ];do*
echo "Waiting...."
sleep 5
ORACLE_STATUS=$(ps -eaf | grep pmon_$ORA_SID | wc -l)
done
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
*"stop")*
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
esac
Press the Esc key to leave insert mode, then type *:wq* to write the file and quit.
We'll need to make the script executable, so we need to run the following command:
[root@localhost init.d]# *chmod +x oracleEM*
Finally we need to register the oracleEM script with Linux using the chkconfig command:
[root@localhost init.d]# *chkconfig --add oracleEM*
Now Enterprise Manager will start up automatically when you start your system, but only after Oracle has started.
Rich
Edited by: RichS on Jun 9, 2012 1:00 AMThe script you are using will not work for RHEL or Oracle Linux since it is incorrect and missing important coding.
You can probably fix the script by removing the dash (-) from the su command and adding the lockfile that is required for RHEL to process the stop routine at system shutdown. The dash will reset the shell environment and the startup won't work. You should also start it in the background in order not to prolong the system startup more then necessary.
lockfile=/var/lock/subsys/oracleEM
start)
su $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole &" &>/dev/null
touch $lockfile
stop)
su $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
rm -rf $lockfile
...You do not need to start your Oracle instance before starting dbconsole. So there is no need for the "sleep" routine. You can start the Oracle Database control console even when the instance is down:
For instance:
<pre>
[oracle@vm005 ~]$ ps -ef | grep pmon
oracle 17749 10343 0 22:48 pts/3 00:00:00 grep pmon
$ emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
https://vm005.example.com:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ....... started.
</pre> -
Hi Expert,
I have following infrastructure at par. where i have 3 server in WFC(Windows Failover cluster) Win2012 and out of 3 servers two servers are active/passive cluster with SQL Instance hosted on it and i have created AG group for 3 users database and setup Sync
Replica on 3rd server within my WFC cluster.
I have SQL VIP(Virtual Server Name) for cluster and also i have AG Listener resources also on the cluster. Now this cluster is attached to SAN single.
3rd server where we kept sync replica its storage is not coming from SAN it has local storage attached to it.
Now we know we have single point failure if SAN goes down My SQL Server 2node active passive cluster instance will also come down.
Now in this kind of event will my AG Listener can be online on WFC even if SAN is down so that it can redirect connection to the 3rd server where it has sync replica copy.
Also if in case Listener will not be able to be online in event of SAN failure what would alternative path we consider here
your valuable suggestion and time are most welcome.
Thank you very much..
Regards, Nirav JoshiThis will depend on your quorum configuration. If you started building your SQL Server failover clustered instance before adding your 3rd node, you may have a node a disk majority quorum. When the SAN fails, you take down the disk witness and the SQL Server
instance but since you still have 2 additional voting nodes, you still have a quorum so the Availability Group stays online. Unfortunately, because you have a combination of SQL Server Failover clustered instance and stand alone instance for your Availability
Group, you lose the ability to have automatic failover. So, even if there is a majority of votes in your cluster, you still have to manually failover the Availability Group and the listener name on the standalone instance running on the 3rd node.
Edwin Sarmiento SQL Server MVP | Microsoft Certified Master
Blog |
Twitter | LinkedIn
SQL Server High Availability and Disaster Recover Deep Dive Course -
SQL Servers White in SQL 2012 SP2 Management Studio Object Explorer
I had a similar issue before and thought I had resolved it but no, so....
I have a lot of servers on different versions registered in SQL2012 MS 2012 SP2 (tools only). They are all green and I have the option to stop/start in service control (I am an admin on all the servers). When I open Object Explorer most of the time they
are white and I don't have the stop/start options. I don't have this problem on any other version of MS - as soon as I double click on a registered server they go green - so why do I have this issue on 2012? Any ideas?Hello,
The state of a SQL Server Service is provided by WMI and you need permissions to fetch this Information. If the state is shown up with White circle, then because you don't have the permissions.
See MSDN: Configure WMI to Show Server Status in SQL Server Tools
Olaf Helper
[ Blog] [ Xing] [ MVP] -
SQL 2012 Central Management Server - can it manage itself?
I'm setting up a SQL Server 2012 lab on Windows 2008 R2 which has 5 SQL servers. I registered "SQL1" as my central management server and created a group under this server that includes all the servers and the CMS itself. I'm a bit confused since
the documentation says the CMS cannot be a member of a group it maintains. However, i'm able to include it in the group, run multiple queries and evaluate policies (at least i think i am).
reference: http://msdn.microsoft.com/en-us/library/bb895144.aspx see under "Related tasks"
I've seen other forum posts where users have issues registering the CMS itself but i don't have this problem at all. Has something changed?
Thanks,
PaulCan you confirm what version of SQL and SSMS you're running?
I'm running SQL Server 2012 Enterprise SP1 and SSMS 2012.
Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
Dec 28 2012 20:23:12
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
Here's the CMS returning queries for the whole group. -
Automatically create ODBC DSN connection with powershell or GPO
Hi,
I'm trying to create a ODBC connection that has a special network port and also password automatically stored.
I have tried to do this with the add-odbcdsn cmdlet and adding attributes to a group policy object configuration without luck.
If I try to export settings with regedit and import them trough logonscript, the normal users dont have user rights to the LOCAL Machine hive.
Therefore I have tried to export a USER DSN instead, but either of the port or password settings are exported.
Please help.Hello,
You can create a VB Script (.vbs) as the one create by Clamp77 on the following thread.
http://stackoverflow.com/questions/23552529/can-i-create-a-bat-file-to-automate-data-sources-adding-in-odbc-data-source-adm
Then you can run the script on computers using GPOs as explained on the following article.
http://technet.microsoft.com/en-us/library/dn789196.aspx
Hope this helps.
Regards,
Alberto Morillo
SQLCoffee.com -
[SQL 2012] split string with forbidden characters
Hi all,
I have an issue with a query
I would like to find an equivalent of pivot function, but with a column that contains forbidden characters (like []&) and using delimiter (,), and when number of value on column could be different :
colA colB colC
toto titi [valeur].[membre].&[test1],[valeur].[membre].&[test2],[valeur].[membre].&[test3]
tata tutu [valeur].[membre].&[test4],[valeur].[membre].&[test5]
fifi fafa [valeur].[membre].&[test6]
fofo fufu [valeur].[membre].&[test7],[valeur].[membre].&[test7],[valeur].[membre].&[test9]
what should give :
colA colB colC
toto titi [valeur].[membre].&[test1]
toto titi [valeur].[membre].&[test2]
toto titi [valeur].[membre].&[test3]
tata tutu [valeur].[membre].&[test4]
tata tutu [valeur].[membre].&[test5]
fifi fafa [valeur].[membre].&[test6]
fofo fufu [valeur].[membre].&[test7]
fofo fufu [valeur].[membre].&[test8]
fofo fufu [valeur].[membre].&[test9]
I try with splitstring function, xml path, but nothing works.
Thanks in advance.
XavierXavier,
check if this helps:
simple usage of a split function which can then be cross applied with the table.
--CREATE FUNCTION dbo.fn_sample_Split
-- @RowData nvarchar(2000),
-- @SplitOn nvarchar(5)
--RETURNS @RtnValue table
-- Id int identity(1,1),
-- Data nvarchar(100)
--AS
--BEGIN
-- Declare @Cnt int
-- Set @Cnt = 1
-- While (Charindex(@SplitOn,@RowData)>0)
-- Begin
-- Insert Into @RtnValue (data)
-- Select
-- Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
-- Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
-- Set @Cnt = @Cnt + 1
-- End
-- Insert Into @RtnValue (data)
-- Select Data = ltrim(rtrim(@RowData))
-- Return
--END
declare @tab table (cola varchar(20),colb varchar(20),colc varchar(100))
INSERT @tab SELECT 'toto','titi','[valeur].[membre].&[test1],[valeur].[membre].&[test2],[valeur].[membre].&[test3]'
INSERT @tab SELECT 'tata','tutu','[valeur].[membre].&[test4],[valeur].[membre].&[test5]'
INSERT @tab SELECT 'fifi','fafa','[valeur].[membre].&[test6]'
INSERT @tab SELECT 'fofo','fufu','[valeur].[membre].&[test7],[valeur].[membre].&[test7],[valeur].[membre].&[test9]'
select t.cola,t.colb,fn.data
From @tab t
cross apply dbo.fn_sample_split(t.colc,',') fn
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>
Maybe you are looking for
-
I was unable to open iTunes and got a message error 7 (windows 126) so I tried to uninstall and download latest itunes 10. When I tried to remove old version of itunes I got the message... The feature you are trying to remove is on a network resourc
-
Error message when trying to activate caller ID fo...
Hello. I keep getting an error message when trying to activate my caller ID for my mobile number. It keeps saying "We were unable to send you a confirmation code at this time. Please try again later. " I have checked the list of countries excluded fr
-
Please help me i don't know what to do and it's getting fustrating
-
Win 7 minimize and restore error
Hello, This error is somewhat similar to another just recently mentioned on this board here: http://forums.ni.com/t5/LabWindows-CVI/Window-Minimize-and-Restore-issue/td-p/3085541, but not quite the same. When running an application on Windows 7 creat
-
How do I get album artwork off my phone onto my PC?
I wiped my old PC and while I saved all my old MP3 files, I didn't think to save any of the old artwork. Of course, the files that Apple knows has the artwork but there are plenty that Apple doesn't recognize which I'd spent days gathering. I haven't