Skip to content

Commit

Permalink
Merge branch 'master' into report-log
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Danras Justo committed Jul 30, 2017
2 parents 38e16f7 + 228c3eb commit 5133456
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- Using cron scheduler library from Rob Figueiredo
- Deploy scripts now configure themselves as daemons

## [3.1.0] - 2017-06-21
### Added
Expand Down
84 changes: 84 additions & 0 deletions deploy/deb/package-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
set -e

# package information
readonly PACKAGE_NAME="toglacier"
readonly VENDOR="Rafael Dantas Justo"
readonly MAINTAINER="Rafael Dantas Justo <[email protected]>"
readonly URL="https://rafael.net.br"
readonly LICENSE="MIT"
readonly DESCRIPTION="Send data to Amazon Glacier service periodically."

# install information
readonly TMP_PATH="/tmp/toglacier/"
readonly BIN_PATH="$TMP_PATH/usr/local/bin/"
readonly CONF_PATH="$TMP_PATH/etc/"

exit_error() {
echo "$1. Abort" 1>&2
exit 1
}

prepare() {
rm -f toglacier*.deb 2>/dev/null

mkdir -p $BIN_PATH || exit_error "Cannot create the temporary path"
mkdir -p $CONF_PATH || exit_error "Cannot create the temporary path"
}

compile() {
local project_path=`echo $GOPATH | cut -d: -f1`
local program_path=""
local current_path=`pwd`

program_path=$project_path/src/github.com/rafaeljusto/toglacier/cmd/toglacier
cd $program_path || exit_error "Cannot change directory"
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/rafaeljusto/toglacier/internal/config.Version=$VERSION" || exit_error "Compile error"
mv toglacier $BIN_PATH || exit_error "Error copying binary"
cp toglacier.yml $CONF_PATH/toglacier.yml.sample || exit_error "Error copying configuration sample"

program_path=$project_path/src/github.com/rafaeljusto/toglacier/cmd/toglacier-storage
cd $program_path || exit_error "Cannot change directory"
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/rafaeljusto/toglacier/internal/config.Version=$VERSION" || exit_error "Compile error"
mv toglacier-storage $BIN_PATH || exit_error "Error copying binary"

cd $current_path
}

build_deb() {
local project_path=`echo $GOPATH | cut -d: -f1`
project_path=$project_path/src/github.com/rafaeljusto/toglacier

local version=`echo "$VERSION" | awk -F "-" '{ print $1 }'`
local release=`echo "$VERSION" | awk -F "-" '{ print $2 }'`

fpm -s dir -t deb --after-install $project_path/deploy/deb/toglacier.postinst \
--after-upgrade $project_path/deploy/deb/toglacier.postinst \
-n $PACKAGE_NAME -v "$version" --iteration "$release" --vendor "$VENDOR" \
--maintainer "$MAINTAINER" --url $URL --license "$LICENSE" --description "$DESCRIPTION" \
--deb-upstart $project_path/deploy/deb/toglacier.upstart \
--deb-systemd $project_path/deploy/deb/toglacier.service \
--deb-user root --deb-group root \
--prefix / -C $TMP_PATH usr/local/bin etc
}

cleanup() {
rm -rf $TMP_PATH
}

VERSION=$1

usage() {
echo "Usage: $1 <version>"
}

if [ -z "$VERSION" ]; then
echo "Undefined VERSION!"
usage $0
exit 1
fi

prepare
compile
build_deb
cleanup
21 changes: 21 additions & 0 deletions deploy/deb/toglacier.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e

user=toglacier
group=toglacier

# make sure the user exists
if ! getent passwd $user > /dev/null; then
adduser --system --quiet --no-create-home --shell /bin/bash \
--group --gecos "toglacier tool" $user
fi

# if the user was created manually, make sure the group is there as well
if ! getent group $user > /dev/null; then
addgroup --system --quiet $user
fi

# make sure the created user is in the created group
if ! id -Gn $user | grep -qw $group; then
adduser --quiet $user $group
fi
16 changes: 16 additions & 0 deletions deploy/deb/toglacier.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=toglacier - Periodic send backups to the cloud
Requires=network.target
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/toglacier -c /etc/toglacier.yml start
Restart=on-failure
RestartSec=10
StartLimitInterval=10m
StartLimitBurst=5
User=toglacier

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions deploy/deb/toglacier.upstart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Upstart job configuration file

description "toglacier - Periodic send backups to the cloud"
author "Rafael Dantas Justo"

start on filesystem and (started networking)

respawn
respawn limit 3 10

exec start-stop-daemon \
--start \
-c toglacier \
--exec /usr/local/bin/toglacier \
-- -c /etc/toglacier.yml start
File renamed without changes.
10 changes: 8 additions & 2 deletions package-txz.sh → deploy/txz/package-txz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readonly DESCRIPTION="Send data to Amazon Glacier service periodically."

# install information
readonly TMP_PATH="/tmp/toglacier/"
readonly SCRIPTS_PATH="$TMP_PATH/usr/local/etc/rc.d"
readonly BIN_PATH="$TMP_PATH/usr/local/bin/"
readonly CONF_PATH="$TMP_PATH/etc/"

Expand All @@ -19,14 +20,19 @@ exit_error() {
}

prepare() {
mkdir -p $BIN_PATH || exit_error "Cannot create the temporary path"
mkdir -p $CONF_PATH || exit_error "Cannot create the temporary path"
mkdir -p $SCRIPTS_PATH || exit_error "Cannot create the temporary scripts path"
mkdir -p $BIN_PATH || exit_error "Cannot create the temporary binary path"
mkdir -p $CONF_PATH || exit_error "Cannot create the temporary configuration path"
}

copy_files() {
local project_path=`echo $GOPATH | cut -d: -f1`
project_path=$project_path/src/github.com/rafaeljusto/toglacier
local version=`echo "$VERSION" | awk -F "-" '{ print $1 }'`
local release=`echo "$VERSION" | awk -F "-" '{ print $2 }'`

cp $project_path/deploy/txz/toglacier $SCRIPTS_PATH/toglacier || exit_error "Cannot copy execution script"

# calculate the files size
local files_size=0
for f in `find $TMP_PATH -type f`
Expand Down
17 changes: 17 additions & 0 deletions deploy/txz/toglacier
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# PROVIDE: toglacier
# REQUIRE: DAEMON ntpd
# KEYWORD: shutdown

. /etc/rc.subr

name="toglacier"
rcvar=`set_rcvar`
command="/usr/local/bin/toglacier -c /etc/toglacier.yml start"
pidfile="/var/run/toglacier.pid"

: ${toglacier_enable:=no}

load_rc_config $name
run_rc_command "$1"

0 comments on commit 5133456

Please sign in to comment.