How can I switch from listening tentacles to polling tentacles in Octopus Deploy? - octopus-deploy

Setting up a cloud hybrid seems to be the way a lot of companies are going. A common configuration is Octopus Deploy is running on an on-premise VM. Octopus Deploy deploys to on-premise VMs as well as VMs running in Azure. The Octopus Deploy instance will be migrated to a VM running in Azure. This is part of our overall strategy of moving more of our on-premise VMs up to Azure.
Here is the kicker, the corporate firewall has been configured to only allow connections out to Azure. The on-premise VMs have no problem connecting to Azure. But Azure VMs cannot connect to the on-premise VMs. All of the on-premise VMs are using listening tentacles. Is it possible to switch over to polling tentacles. Can that be automated?

Once a tentacle instance is created the communication mode (listening or polling) cannot be changed. What you will need to do is create a new instance. This is one use case where the new Runbooks feature comes in handy.
Please note: This assumes you moved your Octopus Deploy instance to Azure already.
You will have two runbooks. The first runbook will:
Use the run a script step on the existing tentacle to create a new polling tentacle instance.
The second runbook will:
Use the run a script step on the new polling tentacle to disable the registration for the older listening tentacles.
Pause for manual intervention while you test some deployments to the new tentacle instances.
Use the run a script step on the new polling tentacle to delete the older listening tentacle instances.
First, let's use the script console to create polling tentacles. A couple of notes:
- When you register the new tentacles with Octopus Deploy, you will need to supply a name. I suggest you use something easy to remember. If your current listening tentacles are registered as [MachineName], then use [MachineName]-Polling.
- In addition to providing your deployment roles, also add "PollingTentacle" as a role that will make it easy for future runs with the script console.
$OldMachineName = $OctopusParameters["Octopus.Machine.Name"]
$Environment = $OctopusParameters["Octopus.Environment.Name"]
$Roles = $OctopusParameters["Octopus.Machine.Roles"]
$APIKey = #Your API Key
$Server = #Your Server
$NewMachineName = "$OldMachineName-Polling"
Set-Location "C:\Program Files\Octopus Deploy\Tentacle"
$baseArgs = #("register-with","--instance=Polling","--Name=$NewMachineName","--server=$Server","--apiKey=$octopusApiKey","--comms-style=TentacleActive","--server-comms-port=10943","--environment=$Environment")
$roleList = $roles -split ","
foreach ($role in $roleList) {
$baseArgs += "--role=$role"
}
$baseArgs += "--console"
& .\Tentacle.exe create-instance --instance "Polling" --config "C:\Octopus\Tentacle.config" --console
& .\Tentacle.exe new-certificate --instance "Polling" --if-blank --console
& .\Tentacle.exe configure --instance "Polling" --reset-trust --console
& .\Tentacle.exe configure --instance "Polling" --home "C:\Octopus\Polling" --app "C:\Octopus\Applications\Polling" --noListen "True" --console
& .\Tentacle.exe $baseArgs
& .\Tentacle.exe service --instance "Polling" --install --start --console
Next, using the API, disable the older machines. This is where having the role "PollingTentacles" and the machine registration set to [MachineName]-Polling makes it easy. This script will disable the older target.
###CONFIG###
$OctopusURL = #Octopus Server root URL
$APIKey = #Octopus API Key
$NewMachineName = $OctopusParameters["Octopus.Machine.Name"]
$machineName = $NewMachineName -replace "-Polling", ""
###PROCESS###
$header = #{ "X-Octopus-ApiKey" = $APIKey }
#Getting all machines
$allmachines = Invoke-RestMethod $OctopusURL/api/machines/all -Headers $header
#Filtering machine by name
$machine = $allmachines | ?{$_.name -eq $machineName}
#Setting the "IsDisabled" property
$machine.IsDisabled = $true #Set to $false to disable the machine
#Converting $machine into a JSON blob to PUT is back to the server
$body = $machine | ConvertTo-Json -Depth 4
#Pushing the modified machine to the userver
Invoke-RestMethod ($OctopusURL + $machine.Links.Self) -Method Put -Body $body -Headers $header
Now that the polling tentacles are running and the older tentacles as disabled, run some test deployments. Everything should continue to work as-is.
Finally, you will need to leverage the script console to deregister and delete the old tentacle.
cd "C:\Program Files\Octopus Deploy\Tentacle"
Tentacle.exe deregister-from --instance "Tentacle" --server "http://YOUR_OCTOPUS" --apiKey "API-YOUR_API_KEY" --multiple
Tentacle.exe delete-instance --instance "Tentacle"
For more information about the command line, please refer to our documentation.
If this puts you over your license limits, please reach out to support#octopus.com, explain what you are trying to do, and we will provide you with a temporary license.

Related

WebLogic in Docker: how to start managed servers automatically

I am learning Docker, and creating an image for Oracle WebLogic 12.2.1.4 server.
My image is ready, working fine. It contains
an admin server
two managed servers
When I run my image with docker run -d -p 7001:7001 --name WL oracle/weblogic-12.2.1.4.0:1.0 the admin server starts automatically because I added the following line at the end of my Dockerfile:
CMD /u01/oracle/user_projects/domains/$DOMAIN_NAME/startWebLogic.sh
But I need to start managed servers manually. I need to login into the container and start them by hand:
docker exec -it WL /bin/bash
./startManagedWebLogic.sh MANAGED_SERVER_1 http://localhost:7001 &
./startManagedWebLogic.sh MANAGED_SERVER_2 http://localhost:7001 &
This is not what I want. I want to start managed servers automatically after admin server is up and running.
I was thinking about to create a new bash script, copy it into the image and use it to boot up the admin and managed servers. Like this:
start-wls-domain.sh
#!/bin/bash
/u01/oracle/user_projects/domains/$DOMAIN_NAME/startWebLogic.sh &
# there are a more sophisticated way to check the status of the admin server but it is okay for test
sleep 60
./startManagedWebLogic.sh MANAGED_SERVER_1 http://localhost:7001 &
./startManagedWebLogic.sh MANAGED_SERVER_2 http://localhost:7001 &
This script can be called from Dockerfile with CMD command.
But with this solution, I lost the ability to see the output on the default Docker log. The docker logs WL -f will display nothing.
Another issue with this bash script solution is if this script finished the container will stop running. Do I need an infinite loop at the end of this script?
If possible I would like to have a solution without start-wls-domain.sh.
What is the best and easiest way to start Weblogic managed servers automatically within a Docker container?
I followed the suggestions and I run different servers in different containers. That way I was able to start properly the server.
I published the solution on Github, here.

Jenkins: Deploying & updating java (& others) on Windows

I'd like to use Jenkins to deploy/update programs on a remote windows server (not always the same version). By "programs", I mean java, tomcat, ActiveMQ and some server executables (.exe).
To update some of those, I would need to stop the associated service, deploy the updated executable & restart the service (like tomcat). Some others would just need to be installed on the remote machine without prompt (like updating java from version 8 to 9).
The problem is I'm not sure how to configure Jenkins to do these jobs on remote windows environnement, and I'm not sure what would be the best way of doing it.
Jenkins has the ability to run Powershell - which is one of the most straightforward ways to make changes in Windows. You can use the Start-Service or Stop-Service cmdlets for service management.
For script-based installation, my go-to is Chocolatey, which allows you to install almost anything.
For example, once installed, you can use this simple command to install Java:
choco install jdk8
Just as #sharpslinger said Powershell is the right tool for the job. I would go for Powershell DSC. Useful DSC resources in your case:
For starting / stopping service use Service resource:
Service ServicesStop
{
Name = "TheTestService"
State = "Stopped"
}
To deploy your executable you can use File resource:
File CopyMyExe
{
Ensure = "Present"
Type = "File"
SourcePath = "MySource.jar"
DestinationPath = "MyDestination.jar"
}
To install java silently you can use Script resource. Source of example below: link.
# This allows the reboot
LocalConfigurationManager
{
RebootNodeIfNeeded = $true
}
Script Java
{
GetScript = { return #{} }
TestScript = { return Test-Path 'HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment' }
SetScript = {
$installer = "jre-8u144-windows-x64.exe"
Start-Process $installer -ArgumentList '/s' -Wait
# signal reboot
$global:DSCMachineStatus = 1
}
}
Jenkins' job will be to simply call Powershell script that deploys your application.

How to launch Jenkins slave programmatically without manual login to Slave machine

We are using windows R2 2012 64bit servers. In future we will be having many machines where we would be running our jenkins slaves.
We want to automate the jenkins slave launching process.
I have gone through link by jenkins but did not got much help from it.
I also wonder that how to install same set of tools from master to all slave machines.
I did googling but did not found any article on this topic.
What I do to add a Windows slave is to use a script which:
set the right environment variables like JAVA_HOME,
launch the right java -jar slave.jar with the secret key you can see in the Jenkins master node page for that new slave.
To get slave.jar from the master onto the slave, execute from the slave Windows server:
curl -o slave.jar https://your.server/jenkins/jnlpJars/slave.jar
use nssm to declare that script as a Windows service
The script is similar to agent.bat:
set PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0
set PATH=D:\Tools\SonarRunner\bin;%PATH%
set M2_HOME=D:\Tools\apache-maven-3.5.0
set PATH=%M2_HOME%\bin;%PATH%
set PATH=D:\Tools\apache-ant-1.9.3\bin;%PATH%
set GH=D:\Tools\Git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
set PATH=%JAVA_HOME%\bin;%PATH%
set WORKSPACE_FOLDER=D:\Jenkins\workspace
set GIT_WORKSPACE_FOLDER=D:\Jenkins\workspace
java -Xmx768m -jar slave.jar -jnlpUrl https://your.server/jenkins/computer/<SlaveName>/slave-agent.jnlp -secret 87ef3d...
That script is then called as a Windows service, ran by a dedicated user account:
runas /user:<domain>\<jenkinsUser> cmd ( enter `jenkinsUser` Windows password )
D:\Tools\nssm-2.24\win64\nssm.exe install <SlaveName> D:\Jenkins\agent.bat
Its Windows service is then configured:
sc config <SlaveName> obj= <domain>\<jenkinsUsers> password= <jenkinsUser password>
sc config <SlaveName> start= auto
For automating the installation of other software: see Chocolatey - Software Management Automation, The package manager for Windows.
To fully automate the declaration-side of slaves, use the web API to create the slave, and a groovy script to retrieve the Jenkins node/slave secret JnlpMac key.
See this script for the creation.
And the groovy script (with Jenkins 2.46 or newer) to get the secret key:
echo 'println jenkins.model.Jenkins.instance.nodesObject.getNode("my-agent")?.computer?.jnlpMac' \
| java -jar ~/Downloads/jenkins-cli.jar -s https://jenkins/ groovy =

Enabling mounted EBS volumes at startup in Amazon EC2 on Windows

I'm trying to bring a drive online automatically on startup in Windows on EC2, the device is present in the Disk Management app, just offline.
I'm using a custom AMI built using Packer and would like to have it do this when the AMI is launched into an instance.
My current thinking is to create a scheduled job in Powershell triggered on startup, however this job never runs and I can't work out why.
$script = {Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False}
$trigger = New-JobTrigger -AtStartup
Register-ScheduledJob -Name 'Mount EBS Drives' -ScriptBlock $script -Trigger $trigger
What am I doing wrong with this script and/or is there another way to achieve my goal?
If these instances are being launched by an Auto-Scaling Group, you can define a block of UserData in the Launch Configuration that can contain PowerShell script that runs on first boot. It can be made to run on each boot with a bit of tweaking.
Look under "Executing Scripts with User Data" in this AWS document: http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html
Regrettably, I am still learning this, and found your question in the course of my research. It looks like this question is actually about Scheduled Tasks and this is not reflected in the tags.

bluemix service creation timing out in DevOps Services

With Bluemix DevOps Services I want a deploy script that will always create a new service instance (for example I am deploying to QA stack).
My deploy script looks something like this:
echo "Deleting app ${CF_APP}"
cf delete "${CF_APP}" -f -r
if cf services | grep "Insights for Twitter-test" -q
then
echo "Twitter Service found, deleting in order to create a new one."
cf delete-service "Insights for Twitter-test" -f
else
echo "Twitter Service doesn't exist yet, will create new one."
fi
echo "Creating new service instance for Twitter"
cf create-service twitterinsights Free "Insights for Twitter-test"
echo "Pushing app ${CF_APP}"
cf push "${CF_APP}"
Everytime I run it, the service creation part times out:
Server error, status code: 504, error code: 10001, message: Service instance Insights for Twitter-test: The request to the service broker timed out: https://provision-broker.ng.bluemix.net/bmx/provisioning/brokers/832dfb83-50e9-42b5-9516-ac54ab1eeaf4/v2/service_instances/c3a42482-398c-4148-bacb-297c1f6670ef?accepts_incomplete=true&plan_id=a888c333-41b6-4384-97d1-f89d11d48be9&service_id=4176989f-0bf7-4cf2-987a-6a57320744d1
If I manually run this script with the CF CLI it works fine. Only in DevOps Services does the service creation time out.
For the moment I am not concerned with the fact that the Twitter service doesn't have any state, and that I might as well leave it. Imagine a database service instead, that I want to ensure has been create anew.
Any and all help is appreciated.

Resources