diff --git a/.gitignore b/.gitignore index 8805dee0..231cbeb8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ src/vendor src/caduceus/caduceus src/caduceus/debug src/caduceus/output +caduceus.spec # config src/caduceus/caduceus.json diff --git a/.travis.yml b/.travis.yml index 5c79321c..8cb77453 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ branches: - master before_install: - - docker pull schmidtw/webpa.builder.centos6:latest - - docker run -it -e BUILD_NUMBER=$TRAVIS_BUILD_NUMBER -d --name build schmidtw/webpa.builder.centos6 bash + - docker pull schmidtw/xmidt.builder.centos7:latest + - docker run -it -e BUILD_NUMBER=$TRAVIS_BUILD_NUMBER -d --name build schmidtw/xmidt.builder.centos7 bash - env - docker exec build rpm -q golang - docker exec build go version diff --git a/ChangeLog b/ChangeLog index fddb8d11..7fab64f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,2 +1,4 @@ +* Sun Nov 12 2017 Weston Schmidt - 0.1.1 +- update to support centos 7 / systemd * Tue Mar 28 2017 Weston Schmidt - 0.1.1 - initial creation diff --git a/build_rpm.sh b/build_rpm.sh index 56addbed..3bd19515 100755 --- a/build_rpm.sh +++ b/build_rpm.sh @@ -2,6 +2,41 @@ NAME=caduceus +RPM_BUILD_ROOT=/root +SIGN=1 + + +usage() +{ + echo "usage: build_rpm.sh [--rpm-build-root path] [--no-sign]" + echo " --rpm-build-root - the path where /rpmbuild exists for your user" + echo " --no-sign - don't try to sign the build" +} + +while [ "$1" != "" ]; do + case $1 in + --rpm-build-root ) shift + RPM_BUILD_ROOT=$1 + ;; + + --no-sign ) SIGN=0 + ;; + + --build-number ) shift + BUILD_NUMBER=$1 + ;; + + -h | --help ) usage + exit + ;; + + * ) usage + exit 1 + + esac + shift +done + echo "Adjusting build number..." taglist=`git tag -l` @@ -26,22 +61,30 @@ echo "Building the ${NAME} rpm..." pushd .. cp -r ${NAME} ${NAME}-$release tar -czvf ${NAME}-$new_release.tar.gz ${NAME}-$release -mv ${NAME}-$new_release.tar.gz /root/rpmbuild/SOURCES +mv ${NAME}-$new_release.tar.gz ${RPM_BUILD_ROOT}/rpmbuild/SOURCES rm -rf ${NAME}-$release popd # Merge the changelog into the spec file so we're consistent +cat ${NAME}.spec.in > ${NAME}.spec cat ChangeLog >> ${NAME}.spec -yes "" | rpmbuild -ba --sign \ - --define "_signature gpg" \ - --define "_gpg_name Comcast Xmidt Team " \ - --define "_ver $release" \ - --define "_releaseno ${BUILD_NUMBER}" \ - --define "_fullver $new_release" \ - ${NAME}.spec +if [ 0 eq $SIGN ]; then + yes "" | rpmbuild -ba \ + --define "_ver $release" \ + --define "_releaseno ${BUILD_NUMBER}" \ + --define "_fullver $new_release" \ + ${NAME}.spec +else + yes "" | rpmbuild -ba --sign \ + --define "_signature gpg" \ + --define "_gpg_name Comcast Xmidt Team " \ + --define "_ver $release" \ + --define "_releaseno ${BUILD_NUMBER}" \ + --define "_fullver $new_release" \ + ${NAME}.spec +fi pushd .. echo "$new_release" > versionno.txt popd - diff --git a/caduceus.spec b/caduceus.spec deleted file mode 100644 index c133de19..00000000 --- a/caduceus.spec +++ /dev/null @@ -1,110 +0,0 @@ -%define debug_package %{nil} - -Name: caduceus -Version: %{_ver} -Release: %{_releaseno}%{?dist} -Summary: The Xmidt event delivery server. - -Group: System Environment/Daemons -License: ASL 2.0 -URL: https://github.com/Comcast/caduceus -Source0: %{name}-%{_fullver}.tar.gz - -BuildRequires: golang >= 1.8 -Requires: supervisor - -%description -The Xmidt server for delivering events written in Go. - -%prep -%setup -q - - -%build -export GOPATH=$(pwd) -pushd src -glide install --strip-vendor -cd caduceus -go build %{name} -popd - -%install - -# Install Binary -mkdir -p %{buildroot}%{_bindir} -%{__install} -p src/caduceus/%{name} %{buildroot}%{_bindir} - -# Install Service -mkdir -p %{buildroot}%{_initddir} -%{__install} -p etc/init.d/%{name} %{buildroot}%{_initddir} - -# Install Configuration -%{__install} -d %{buildroot}%{_sysconfdir}/%{name} -%{__install} -p etc/%{name}/%{name}.env.example %{buildroot}%{_sysconfdir}/%{name}/%{name}.env.example -%{__install} -p etc/%{name}/%{name}.json %{buildroot}%{_sysconfdir}/%{name}/%{name}.json -%{__install} -p etc/%{name}/supervisord.conf %{buildroot}%{_sysconfdir}/%{name}/supervisord.conf - -# Create Logging Location -%{__install} -d %{buildroot}%{_localstatedir}/log/%{name} - -# Create Runtime Details Location -%{__install} -d %{buildroot}%{_localstatedir}/run/%{name} - -%files -%defattr(644, caduceus, caduceus, 755) - -# Binary -%attr(755, caduceus, caduceus) %{_bindir}/%{name} - -# Init.d -%attr(755, caduceus, caduceus) %{_initddir}/%{name} - -# Configuration -%dir %{_sysconfdir}/%{name} -%config %attr(644, caduceus, caduceus) %{_sysconfdir}/%{name}/%{name}.env.example -%config %attr(644, caduceus, caduceus) %{_sysconfdir}/%{name}/%{name}.json -%config %attr(644, caduceus, caduceus) %{_sysconfdir}/%{name}/supervisord.conf - -# Logging Location -%dir %{_localstatedir}/log/%{name} - -# Runtime Details Location -%dir %{_localstatedir}/run/%{name} - -%pre -# If app user does not exist, create -id %{name} >/dev/null 2>&1 -if [ $? != 0 ]; then - /usr/sbin/groupadd -r %{name} >/dev/null 2>&1 - /usr/sbin/useradd -d /var/run/%{name} -r -g %{name} %{name} >/dev/null 2>&1 -fi - - -%post -if [ $1 = 1 ]; then - /sbin/chkconfig --add %{name} -fi - -%preun -# Stop service if running -if [ -e /etc/init.d/%{name} ]; then - /sbin/service %{name} stop > /dev/null 2>&1 - true -fi - -# If not an upgrade, then delete -if [ $1 = 0 ]; then - /sbin/chkconfig --del %{name} > /dev/null 2>&1 - true -fi - -%postun -# Do not remove anything if this is not an uninstall -if [ $1 = 0 ]; then - /usr/sbin/userdel -r %{name} >/dev/null 2>&1 - /usr/sbin/groupdel %{name} >/dev/null 2>&1 - # Ignore errors from above - true -fi - -%changelog diff --git a/caduceus.spec.in b/caduceus.spec.in new file mode 100644 index 00000000..936781fa --- /dev/null +++ b/caduceus.spec.in @@ -0,0 +1,93 @@ +%define debug_package %{nil} + +Name: caduceus +Version: %{_ver} +Release: %{_releaseno}%{?dist} +Summary: The Xmidt event delivery server. + +Group: System Environment/Daemons +License: ASL 2.0 +URL: https://github.com/Comcast/%{name} +Source0: %{name}-%{_fullver}.tar.gz + +BuildRequires: golang >= 1.8 +BuildRequires: systemd +Requires: systemd + +Provides: %{name} + +%description +The Xmidt server for delivering events. + +%prep +%setup -q + + +%build +export GOPATH=$(pwd) +pushd src +glide install --strip-vendor +cd %{name} +go build %{name} +popd + +%install + +# Install Binary +mkdir -p %{buildroot}%{_bindir} +%{__install} -p src/%{name}/%{name} %{buildroot}%{_bindir} + +# Install Service +mkdir -p %{buildroot}%{_unitdir}/ +%{__install} -m644 etc/systemd/%{name}.service %{buildroot}%{_unitdir} + +# Install Configuration +%{__install} -d %{buildroot}%{_sysconfdir}/%{name} +%{__install} -p etc/%{name}/%{name}.json %{buildroot}%{_sysconfdir}/%{name}/%{name}.json + +# Create Logging Location +%{__install} -d %{buildroot}%{_localstatedir}/log/%{name} + +%files +%defattr(644, %{name}, %{name}, 755) + +# Binary +%attr(755, %{name}, %{name}) %{_bindir}/%{name} + +# Systemd +%attr(755, %{name}, %{name}) %{_unitdir}/%{name}.service + +# Configuration +%dir %{_sysconfdir}/%{name} +%config %attr(644, %{name}, %{name}) %{_sysconfdir}/%{name}/%{name}.json + +# Logging Location +%dir %{_localstatedir}/log/%{name} + +%pre +# If app user does not exist, create +id %{name} >/dev/null 2>&1 +if [ $? != 0 ]; then + /usr/sbin/groupadd -r %{name} >/dev/null 2>&1 + /usr/sbin/useradd -r -g %{name} %{name} >/dev/null 2>&1 +fi + + +%post +%systemd_post %{name}.service + +%preun +%systemd_preun %{name}.service + +%postun +%systemd_postun_with_restart %{name}.service + +# Do not remove anything if this is not an uninstall +if [ $1 = 0 ]; then + /usr/sbin/userdel -r %{name} >/dev/null 2>&1 + /usr/sbin/groupdel %{name} >/dev/null 2>&1 + # Ignore errors from above + true +fi + +%changelog diff --git a/etc/caduceus/caduceus.env.example b/etc/caduceus/caduceus.env.example deleted file mode 100644 index 4ae21a83..00000000 --- a/etc/caduceus/caduceus.env.example +++ /dev/null @@ -1,5 +0,0 @@ -#ULIMIT_OPEN_FILES=75000 -#NET_CORE_SOMAXCONN=1000 -#NET_IPV4_TCP_MAX_SYN_BACKLOG=1000 -#NET_IPV4_TCP_MEM="100000000 100000000 100000000" -DAEMON_COREFILE_LIMIT=unlimited diff --git a/etc/caduceus/supervisord.conf b/etc/caduceus/supervisord.conf deleted file mode 100644 index aea3c010..00000000 --- a/etc/caduceus/supervisord.conf +++ /dev/null @@ -1,61 +0,0 @@ - -[supervisord] -http_port=/var/tmp/supervisor_caduceus.sock ; (default is to run a UNIX domain socket server) -;http_port=127.0.0.1:9001 ; (alternately, ip_address:port specifies AF_INET) -;sockchmod=0700 ; AF_UNIX socketmode (AF_INET ignore, default 0700) -;sockchown=nobody.nogroup ; AF_UNIX socket uid.gid owner (AF_INET ignores) -;umask=022 ; (process file creation umask;default 022) -logfile=/var/log/caduceus/supervisord.log ; (main log file;default $CWD/supervisord.log) -logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) -logfile_backups=10 ; (num of main logfile rotation backups;default 10) -loglevel=info ; (logging level;default info; others: debug,warn) -pidfile=/var/run/caduceus.pid ; (supervisord pidfile;default supervisord.pid) -nodaemon=false ; (start in foreground if true;default false) -minfds=1024 ; (min. avail startup file descriptors;default 1024) -minprocs=200 ; (min. avail process descriptors;default 200) - -;nocleanup=true ; (don't clean up tempfiles at start;default false) -;http_username=user ; (default is no username (open system)) -;http_password=123 ; (default is no password (open system)) -;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP) -;user=chrism ; (default is current user, required if root) -user=root -;directory=/tmp ; (default is not to cd during start) -directory=/var/run/caduceus -;environment=KEY=value ; (key value pairs to add to environment) - -[supervisorctl] -serverurl=unix:///var/tmp/supervisor_caduceus.sock ; use a unix:// URL for a unix socket -;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket -;username=chris ; should be same as http_username if set -;password=123 ; should be same as http_password if set -;prompt=mysupervisor ; cmd line prompt (default "supervisor") - -; The below sample program section shows all possible program subsection values, -; create one or more 'real' program: sections to be able to control them under -; supervisor. - -;[program:theprogramname] -;command=/bin/cat ; the program (relative uses PATH, can take args) -;priority=999 ; the relative start priority (default 999) -;autostart=true ; start at supervisord start (default: true) -;autorestart=true ; retstart at unexpected quit (default: true) -;startsecs=10 ; number of secs prog must stay running (def. 10) -;startretries=3 ; max # of serial start failures (default 3) -;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10) -;user=chrism ; setuid to this UNIX account to run the program -;log_stdout=true ; if true, log program stdout (default true) -;log_stderr=true ; if true, log program stderr (def false) -;logfile=/var/log/cat.log ; child log path, use NONE for none; default AUTO -;logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;logfile_backups=10 ; # of logfile backups (default 10) - -[program:caduceus] -user=caduceus -command=/usr/bin/caduceus -logfile=/var/log/caduceus/console.out -log_stderr=true - - diff --git a/etc/init.d/caduceus b/etc/init.d/caduceus deleted file mode 100644 index d06099fa..00000000 --- a/etc/init.d/caduceus +++ /dev/null @@ -1,94 +0,0 @@ -#!bin/bash -# -# caduceus Application Startup Script -# -# chkconfig: 345 90 14 -# description: Application Startup Script -# config: /etc/caduceus/supervisord.conf -# pidfile: /var/run/caduceus/caduceus.pid - -# Source function library -. /etc/rc.d/init.d/functions - -# Source the optional environment setup file -if [ -f /etc/caduceus/caduceus.env ]; then - . /etc/caduceus/caduceus.env -fi - -RETVAL=0 - -# Set limits here in addition to limits.conf -#------------------------------------------------------------------------------- -if [ -n "$ULIMIT_OPEN_FILES" ]; then - sysctl -w fs.file-max=$ULIMIT_OPEN_FILES > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "fs.file-max=$ULIMIT_OPEN_FILES failed" && exit $RETVAL - - sysctl -w fs.nr_open=$ULIMIT_OPEN_FILES > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "fs.nr_open=$ULIMIT_OPEN_FILES failed" && exit $RETVAL - - ulimit -n $ULIMIT_OPEN_FILES > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "ulimit -n $ULIMIT_OPEN_FILES failed" && exit $RETVAL -fi -if [ -n "$NET_IPV4_TCP_MEM" ]; then - sysctl -w net.ipv4.tcp_mem=$NET_IPV4_TCP_MEM > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "net.ipv4.tcp_mem=$NET_IPV4_TCP_MEM failed" && exit $RETVAL -fi -if [ -n "$NET_CORE_SOMAXCONN" ]; then - sysctl -w net.core.somaxconn=$NET_CORE_SOMAXCONN > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "net.core.somaxconn=$NET_CORE_SOMAXCONN failed" && exit $RETVAL -fi -if [ -n "$NET_IPV4_TCP_MAX_SYN_BACKLOG" ]; then - sysctl -w net.ipv4.tcp_max_syn_backlog=$NET_IPV4_TCP_MAX_SYN_BACKLOG > /dev/null - RETVAL=$? - [ $RETVAL -ne 0 ] && echo "net.ipv4.tcp_max_syn_backlog=$NET_IPV4_TCP_MAX_SYN_BACKLOG failed" && exit $RETVAL -fi -#------------------------------------------------------------------------------- - -start() { - echo -n $"Starting caduceus: " - daemon supervisord -c /etc/caduceus/supervisord.conf - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/caduceus -} - -stop() { - echo -n $"Stopping caduceus: " - killproc supervisord - echo - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/caduceus -} - -restart() { - stop - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart|force-reload|reload) - restart - ;; - condrestart) - [ -f /var/lock/subsys/caduceus ] && restart - ;; - status) - status supervisord - RETVAL=$? - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" - exit 1 -esac - -exit $RETVAL diff --git a/etc/systemd/caduceus.service b/etc/systemd/caduceus.service new file mode 100644 index 00000000..4d9aa7c4 --- /dev/null +++ b/etc/systemd/caduceus.service @@ -0,0 +1,12 @@ +[Unit] +Description=The Xmidt server for delivering events. +After=network.target + +[Service] +Type=simple +User=caduceus +ExecStart=/usr/bin/caduceus +Restart=on-failure + +[Install] +WantedBy=multi-user.target