Skip to content

Commit fde12a7

Browse files
Added msi packaging & standardised naming (open-telemetry#3)
2 parents bf04e2b + 56938cb commit fde12a7

8 files changed

+132
-15
lines changed

.build/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package-googet: build pack-googet
2121

2222
.PHONY: build
2323
build:
24-
GOOS=windows go build -o ./bin/otelopscol_windows_$(GOARCH).exe ./cmd/otelopscol
24+
GOOS=windows go build -o ./bin/google-cloudops-opentelemetry-collector_windows_$(GOARCH).exe ./cmd/otelopscol
2525

2626
.PHONY: pack-googet
2727
pack-googet: SHELL:=/bin/bash

cmd/otelopscol/main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
package main
1616

1717
import (
18+
"fmt"
1819
"log"
1920

20-
"github.com/pkg/errors"
2121
"go.opentelemetry.io/collector/service"
2222

2323
"github.com/GoogleCloudPlatform/opentelemetry-operations-collector/internal/version"
@@ -30,7 +30,7 @@ func main() {
3030
}
3131

3232
info := service.ApplicationStartInfo{
33-
ExeName: "otelcol",
33+
ExeName: "google-cloudops-opentelemetry-collector",
3434
LongName: "OpenTelemetry Cloud Operations Collector",
3535
Version: version.Version,
3636
GitHash: version.GitHash,
@@ -46,12 +46,12 @@ func main() {
4646
func runInteractive(params service.Parameters) error {
4747
app, err := service.New(params)
4848
if err != nil {
49-
return errors.Wrap(err, "failed to construct the application")
49+
return fmt.Errorf("failed to construct the application: %w", err)
5050
}
5151

5252
err = app.Start()
5353
if err != nil {
54-
return errors.Wrap(err, "application run finished with error: %v")
54+
return fmt.Errorf("application run finished with error: %w", err)
5555
}
5656

5757
return nil

cmd/otelopscol/main_windows.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
package main
1818

1919
import (
20-
"github.com/pkg/errors"
20+
"fmt"
21+
2122
"go.opentelemetry.io/collector/service"
2223
"golang.org/x/sys/windows/svc"
2324
)
2425

2526
func run(params service.Parameters) error {
2627
isInteractive, err := svc.IsAnInteractiveSession()
2728
if err != nil {
28-
return errors.Wrap(err, "failed to determine if we are running in an interactive session")
29+
return fmt.Errorf("failed to determine if we are running in an interactive session: %w", err)
2930
}
3031

3132
if isInteractive {
@@ -38,7 +39,7 @@ func run(params service.Parameters) error {
3839
func runService(params service.Parameters) error {
3940
// do not need to supply service name when startup is invoked through Service Control Manager directly
4041
if err := svc.Run("", service.NewWindowsService(params)); err != nil {
41-
return errors.Wrap(err, "failed to start service")
42+
return fmt.Errorf("failed to start service: %w", err)
4243
}
4344

4445
return nil

packaging/googet/google-cloudops-opentelemetry-collector.goospec

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "http://www.apache.org/licenses/LICENSE-2.0",
77
"description": "Google Cloud Operations OpenTelemetry Collector based Monitoring Agent",
88
"files": {
9-
"bin/otelopscol_windows_${GOARCH}.exe": "<ProgramFiles>/Google/Cloud Operations/OpenTelemetry Collector/google-cloudops-opentelemetry-collector.exe",
9+
"bin/google-cloudops-opentelemetry-collector_windows_${GOARCH}.exe": "<ProgramFiles>/Google/Cloud Operations/OpenTelemetry Collector/google-cloudops-opentelemetry-collector.exe",
1010
"config.yaml": "<ProgramFiles>/Google/Cloud Operations/OpenTelemetry Collector/config.yaml"
1111
},
1212
"install": {
@@ -17,7 +17,7 @@
1717
},
1818
"sources": [{
1919
"include": [
20-
"./bin/otelopscol_windows_${GOARCH}.exe",
20+
"./bin/google-cloudops-opentelemetry-collector_windows_${GOARCH}.exe",
2121
"./config.yaml",
2222
"./packaging/googet/install.ps1",
2323
"./packaging/googet/uninstall.ps1"

packaging/googet/install.ps1

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ function Set-ServiceConfig {
2424
sc.exe triggerinfo google-cloudops-opentelemetry-collector start/networkon
2525
}
2626

27+
$InstallDir = "%ProgramFiles%\Google\Cloud Operations\OpenTelemetry Collector"
28+
2729
try
2830
{
29-
if (-not (Get-Service 'google-cloudops-opentelemetry-collector' -ErrorAction SilentlyContinue))
31+
if (-not (Get-Service "google-cloudops-opentelemetry-collector" -ErrorAction SilentlyContinue))
3032
{
31-
New-Service -DisplayName 'Google Cloud Operations OpenTelemetry Collector' `
32-
-Name 'google-cloudops-opentelemetry-collector' `
33-
-BinaryPathName '%ProgramFiles%\Google\Cloud Operations\OpenTelemetry Collector\opentelemetry-collector.exe --config="C:\Users\jbebb\go\src\go.opentelemetry.io\collector\examples\otel-local-config.yaml"' `
33+
New-Service -DisplayName "Google Cloud Operations OpenTelemetry Collector" `
34+
-Name "google-cloudops-opentelemetry-collector" `
35+
-BinaryPathName "$InstallDir\google-cloudops-opentelemetry-collector.exe --config=""$InstallDir\config.yaml""" `
3436
-StartupType AutomaticDelayedStart `
35-
-Description 'Google Cloud Operations OpenTelemetry Collector based Monitoring Agent'
37+
-Description "Google Cloud Operations OpenTelemetry Collector based Monitoring Agent"
3638

3739
Set-ServiceConfig
3840
Start-Service 'google-cloudops-opentelemetry-collector' -Verbose -ErrorAction Stop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
2+
<Product Id="*" UpgradeCode="2B747F3C-BA1A-47DB-8617-E6BE77832F7E" Name="Google Cloud Operations OpenTelemetry Collector" Version="$(var.Version)" Manufacturer="OpenTelemetry" Language="1033">
3+
<Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/>
4+
<Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
5+
<Icon Id="ProductIcon" SourceFile="./packaging/msi/opentelemetry.ico"/>
6+
<Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
7+
<Property Id="ARPHELPLINK" Value="https://cloud.google.com/monitoring/agent"/>
8+
<Property Id="ARPURLINFOABOUT" Value="https://cloud.google.com/monitoring/agent"/>
9+
<Property Id="ARPNOREPAIR" Value="1"/>
10+
<Property Id="ARPNOMODIFY" Value="1"/>
11+
12+
<Feature Id="Feature" Level="1">
13+
<ComponentRef Id="ApplicationComponent"/>
14+
</Feature>
15+
16+
<Directory Id="TARGETDIR" Name="SourceDir">
17+
<Directory Id="ProgramFiles64Folder">
18+
<Directory Id="INSTALLDIR" Name="Google\Cloud Operations\OpenTelemetry Collector">
19+
<Component Id="ApplicationComponent" Guid="03F8DA4A-B41A-4AC1-8B18-5E3AF5D7A548">
20+
<File Id="ExecutableFile" Name="google-cloudops-opentelemetry-collector.exe" KeyPath="yes" Source="./bin/otelopscol_windows_amd64.exe"/>
21+
<File Id="ConfigFile" Name="config.yaml" Source="$(var.Config)" />
22+
23+
<ServiceInstall
24+
Id="Sevice"
25+
Name="google-cloudops-opentelemetry-collector"
26+
DisplayName="Cloud Operations OpenTelemetry Collector"
27+
Description="Google Cloud Operations OpenTelemetry Collector based Monitoring Agent"
28+
Type="ownProcess"
29+
Vital="yes"
30+
Start="auto"
31+
Account="LocalSystem"
32+
ErrorControl="normal"
33+
Arguments=" --config=&quot;[INSTALLDIR]config.yaml&quot;"
34+
Interactive="no" />
35+
<ServiceControl
36+
Id="StartStopRemoveService"
37+
Name="google-cloudops-opentelemetry-collector"
38+
Start="install"
39+
Stop="both"
40+
Remove="uninstall"
41+
Wait="yes" />
42+
</Component>
43+
</Directory>
44+
</Directory>
45+
</Directory>
46+
</Product>
47+
</Wix>

packaging/msi/make.ps1

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2020, Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
<#
16+
.SYNOPSIS
17+
Makefile like build commands for the Operations Collector on Windows.
18+
19+
Usage: .\make.ps1 <Command> [-<Param> <Value> ...]
20+
Example: .\make.ps1 New-MSI -Config "./config.yaml"
21+
.PARAMETER Target
22+
Build target to run (Install-Tools, New-MSI, Confirm-MSI)
23+
#>
24+
Param(
25+
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)][string]$Target
26+
)
27+
28+
$ErrorActionPreference = "Stop"
29+
30+
function Install-Tools {
31+
choco install wixtoolset -y
32+
setx /m PATH "%PATH%;C:\Program Files (x86)\WiX Toolset v3.11\bin"
33+
refreshenv
34+
}
35+
36+
function New-MSI(
37+
[string]$Version="0.0.0",
38+
[string]$Config="./config.yml"
39+
) {
40+
candle -arch x64 -dVersion="$Version" -dConfig="$Config" packaging/msi/google-cloudops-opentelemetry-collector.wxs
41+
light google-cloudops-opentelemetry-collector.wixobj
42+
Move-Item -Force google-cloudops-opentelemetry-collector.msi bin/google-cloudops-opentelemetry-collector.msi
43+
}
44+
45+
function Confirm-MSI {
46+
# ensure system32 is in Path so we can use executables like msiexec & sc
47+
$env:Path += ";C:\Windows\System32"
48+
49+
# install msi, validate service is installed & running
50+
Start-Process -Wait msiexec "/i `"$pwd\bin\google-cloudops-opentelemetry-collector.msi`" /qn"
51+
sc.exe query state=all | findstr "google-cloudops-opentelemetry-collector" | Out-Null
52+
if ($LASTEXITCODE -ne 0) { Throw "google-cloudops-opentelemetry-collector service failed to install" }
53+
54+
# stop service
55+
Stop-Service google-cloudops-opentelemetry-collector
56+
57+
# start service
58+
Start-Service google-cloudops-opentelemetry-collector
59+
60+
# uninstall msi, validate service is uninstalled
61+
Start-Process -Wait msiexec "/x `"$pwd\bin\opentelemetry-contrib-collector.msi`" /qn"
62+
sc.exe query state=all | findstr "google-cloudops-opentelemetry-collector" | Out-Null
63+
if ($LASTEXITCODE -ne 1) { Throw "google-cloudops-opentelemetry-collector service failed to uninstall" }
64+
}
65+
66+
$sb = [scriptblock]::create("$Target")
67+
Invoke-Command -ScriptBlock $sb

packaging/msi/opentelemetry.ico

269 KB
Binary file not shown.

0 commit comments

Comments
 (0)