Browse code

consul : New Package

Added new package consul and corresponding service file to initiate the consul agent for dev branch.

Change-Id: I700b6e96bdf658986900bb5abdad1a70bfd5cb88
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5298
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Sharath George

Ankit Jain authored on 2018/06/26 06:17:18
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,16 @@
0
+[Unit]
1
+Description=Consul Agent
2
+Requires=network.target
3
+After=network.target
4
+
5
+[Service]
6
+ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d -dev -advertise 127.0.0.1
7
+ExecReload=/usr/bin/kill -HUP $MAINPID
8
+KillSignal=SIGINT
9
+User=consul
10
+Group=consul
11
+Restart=on-failure
12
+LimitNOFILE=131072
13
+
14
+[Install]
15
+WantedBy=multi-user.target
0 16
new file mode 100644
... ...
@@ -0,0 +1,105 @@
0
+Summary:        Consul is a tool for service discovery and configuration.
1
+Name:           consul
2
+Version:        1.1.0
3
+Release:        1%{?dist}
4
+License:        Mozilla Public License, version 2.0
5
+Group:          System Environment/Daemons
6
+Vendor:         VMware, Inc.
7
+Distribution:   Photon
8
+URL:		https://github.com/hashicorp/consul/archive/v%{version}.tar.gz
9
+Source0:	%{name}-%{version}.tar.gz
10
+%define sha1 %{name}-%{version}.tar.gz=e3a4f1047acb7c831bf772c3d26c4d5c0778df69
11
+Source1:        %{name}.service
12
+BuildRequires:  unzip
13
+BuildRequires:  systemd
14
+BuildRequires:  go
15
+Requires:       systemd
16
+
17
+%description
18
+Consul is a tool for service discovery and configuration. Consul is distributed, highly available, and extremely scalable.
19
+
20
+Consul provides several key features:
21
+ - Service Discovery - Consul makes it simple for services to register themselves and to discover other services via a DNS or HTTP interface. External services such as SaaS providers can be registered as well.
22
+ - Health Checking - Health Checking enables Consul to quickly alert operators about any issues in a cluster. The integration with service discovery prevents routing traffic to unhealthy hosts and enables service level circuit breakers.
23
+ - Key/Value Storage - A flexible key/value store enables storing dynamic configuration, feature flagging, coordination, leader election and more. The simple HTTP API makes it easy to use anywhere.
24
+ - Multi-Datacenter - Consul is built to be datacenter aware, and can support any number of regions without complex configuration.
25
+
26
+%global debug_package %{nil}
27
+
28
+%prep
29
+%setup -q
30
+
31
+%build
32
+export LANG=en_US.UTF-8
33
+export LC_ALL=en_US.UTF-8
34
+export PKG=github.com/hashicorp/%{name}
35
+export GOPATH=/usr/share/gocode
36
+export GOROOT=/usr/lib/golang
37
+export GOHOSTOS=linux
38
+export CGO_ENABLED=0
39
+export GOOS=linux
40
+export VERSION=%{version}
41
+mkdir -p ${GOPATH}/src/${PKG}
42
+cp -r * ${GOPATH}/src/${PKG}/.
43
+pushd ${GOPATH}/src/${PKG}
44
+mkdir -p %{name}_bin
45
+CGO_ENABLED=0 GOOS=linux go build -v -o %{name}_bin/%{name} -ldflags "-X main.VERSION=%{version} -s -w" *.go
46
+
47
+%install
48
+export PKG=github.com/hashicorp/%{name}
49
+pushd ${GOPATH}/src/${PKG}
50
+install -vdm 755 %{buildroot}%{_bindir}
51
+install ${GOPATH}/src/${PKG}/%{name}_bin/%{name} %{buildroot}%{_bindir}
52
+install -vdm 755 %{buildroot}%{_sysconfdir}/%{name}.d
53
+install -vdm 755 %{buildroot}/usr/lib/systemd/system
54
+
55
+chown -R root:root %{buildroot}%{_bindir}
56
+
57
+install -vdm 755 %{buildroot}/usr/lib/systemd/system
58
+install -p -m 0644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/
59
+
60
+install -vdm 755 %{buildroot}/var/lib/%{name}
61
+
62
+%pre
63
+if ! getent group %{name} >/dev/null; then
64
+    groupadd %{name}
65
+fi
66
+if ! getent passwd %{name} >/dev/null; then
67
+    useradd -c "Consul Agent" -d /var/lib/%{name} -g %{name} -s /bin/false %{name}
68
+fi
69
+exit 0
70
+
71
+%post
72
+/sbin/ldconfig
73
+%systemd_post %{name}.service
74
+
75
+%postun
76
+if [ $1 -eq 0 ]; then
77
+  # this is delete operation
78
+  if getent passwd %{name} >/dev/null; then
79
+      userdel %{name}
80
+  fi
81
+  if getent group %{name} >/dev/null; then
82
+      groupdel %{name}
83
+  fi
84
+fi
85
+/sbin/ldconfig
86
+%systemd_postun_with_restart %{name}.service
87
+
88
+%preun
89
+/sbin/ldconfig
90
+%systemd_preun %{name}.service
91
+
92
+%clean
93
+rm -rf %{buildroot}
94
+
95
+%files
96
+%defattr(-,%{name},%{name})
97
+%{_bindir}/%{name}
98
+/usr/lib/systemd/system/%{name}.service
99
+%dir /var/lib/%{name}
100
+%dir %{_sysconfdir}/%{name}.d
101
+
102
+%changelog
103
+*       Thu Jun 28 2018 Ankit Jain <ankitja@vmware.com> 1.1.0-1
104
+-       Initial build.  First version