Creating a simple Debian installer (for Opencensus)

  • creates a debian .deb installer for OpenCensus Agent
  • creates a package distribution site (i.,e apt-repository; kinda like the professionals!)

References

Creating a .deb file

  • package the opencensus agent. The agent is already provided as a platform binary so this article does not compile from source
  • create user/group that the agent will run as oc-agent/oc-agent.
  • install the agent and cofig file under /opt/opencensus-agent/*
  • install and configure systemd such that you can start/stop the agent easily.
  1. Setup some libraries we will need later
apt-get update
apt-get install debhelper dh-systemd dh-make reprepro gnupg2 vim wget nginx lsb-release -y
gpg --import stage/certs/oc_private.key   gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 0C74009E141D7911: public key "OpenCensus (https://opencensus.io) <census-developers@googlegroups.com>" imported
gpg: key 0C74009E141D7911: secret key imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: secret keys read: 1
gpg: secret keys imported: 1
gpg --import stage/certs/oc_public.key
gpg: key 0C74009E141D7911: "OpenCensus (https://opencensus.io) <census-developers@googlegroups.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
  • pick sign only (option 4);
  • Username: Opencensus
  • email: census-developers@googlegroups.com
  • pick any password
gpg --keyid-format SHORT --list-keys
pub rsa4096/141D7911 2019-03-01 [SC]
9A70363996C3EE279ABBAF2E0C74009E141D7911
uid [ unknown] OpenCensus (https://opencensus.io) <census-developers@googlegroups.com>
mkdir opencensusagent-0.1.2/
cd opencensusagent-0.1.2/
export USER=`whoami`
dh_make  --createorig -e census-developers@googlegroups.com -s -y
cp -R ../stage/debian/* debian/
  • debian/control: describes what this repo does
  • debian/compat
  • debian/files
  • debain/opencensusagent-install: where to copy the installer files (in our case from debian/src/opt/opencensus-agent/* to /opt/)
  • debian/opencensusagent.service: systemd configuration
  • debian/preinst: preinstallation tasks to setup the user/group, etc
  • debian/postinst: post installation tasks
  • debian/postrm: remove the user/group and directories after the package is removed
  • debian/rules: this is an important file: this describes that we will install systemd and any overrides to systemd or installation to apply.
  • debian/source/include-binaries: the target binaries we need to package up (in our case, the opencensus binary and its config file)
  • debian/src/opt/opencensus-agent/bin/ocagent
  • debian/src/opt/opencensus-agent/conf/oca.yaml
wget https://github.com/census-instrumentation/opencensus-service/releases/download/0.1.3/ocagent_linux \
-O debian/src/opt/opencensus-agent/bin/ocagent
dpkg-buildpackage -kcensus-developers@googlegroups.com
cd  ../
gcloud compute instances create oc-client1 --zone=us-central1-a
gcloud compute scp opencensusagent_0.1.2-1_all.deb oc-client1:/tmp/
gcloud compute ssh oc-client1
gcloud compute ssh oc-client1 --zone=us-central1-a
sudo su -
cd /tmp/
dpkg -i opencensusagent_0.1.2-1_all.deb
Selecting previously unselected package opencensusagent.
(Reading database ... 34432 files and directories currently installed.)
Preparing to unpack opencensusagent_0.1.2-1_all.deb ...
Adding system user `ocagent' (UID 108) ...
Adding new group `ocagent' (GID 112) ...
Adding new user `ocagent' (UID 108) with group `ocagent' ...
Not creating home directory `/home/ocagent'.
Unpacking opencensusagent (0.1.2-1) ...
Setting up opencensusagent (0.1.2-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/opencensusagent.service → /lib/systemd/system/opencensusagent.service.
Processing triggers for systemd (232-25+deb9u8) ...
$ service opencensusagent start$ service opencensusagent status
● opencensusagent.service - Opencensus Agent
Loaded: loaded (/lib/systemd/system/opencensusagent.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-03-06 01:30:37 UTC; 1s ago
Main PID: 894 (ocagent)
Tasks: 7 (limit: 4915)
CGroup: /system.slice/opencensusagent.service
└─894 /opt/opencensus-agent/bin/ocagent -c /opt/opencensus-agent/conf/oca.yaml
Mar 06 01:30:37 oc-client1 systemd[1]: Started Opencensus Agent.
Mar 06 01:30:38 oc-client1 opencensusagent[894]: 2019/03/06 01:30:38 Running OpenCensus Trace and Metrics receivers as a gRPC service at "localhost:55678"
Mar 06 01:30:38 oc-client1 opencensusagent[894]: 2019/03/06 01:30:38 Running zPages at ":55679"
$ ps -ef | grep ocagent
root 18473 1 0 01:01 pts/0 00:00:00 /opt/opencensus-agent/bin/ocagent -c /opt/opencensus-agent/conf/oca.yaml
root 18782 1 0 01:03 pts/0 00:00:00 grep ocagent
$ service opencensusagent stop
[ ok ] Stopping opencensusagent:.
$ dpkg -r opencensusagent
$ dpkg -P opencensusagent

Create APT Repository

mkdir repo && cd repo/
cp ../opencensusagent_0.1.2-1_all.deb .
Origin: OpenCensus (https://opencensus.io/)
Label: OpenCensus
Codename: stretch
Architectures: amd64
Components: main
Description: OpenCensus Package Repo
SignWith: 0838A470
Pull: stretch
Origin: OpenCensus (https://opencensus.io/)
Label: OpenCensus
Codename: trusty
Architectures: amd64
Components: main
Description: OpenCensus Package Repo
SignWith: 0838A470
Pull: trusty
$ reprepro  -Vb . includedeb stretch opencensusagent_0.1.2-1_all.deb  opencensusagent_0.1.2_all.deb: component guessed as 'main'
Created directory "./pool"
Created directory "./pool/main"
Created directory "./pool/main/o"
Created directory "./pool/main/o/opencensusagent"
Exporting indices...
Created directory "./dists"
Created directory "./dists/stretch"
Created directory "./dists/stretch/main"
Created directory "./dists/stretch/main/binary-amd64"
Successfully created './dists/stretch/Release.gpg.new'
Successfully created './dists/stretch/InRelease.new'
rm opencensusagent_0.1.2-1_all.deb
cd ../
tar cvf repo.tar
  • Create ssl cert for the https distribution
openssl req  -nodes -new -x509  -keyout server.key -out server.cert
gcloud compute instances create repo --zone=us-central1-a
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
repo us-central1-a n1-standard-1 10.128.0.48 35.202.237.155 RUNNING
gcloud compute scp repo.tar repo:/tmp/ --zone=us-central1-a
gcloud compute scp server* repo:/tmp/ --zone=us-central1-a
gcloud compute scp stage/certs/oc_public.key repo:/tmp/ --zone=us-central1-a
gcloud compute ssh repo
sudo su -
apt-get update
apt-get install nginx -y
  • Copy certs over:
cp /tmp/server.key /etc/nginx/
cp /tmp/server.cert /etc/nginx/
  • configure nginx
vi /etc/nginx/sites-enabled/defaultserver {
listen 443 ssl;
listen [::]:443 ssl;
server_name example2.com www.example2.com;
root /var/www/html;
ssl_certificate /etc/nginx/server.cert;
ssl_certificate_key /etc/nginx/server.key;
}
  • copy public key and certificate to the docroot
cd /var/www/html
cp /tmp/oc_public.key .
cp /tmp/repo.tar .
tar xvf repo.tar
service nginx restart

End-to-End Test

  • setup some background libraries;tools
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common vim
  • Download and allow apt to trust our public key
curl -fsSLk https://10.128.0.48/oc_public.key | apt-key add -

OK
apt-key fingerprint 141D7911
pub rsa4096 2019-03-01 [SC]
9A70 3639 96C3 EE27 9ABB AF2E 0C74 009E 141D 7911
uid [ unknown] OpenCensus (https://opencensus.io) <census-developers@googlegroups.com>
  • Install the repo
add-apt-repository "deb http://10.128.0.48/repo $(lsb_release -cs) main"
apt-get update
  • Install the package!
apt-get install opencensusagent
  • Verify
service opencensusagent startservice opencensusagent status
● opencensusagent.service - Opencensus Agent
Loaded: loaded (/lib/systemd/system/opencensusagent.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-03-06 01:52:52 UTC; 33s ago
Main PID: 27922 (ocagent)
Tasks: 8 (limit: 4915)
CGroup: /system.slice/opencensusagent.service
└─27922 /opt/opencensus-agent/bin/ocagent -c /opt/opencensus-agent/conf/oca.yaml
Mar 06 01:52:52 oc-client1 systemd[1]: Started Opencensus Agent.
Mar 06 01:52:53 oc-client1 opencensusagent[27922]: 2019/03/06 01:52:53 Running OpenCensus Trace and Metrics receivers as a gRPC service at "localhost:55678"
Mar 06 01:52:53 oc-client1 opencensusagent[27922]: 2019/03/06 01:52:53 Running zPages at ":55679"
  • Uninstall
apt-get remove opencensusagent
apt-get purge opencensusagent

Done

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Improving web performance with responsive design

Notifications, the whole shebang II

MDS Newsletter #17

I have used only 3 out of these 14 CI/CD tools

Fix DNS_PROBE_FINISHED_NXDOMAIN in chrome

Fast Data Store for Pandas Time-Series Data using PyStore

From Application Developer to Big Data Engineer

WordPress v4.8 and All-in-One WP Migration v6.48

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
salmaan rashid

salmaan rashid

More from Medium

Useful Linux Commands for Developers

Installing Debian (64-bits) on Raspberry Pi 4

Mount Storage Volumes onto Linux Operating Systems

Upgrade cURL on Ubuntu Server