Merge remote-tracking branch 'ungleich/master' into the-good-the-bad-and-the-ugly

This commit is contained in:
Darko Poljak 2017-06-12 13:15:00 +02:00
commit e375bd464d
98 changed files with 1547 additions and 106 deletions

View file

@ -85,9 +85,11 @@ def get_parsers():
action='store_true', default=False)
parser['loglevel'].add_argument(
'-v', '--verbose',
help=('Increase log level, be more verbose. Use it more than once '
'to increase log level. The order of levels from the lowest '
'to the highest are: ERROR, WARNING, INFO, DEBUG.'),
help=('Increase the verbosity level. Every instance of -v '
'increments the verbosity level by one. Its default value '
'is 0. There are 4 levels of verbosity. The order of levels '
'from the lowest to the highest are: ERROR (0), '
'WARNING (1), INFO (2) and DEBUG (3 or higher).'),
action='count', default=0)
parser['beta'] = argparse.ArgumentParser(add_help=False)

View file

@ -0,0 +1 @@
uname -s

View file

@ -1,9 +1,9 @@
cdist-type__install_chroot_mount(7)
cdist-type__chroot_mount(7)
===================================
NAME
----
cdist-type__install_chroot_mount - mount a chroot
cdist-type__chroot_mount - mount a chroot
DESCRIPTION
@ -26,7 +26,7 @@ EXAMPLES
.. code-block:: sh
__install_chroot_mount /path/to/chroot
__chroot_mount /path/to/chroot
AUTHORS

View file

@ -1,9 +1,9 @@
cdist-type__install_chroot_umount(7)
====================================
cdist-type__chroot_umount(7)
============================
NAME
----
cdist-type__install_chroot_umount - unmount a chroot mounted by __chroot_mount
cdist-type__chroot_umount - unmount a chroot mounted by __chroot_mount
DESCRIPTION
@ -26,7 +26,7 @@ EXAMPLES
.. code-block:: sh
__install_chroot_umount /path/to/chroot
__chroot_umount /path/to/chroot
SEE ALSO

View file

@ -0,0 +1 @@
283033689 36101209 consul

View file

@ -0,0 +1 @@
https://releases.hashicorp.com/consul/0.8.1/consul_0.8.1_linux_amd64.zip

View file

@ -23,7 +23,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
scientific|centos|redhat|ubuntu|debian|archlinux|gentoo)
scientific|centos|redhat|ubuntu|debian|devuan|archlinux|gentoo)
# any linux should work
:
;;

View file

@ -23,7 +23,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
scientific|centos|debian|redhat|ubuntu)
scientific|centos|debian|devuan|redhat|ubuntu)
# whitelist safeguard
:
;;
@ -215,7 +215,11 @@ case "$os" in
esac
;;
ubuntu)
init_upstart
;;
devuan)
init_sysvinit debian
;;
ubuntu)
init_upstart
;;
esac

View file

@ -24,6 +24,9 @@ OPTIONAL PARAMETERS
check-interval
the interval in which the script given with --check-script should be run
check-http
the URL to check for HTTP 200-ish status every --check-interval
check-script
the shell command to run every --check-interval

View file

@ -32,6 +32,10 @@ if [ -f "$__object/parameter/check-script" -a ! -f "$__object/parameter/check-in
echo "When using --check-script you must also define --check-interval" >&2
exit 1
fi
if [ -f "$__object/parameter/check-http" -a ! -f "$__object/parameter/check-interval" ]; then
echo "When using --check-http you must also define --check-interval" >&2
exit 1
fi
# Generate json config file
(
@ -52,6 +56,12 @@ for param in $(ls "$__object/parameter/"); do
printf ' "ttl": "%s"\n' "$(cat "$__object/parameter/check-ttl")"
printf ' }\n'
;;
check-http)
printf ' ,"check": {\n'
printf ' "http": "%s"\n' "$(cat "$__object/parameter/check-http")"
printf ' ,"interval": "%s"\n' "$(cat "$__object/parameter/check-interval")"
printf ' }\n'
;;
tag)
# create json array from newline delimited file
tags="$(awk '{printf "\""$1"\","}' "$__object/parameter/tag")"

View file

@ -1,3 +1,4 @@
check-http
check-interval
check-script
check-ttl

View file

@ -22,4 +22,9 @@
name="$__object_name"
user="$(cat "$__object/parameter/user")"
crontab -u $user -l 2>/dev/null | grep "# $name\$" || true
if [ -f "$__object/parameter/raw_command" ]; then
command="$(cat "$__object/parameter/command")"
crontab -u $user -l 2>/dev/null | grep "^$command\$" || true
else
crontab -u $user -l 2>/dev/null | grep "# $name\$" || true
fi

17
cdist/conf/type/__cron/gencode-remote Executable file → Normal file
View file

@ -3,6 +3,7 @@
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Thomas Oettli (otho at sfs.biz)
# 2017 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@ -26,7 +27,7 @@ command="$(cat "$__object/parameter/command")"
if [ -f "$__object/parameter/raw" ]; then
raw="$(cat "$__object/parameter/raw")"
entry="$raw $command"
entry="$raw $command # $name"
elif [ -f "$__object/parameter/raw_command" ]; then
entry="$command"
else
@ -35,10 +36,9 @@ else
day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
entry="$minute $hour $day_of_month $month $day_of_week $command"
entry="$minute $hour $day_of_month $month $day_of_week $command # $name"
fi
entry="$entry # $name"
mkdir "$__object/files"
echo "$entry" > "$__object/files/entry"
@ -58,7 +58,7 @@ state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
# These are the old markers
prefix="#cdist:__cron/$__object_id"
suffix="#/cdist:__cron/$__object_id"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$"
cat << DONE
crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{
@ -85,7 +85,12 @@ case "$state_should" in
echo ") | crontab -u $user -"
;;
absent)
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"# $name\\$\" | crontab -u $user -"
if [ -f "$__object/parameter/raw_command" ]; then
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"^$entry\\$\" | crontab -u $user -"
else
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"# $name\\$\" | crontab -u $user -"
fi
;;
esac

View file

@ -0,0 +1,63 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: svscan
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: svscan
# Description: djb svscan
### END INIT INFO
# from https://gist.githubusercontent.com/pacojp/5766990/raw/2ed009ab19515afc9e58291b636d673c5ca864b3/init.d.svscan
# written by Adam McKenna <adam@debian.org>
# edited by Kamila Součková <kamila@ksp.sk>
export PATH=$PATH:/usr/local/bin
l=/var/log/svscan
if [ ! -d $l ]; then
mkdir $l
chown daemon $l
fi
case "$1" in
start)
echo -n "Starting daemontools: "
if [ ! `pidof svscan` ]; then
echo -n "svscan "
env - PATH="$PATH" svscan /service 2>&1 | setuidgid daemon multilog t /var/log/svscan &
echo "."
else
echo "already running."
fi
;;
stop)
echo -n "Stopping daemontools: "
if [ `pidof svscan` ]; then
echo -n "svscan"
while [ `pidof svscan` ]; do
kill `pidof svscan`
echo -n "."
done
fi
echo -n " services"
for i in `ls -d /service/*`; do
svc -dx $i
echo -n "."
done
echo -n " logging "
for i in `ls -d /service/*/log`; do
svc -dx $i
echo -n "."
done
echo ""
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
echo 'Usage: /etc/init.d/svscan {start|stop|restart|force-reload}'
exit 1
esac

View file

@ -0,0 +1,49 @@
cdist-type__daemontools(7)
==========================
NAME
----
cdist-type__daemontools - Install daemontools
DESCRIPTION
-----------
Install djb daemontools and (optionally) an init script.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
from-package
Package to install. Must be compatible with the original daemontools. Example: daemontools-encore. Default: daemontools.
BOOLEAN PARAMETERS
------------------
install-init-script
Add an init script and set it to start on boot. Default yes.
EXAMPLES
--------
.. code-block:: sh
__daemontools --from-package daemontools-encore # if you prefer
SEE ALSO
--------
:strong:`cdist-type__daemontools_service`\ (7)
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,20 @@
#!/bin/sh
pkg=$(cat "$__object/parameter/from-package")
__package $pkg
if [ -f "$__object/parameter/install-init-script" ]; then
init=$(cat "$__global/explorer/init")
case $init in
init)
__config_file /etc/init.d/svscan --mode 755 --source "$__type/files/init.d-svscan"
require="$require __config_file/etc/init.d/svscan" __start_on_boot svscan
require="$require __start_on_boot/svscan" __process svscan --start 'service svscan start'
;;
*)
echo "Your init system ($init) is not supported by this type. Submit a patch at github.com/ungleich/cdist!"
exit 1
;;
esac
fi

View file

@ -0,0 +1 @@
install-init-script

View file

@ -0,0 +1 @@
daemontools

View file

@ -0,0 +1 @@
from-package

View file

View file

@ -0,0 +1 @@
command -v svc

View file

@ -0,0 +1,72 @@
cdist-type__daemontools_service(7)
==================================
NAME
----
cdist-type__daemontools_service - Create a daemontools-compatible service dir.
DESCRIPTION
-----------
Create a directory structure compatible with daemontools-like service management.
Note that svc must be present on the target system.
The object ID will be used as the service name.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
run
Command to run. exec-ing and stderr redirection will be added. One of run, run-file must be specified.
Example: `my-program`
run-file
File to save as <servicedir>/run. One of run, run-file must be specified.
Example:
.. code-block:: sh
#!/bin/sh
exec 2>&1
exec my_program
log-run
Command to run for log consumption. Default: `multilog t ./main`
servicedir
Directory to install into. Default: `/service`
BOOLEAN PARAMETERS
------------------
None.
EXAMPLES
--------
.. code-block:: sh
require="__daemontools" __daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $FLAGS"
SEE ALSO
--------
:strong:`cdist-type__daemontools`\ (7)
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,38 @@
#!/bin/sh
RUN_PREFIX="#!/bin/sh
exec 2>&1
exec " # mind the space :D
name=$__object_id
servicedir=$(cat "$__object/parameter/servicedir")
run=$(cat "$__object/parameter/run")
runfile=$(cat "$__object/parameter/run-file")
logrun=$(cat "$__object/parameter/log-run")
svc=$(cat "$__type/explorer/svc")
if [ -z "$svc" ]; then
echo "svc not found! Install daemontools first: see __daemontools"
exit 1
fi
badusage() {
echo "__daemontools_service/$__object_id: exactly one of --run, --run-file must be set" >&2
exit 1
}
[ -z "$run$runfile" ] && badusage
[ -n "$run" ] && [ -n "$runfile" ] && badusage
__directory $servicedir/$name/log/main --parents
echo "$RUN_PREFIX$run" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/run" \
--onchange "svc -t '$servicedir/$name' 2>/dev/null" \
--mode 755 \
--source "${runfile:--}"
echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file $servicedir/$name/log/run \
--onchange "svc -t '$servicedir/$name/log' 2>/dev/null" \
--mode 755 \
--source "-"

View file

@ -0,0 +1 @@
multilog t ./main

View file

@ -0,0 +1 @@
/service

View file

@ -0,0 +1,4 @@
log-run
run
run-file
servicedir

View file

@ -26,17 +26,24 @@ BOOLEAN PARAMETERS
experimental
Install the experimental docker-engine package instead of the latest stable release.
state
'present' or 'absent', defaults to 'present'
EXAMPLES
--------
.. code-block:: sh
# Install docker
__docker
# experimental
# Install experimental
__docker --experimental
# Remove docker
__docker --state absent
AUTHORS
-------

View file

@ -20,38 +20,39 @@
os=$(cat "$__global/explorer/os")
state=$(cat "$__object/parameter/state")
case "$os" in
centos)
component="main"
centos)
component="main"
if [ -f "$__object/parameter/experimental" ]; then
component="experimental"
fi
__yum_repo docker \
--name 'Docker Repository' \
--baseurl "https://yum.dockerproject.org/repo/$component/centos/\$releasever/" \
--enabled \
--gpgcheck 1 \
--gpgkey 'https://yum.dockerproject.org/gpg' \
--state ${state}
require="__yum_repo/docker" __package docker-engine --state ${state}
;;
ubuntu)
component="main"
if [ -f "$__object/parameter/experimental" ]; then
component="experimental"
fi
export CDIST_ORDER_DEPENDENCY=on
__yum_repo docker \
--name 'Docker Repository' \
--baseurl "https://yum.dockerproject.org/repo/$component/centos/\$releasever/" \
--enabled \
--gpgcheck \
--gpgkey 'https://yum.dockerproject.org/gpg'
__package docker-engine
unset CDIST_ORDER_DEPENDENCY
;;
ubuntu)
component="main"
if [ -f "$__object/parameter/experimental" ]; then
component="experimental"
fi
__package apparmor
__package ca-certificates
__package apt-transport-https
__apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D
__package apparmor --state ${state}
__package ca-certificates --state ${state}
__package apt-transport-https --state ${state}
__apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state}
export CDIST_ORDER_DEPENDENCY=on
__apt_source docker \
--uri https://apt.dockerproject.org/repo \
--distribution "ubuntu-$(cat "$__global/explorer/lsb_codename")" \
--state ${state} \
--component "$component"
__package docker-engine
__package docker-engine --state ${state}
unset CDIST_ORDER_DEPENDENCY
;;
debian)
@ -60,16 +61,17 @@ case "$os" in
component="experimental"
fi
__package apt-transport-https
__package ca-certificates
__package gnupg2
__apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D
__package apt-transport-https --state ${state}
__package ca-certificates --state ${state}
__package gnupg2 --state ${state}
__apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state}
export CDIST_ORDER_DEPENDENCY=on
__apt_source docker \
--uri https://apt.dockerproject.org/repo \
--distribution "debian-$(cat "$__global/explorer/lsb_codename")" \
--state ${state} \
--component "$component"
__package docker-engine
__package docker-engine --state ${state}
unset CDIST_ORDER_DEPENDENCY
;;

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
state

View file

@ -0,0 +1,31 @@
#!/bin/sh
#
# 2016 Dominique Roux (dominique.roux at ungleich.ch)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
# Variables
version="$(cat "$__object/parameter/version")"
state="$(cat "$__object/parameter/state")"
if [ ${state} = "present" ]; then
# Download docker-compose file
echo 'curl -L "https://github.com/docker/compose/releases/download/'${version}'/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose'
echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose'
# Change permissions
echo 'chmod +x /usr/local/bin/docker-compose'
fi

View file

@ -0,0 +1,58 @@
cdist-type__docker_compose(7)
=============================
NAME
----
cdist-type__docker_compose - install docker-compose
DESCRIPTION
-----------
Installs docker-compose package.
State 'absent' will not remove docker binary itself,
only docker-compose binary will be removed
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
version
Define docker_compose version, defaults to "1.9.0"
state
'present' or 'absent', defaults to 'present'
BOOLEAN PARAMETERS
------------------
None.
EXAMPLES
--------
.. code-block:: sh
# Install docker-compose
__docker_compose
# Install version 1.9.0-rc4
__docker_compose --version 1.9.0-rc4
# Remove docker-compose
__docker_compose --state absent
AUTHORS
-------
Dominique Roux <dominique.roux--@--ungleich.ch>
COPYING
-------
Copyright \(C) 2016 Dominique Roux. Free use of this software is
granted under the terms of the GNU General Public License version 3 or later (GPLv3+).

View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# 2016 Dominique Roux (dominique.roux at ungleich.ch)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
state="$(cat "$__object/parameter/state")"
# Needed packages
if [ ${state} = "present" ]; then
__docker
__package curl
elif [ ${state} = "absent" ]; then
__file /usr/local/bin/docker-compose --state absent
else
echo "Unknown state: ${state}" >&2
exit 1
fi

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
1.12.0

View file

@ -0,0 +1,2 @@
state
version

View file

@ -0,0 +1,27 @@
#!/bin/sh
# Copyright (C) 2016 Dmitry Bogatov <KAction@gnu.org>
# Author: Dmitry Bogatov <KAction@gnu.org>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -eu
user="$(cat "${__object}/parameter/user")"
if which getent >/dev/null 2>&1; then
line=$(getent passwd "${user}")
else
line=$(grep "^${user}:" /etc/passwd)
fi
printf '%s' "$line" | cut -d: -f6

View file

@ -0,0 +1,21 @@
#!/bin/sh
# Copyright (C) 2016 Dmitry Bogatov <kaction@sagulo>
# Author: Dmitry Bogatov <kaction@sagulo>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -eu
user="$(cat "${__object}/parameter/user")"
id -gn "${user}"

View file

@ -0,0 +1,71 @@
cdist-type__dot_file(7)
========================
NAME
----
cdist-type__dot_file - install file under user's home directory
DESCRIPTION
-----------
This type installs a file (=\ *__object_id*) under user's home directory,
providing a way to install per-user configuration files. File owner
and group is deduced from user, for who file is installed.
Unlike regular __file type, you do not need make any assumptions,
where user's home directory is.
REQUIRED PARAMETERS
-------------------
user
User, for who file is installed
OPTIONAL PARAMETERS
-------------------
mode
forwarded to :strong:`__file` type
state
forwarded to :strong:`__file` type
source
forwarded to :strong:`__file` type
MESSAGES
--------
This type inherits all messages from :strong:`file` type, and do not add
any new.
EXAMPLES
--------
.. code-block:: sh
# Install .forward file for user 'alice'. Since state is 'present',
# user is not meant to edit this file, all changes will be overridden.
# It is good idea to put warning about it in file itself.
__dot_file .forward --user alice --source "$__files/forward"
# Install .muttrc for user 'bob', if not already present. User can safely
# edit it, his changes will not be overwritten.
__dot_file .muttrc --user bob --source "$__files/recommended_mutt_config" --state exists
# Install default xmonad config for user 'eve'. Parent directory is created automatically.
__dot_file .xmonad/xmonad.hs --user eve --state exists --source "$__files/xmonad.hs"
SEE ALSO
--------
**cdist-type__file**\ (7)
COPYING
-------
Copyright (C) 2015 Dmitry Bogatov. Free use of this software is granted
under the terms of the GNU General Public License version 3 or later
(GPLv3+).

View file

@ -0,0 +1,65 @@
#!/bin/sh
#
# Copyright (C) 2016 Bogatov Dmitry <KAction@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -eu
user="$(cat "${__object}/parameter/user")"
home="$(cat "${__object}/explorer/home")"
primary_group="$(cat "${__object}/explorer/primary_group")"
# Create parent directory. Type __directory has flag 'parents', but it
# will leave us with root-owned directory in user home, which is not
# acceptable. So we create parent directories one-by-one. XXX: maybe
# it should be fixed in '__directory'?
set --
subpath=${__object_id}
while subpath="$(dirname "${subpath}")" ; do
[ "${subpath}" = . ] && break
set -- "${subpath}" "$@"
done
unset subpath
export CDIST_ORDER_DEPENDENCY
for dir ; do
__directory "${home}/${dir}" \
--group "${primary_group}" \
--owner "${user}"
done
# These parameters are forwarded to __file type. 'mode' is always
# present, since it have been given default.
set --
for p in state mode source ; do
if [ -f "${__object}/parameter/${p}" ] ; then
value="$(cat "${__object}/parameter/${p}")"
set -- "$@" "--${p}" "${value}"
unset value
fi
done
# If source is `-' we can't just forward it, since stdin is already
# captured by __dot_file. So, we replace '-' with "$__object/stdin".
#
# It means that it is possible for __file to receive --source
# parameter twice, but, since latest wins, it is okay.
source="$(cat "${__object}/parameter/source")"
if [ "${source}" = "-" ] ; then
set -- "$@" --source "${__object}/stdin"
fi
unset source
__file "${home}/${__object_id}" --owner "$user" --group "$primary_group" "$@"

View file

@ -0,0 +1 @@
600

View file

@ -0,0 +1,3 @@
state
mode
source

View file

@ -0,0 +1 @@
user

View file

@ -0,0 +1,3 @@
[ -f /etc/environment ] && . /etc/environment
[ -f /etc/profile ] && . /etc/profile
go version 2>/dev/null || true

View file

@ -0,0 +1,8 @@
package=$__object_id
cat<<EOF
[ -f /etc/environment ] && . /etc/environment
[ -f /etc/profile ] && . /etc/profile
export GOPATH=\${GOPATH:-/opt/gocode}
go get $package
EOF

View file

@ -0,0 +1,48 @@
cdist-type__go_get(7)
=====================
NAME
----
cdist-type__go_get - Install go packages with go get
DESCRIPTION
-----------
This cdist type allows you to install golang packages with go get.
A sufficiently recent version of go must be present on the system.
The object ID is the go package to be installed.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
None.
EXAMPLES
--------
.. code-block:: sh
__go_get github.com/prometheus/prometheus/cmd/...
# usually you'd need to require golang from somewhere:
require="__golang_from_vendor" __go_get github.com/prometheus/prometheus/cmd/...
AUTHORS
-------
Kamila Součková <kamila@ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,17 @@
#!/bin/sh
go_executable=$(cat "$__object/explorer/go-executable")
[ -z "$go_executable" ] && echo "__go_get: Cannot find go executable; make sure it is installed and in PATH" >&2 && exit 1
os=$(cat "$__global/explorer/os")
case $os in
debian|devuan|ubuntu)
__package build-essential
;;
*)
echo "__go_get: Don't know how to install g++ on $os" >&2
echo "__go_get: Send a pull request or contact <kamila@ksp.sk> to add support for $os." >&2
exit 1
;;
esac

View file

@ -0,0 +1,26 @@
#!/bin/sh
version=$(cat "$__object/parameter/version")
kernel_name=$(cat "$__global/explorer/kernel_name" | tr '[:upper:]' '[:lower:]')
machine=$(cat "$__global/explorer/machine")
case $machine in
x86_64|amd64)
arch=amd64
;;
x86)
arch=386
;;
*)
arch=$machine # at least try...
;;
esac
PACKAGE="go${version}.${kernel_name}-${arch}"
URL="https://storage.googleapis.com/golang/${PACKAGE}.tar.gz"
cat <<EOF
[ "x\$(cat /usr/local/go/VERSION 2>/dev/null)" = "xgo$version" ] && exit 0 # already there
wget --no-verbose "$URL" -O "/tmp/${PACKAGE}.tar.gz"
rm -rf /usr/local/go
tar -C /usr/local -xzf /tmp/${PACKAGE}.tar.gz
EOF

View file

@ -0,0 +1,48 @@
cdist-type__golang_from_vendor(7)
=================================
NAME
----
cdist-type__golang_from_vendor - Install any version of golang from golang.org
DESCRIPTION
-----------
This cdist type allows you to install golang from archives provided by https://golang.org/dl/.
See https://golang.org/dl/ for the list of supported versions, operating systems and architectures.
This is a singleton type.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
version
The golang version to install, defaults to 1.8.1
EXAMPLES
--------
.. code-block:: sh
__golang_from_vendor --version 1.8.1
AUTHORS
-------
Kamila Součková <kamila@ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1 @@
__line go_in_path --line 'export PATH=/usr/local/go/bin:$PATH' --file /etc/profile

View file

@ -0,0 +1 @@
1.8.1

View file

@ -0,0 +1 @@
version

View file

@ -0,0 +1,43 @@
cdist-type__grafana_dashboard(7)
================================
NAME
----
cdist-type__grafana_dashboard - Install Grafana (https://grafana.com)
DESCRIPTION
-----------
This cdist type adds the Grafana repository, installs the grafana package, and sets the server to start on boot.
This is a singleton type.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
None.
EXAMPLES
--------
.. code-block:: sh
__grafana_dashboard
AUTHORS
-------
Kamila Součková <kamila@ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,32 @@
os=$(cat $__global/explorer/os)
os_version=$(cat $__global/explorer/os_version)
case $os in
debian|devuan)
case $os_version in
8*|jessie)
__apt_key_uri grafana \
--name 'Grafana Release Signing Key' \
--uri https://packagecloud.io/gpg.key
require="__apt_key_uri/grafana" __apt_source grafana \
--uri https://packagecloud.io/grafana/stable/debian/ \
--distribution jessie \
--component main
__package apt-transport-https
require="__apt_source/grafana __package/apt-transport-https" __package grafana
require="__package/grafana" __start_on_boot grafana-server
;;
*)
echo "Don't know how to install Grafana on $os $os_version. Send us a pull request!"
exit 1
;;
esac
;;
*)
echo "Don't know how to install Grafana on $os. Send us a pull request!"
exit 1
;;
esac

View file

@ -0,0 +1,55 @@
cdist-type__hosts(7)
====================
NAME
----
cdist-type__hosts - manage entries in /etc/hosts
DESCRIPTION
-----------
Add or remove entries from */etc/hosts* file.
OPTIONAL PARAMETERS
-------------------
state
If state is ``present``, make *object_id* resolve to *ip*. If
state is ``absent``, *object_id* will no longer resolve via
*/etc/hosts*, if it was previously configured with this type.
Manually inserted entries are unaffected.
ip
IP address, to which hostname (=\ *object_id*) must resolve. If
state is ``present``, this parameter is mandatory, if state is
``absent``, this parameter is silently ignored.
EXAMPLES
--------
.. code-block:: sh
# Now `funny' resolves to 192.168.1.76,
__hosts funny --ip 192.168.1.76
# and `happy' no longer resolve via /etc/hosts if it was
# previously configured via __hosts.
__hosts happy --state absent
SEE ALSO
--------
:strong:`hosts`\ (5)
AUTHORS
-------
Dmitry Bogatov <KAction@gnu.org>
COPYING
-------
Copyright (C) 2015,2016 Dmitry Bogatov. Free use of this software is granted
under the terms of the GNU General Public License version 3 or later
(GPLv3+).

View file

@ -0,0 +1,29 @@
#!/bin/sh
# Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -ue
hostname="$__object_id"
state="$(cat "$__object/parameter/state")"
marker="# __hosts/$hostname"
set -- "__hosts/$hostname" --file /etc/hosts --state "$state"
if [ "$state" = absent ] ; then
__line "$@" --regex "$marker"
else
ip="$(cat "$__object/parameter/ip")"
__line "$@" --line "$ip $hostname $marker"
fi

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,2 @@
state
ip

View file

@ -1 +0,0 @@
../__chroot_mount/man.rst

View file

@ -0,0 +1,42 @@
cdist-type__install_chroot_mount(7)
===================================
NAME
----
cdist-type__install_chroot_mount - mount a chroot with install command
DESCRIPTION
-----------
Mount and prepare a chroot for running commands within it.
REQUIRED PARAMETERS
-------------------
None
OPTIONAL PARAMETERS
-------------------
None
EXAMPLES
--------
.. code-block:: sh
__install_chroot_mount /path/to/chroot
AUTHORS
-------
Steven Armstrong <steven-cdist--@--armstrong.cc>
COPYING
-------
Copyright \(C) 2012 Steven Armstrong. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -1 +0,0 @@
../__chroot_umount/man.rst

View file

@ -0,0 +1,47 @@
cdist-type__install_chroot_umount(7)
====================================
NAME
----
cdist-type__install_chroot_umount - unmount a chroot mounted by __install_chroot_mount
DESCRIPTION
-----------
Undo what __install_chroot_mount did.
REQUIRED PARAMETERS
-------------------
None
OPTIONAL PARAMETERS
-------------------
None
EXAMPLES
--------
.. code-block:: sh
__install_chroot_umount /path/to/chroot
SEE ALSO
--------
:strong:`cdist-type__install_chroot_mount`\ (7)
AUTHORS
-------
Steven Armstrong <steven-cdist--@--armstrong.cc>
COPYING
-------
Copyright \(C) 2012 Steven Armstrong. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -1 +0,0 @@
../__file/man.rst

View file

@ -0,0 +1,112 @@
cdist-type__install_file(7)
===========================
NAME
----
cdist-type__install_file - Manage files with install command.
DESCRIPTION
-----------
This cdist type allows you to create files, remove files and set file
attributes on the target.
If the file already exists on the target, then if it is a:
regular file, and state is:
present
replace it with the source file if they are not equal
exists
do nothing
symlink
replace it with the source file
directory
replace it with the source file
In any case, make sure that the file attributes are as specified.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
state
'present', 'absent' or 'exists', defaults to 'present' where:
present
the file is exactly the one from source
absent
the file does not exist
exists
the file from source but only if it doesn't already exist
group
Group to chgrp to.
mode
Unix permissions, suitable for chmod.
owner
User to chown to.
source
If supplied, copy this file from the host running cdist to the target.
If not supplied, an empty file or directory will be created.
If source is '-' (dash), take what was written to stdin as the file content.
MESSAGES
--------
chgrp <group>
Changed group membership
chown <owner>
Changed owner
chmod <mode>
Changed mode
create
Empty file was created (no --source specified)
remove
File exists, but state is absent, file will be removed by generated code.
upload
File was uploaded
EXAMPLES
--------
.. code-block:: sh
# Create /etc/cdist-configured as an empty file
__install_file /etc/cdist-configured
# The same thing
__install_file /etc/cdist-configured --state present
# Use __file from another type
__install_file /etc/issue --source "$__type/files/archlinux" --state present
# Delete existing file
__install_file /etc/cdist-configured --state absent
# Supply some more settings
__install_file /etc/shadow --source "$__type/files/shadow" \
--owner root --group shadow --mode 0640 \
--state present
# Provide a default file, but let the user change it
__install_file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \
--state exists \
--owner frodo --mode 0600
# Take file content from stdin
__install_file /tmp/whatever --owner root --group root --mode 644 --source - << DONE
Here goes the content for /tmp/whatever
DONE
AUTHORS
-------
Nico Schottelius <nico-cdist--@--schottelius.org>
COPYING
-------
Copyright \(C) 2011-2013 Nico Schottelius. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -8,16 +8,16 @@ cdist-type__package_dpkg - Manage packages with dpkg
DESCRIPTION
-----------
__package_dpkg is used on Debian and variants (like Ubuntu) to
install packages that are provided locally as *.deb files.
This type is used on Debian and variants (like Ubuntu) to
install packages that are provided locally as \*.deb files.
The object given to __package_dpkg must be the name of the deb package.
The object given to this type must be the name of the deb package.
REQUIRED PARAMETERS
-------------------
source
path to the *.deb package
path to the \*.deb package
EXAMPLES
--------

View file

@ -14,13 +14,13 @@ The object you need to pass to __postgres_extension consists of
the database name and the extension name joined by a colon in the
following form:
.. code-block::
.. code-block:: sh
dbname:extension
f.ex.
.. code-block::
.. code-block:: sh
rails_test:unaccent

View file

@ -0,0 +1,66 @@
cdist-type__prometheus_alertmanager(7)
======================================
NAME
----
cdist-type__prometheus_alertmanager - install Alertmanager
DESCRIPTION
-----------
Install and configure Prometheus Alertmanager (https://prometheus.io/docs/alerting/alertmanager/).
REQUIRED PARAMETERS
-------------------
config
Alertmanager configuration file. It will be saved as /etc/alertmanager/alertmanager.yml on the target.
listen-address
Passed as web.listen-address.
OPTIONAL PARAMETERS
-------------------
storage-path
Where to put data. Default: /data/alertmanager. (Directory will be created if needed.)
BOOLEAN PARAMETERS
------------------
with-daemontools
Create a daemontools service directory under /service/prometheus. Default: yes.
Note: If you do not use this, Alertmanager will not be launched, and will not reload config on change.
If you use this, daemontools (or something compatible) must be installed.
EXAMPLES
--------
.. code-block:: sh
ALERTPORT=9093
__daemontools
__golang_from_vendor --version 1.8.1 # required for prometheus and many exporters
require="__daemontools __golang_from_vendor" __prometheus_alertmanager \
--config "$__manifest/files/alertmanager.yml" \
--storage-path /data/alertmanager \
--listen-address "[::]:$ALERTPORT"
SEE ALSO
--------
:strong:`cdist-type__prometheus_server`\ (7), :strong:`cdist-type__daemontools`\ (7),
Prometheus alerting documentation: https://prometheus.io/docs/alerting/overview/
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,39 @@
#!/bin/sh
GOBIN=/opt/gocode/bin # where to find go binaries
CONF_DIR=/etc/prometheus
LOGLEVEL=info
CONF=$CONF_DIR/alertmanager.yml
### Prometheus server #######################################################
config="$(cat "$__object/parameter/config")"
storage_path="$(cat "$__object/parameter/storage-path")"
listen_address="$(cat "$__object/parameter/listen-address")"
ONCHANGE=""
if [ -f "$__object/parameter/with-daemontools" ]; then
__daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS"
ONCHANGE="svc -h /service/prometheus"
fi
FLAGS="config.file '$CONF'
storage.path '$storage_path'
web.listen-address '$listen_address'
log.level $LOGLEVEL"
REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')"
__go_get github.com/prometheus/alertmanager/cmd/...
__user prometheus --system
__directory "$storage_path" --owner prometheus
__directory "$CONF_DIR" --owner prometheus
__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS"
require="$require __directory/$storage_path" \
__config_file $CONF \
--source $config \
--group prometheus --mode 640 \
--onchange "$ONCHANGE"

View file

@ -0,0 +1 @@
/data/alertmanager

View file

@ -0,0 +1 @@
storage-path

View file

@ -0,0 +1,2 @@
config
listen-address

View file

@ -0,0 +1,78 @@
cdist-type__prometheus_server(7)
================================
NAME
----
cdist-type__prometheus_server - install Prometheus
DESCRIPTION
-----------
Install and configure Prometheus (https://prometheus.io/).
REQUIRED PARAMETERS
-------------------
config
Prometheus configuration file. It will be saved as /etc/prometheus/prometheus.yml on the target.
listen-address
Passed as web.listen-address.
alertmanager-url
Passed as alertmanager.url
OPTIONAL PARAMETERS
-------------------
retention-days
How long to keep data. Default: 30
rule-files
Path to rule files. They will be installed under /etc/prometheus/<filename>. You need to include `rule_files: [/etc/prometheus/<your-pattern>]` in the config file if you use this.
storage-path
Where to put data. Default: /data/prometheus. (Directory will be created if needed.)
target-heap-size
Passed as storage.local.target-heap-size. Default: 1/2 of RAM.
BOOLEAN PARAMETERS
------------------
with-daemontools
Create a daemontools service directory under /service/prometheus. Default: yes.
Note: If you do not use this, Prometheus will not be launched, and will not reload config on change.
If you use this, daemontools (or something compatible) must be installed.
EXAMPLES
--------
.. code-block:: sh
PROMPORT=9090
ALERTPORT=9093
__daemontools
__golang_from_vendor --version 1.8.1 # required for prometheus and many exporters
require="__daemontools __golang_from_vendor" __prometheus_server \
--config "$__manifest/files/prometheus.yml" \
--retention-days 14 \
--storage-path /data/prometheus \
--listen-address "[::]:$PROMPORT" \
--rule-files "$__manifest/files/*.rules" \
--alertmanager-url "http://monitoring1.node.consul:$ALERTPORT,http://monitoring2.node.consul:$ALERTPORT"
SEE ALSO
--------
:strong:`cdist-type__prometheus_alertmanager`\ (7), :strong:`cdist-type__daemontools`\ (7),
Prometheus documentation: https://prometheus.io/docs/introduction/overview/
AUTHORS
-------
Kamila Součková <kamila--@--ksp.sk>
COPYING
-------
Copyright \(C) 2017 Kamila Součková. You can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

View file

@ -0,0 +1,57 @@
#!/bin/sh
GOBIN=/opt/gocode/bin # where to find go binaries
CONF_DIR=/etc/prometheus
CONF=$CONF_DIR/prometheus.yml
LOGLEVEL=info
config="$(cat "$__object/parameter/config")"
retention_days="$(cat "$__object/parameter/retention-days")"
storage_path="$(cat "$__object/parameter/storage-path")"
listen_address="$(cat "$__object/parameter/listen-address")"
alertmanager_url="$(cat "$__object/parameter/alertmanager-url")"
target_heap_size="$(cat "$__object/parameter/target-heap-size")"
rule_files="$(cat "$__object/parameter/rule-files")"
# explorer in kB => convert; by default we go with 1/2 RAM
[ "$target_heap_size" = "auto" ] && target_heap_size=$(($(cat $__global/explorer/memory)*1024/2))
ONCHANGE=""
if [ -f "$__object/parameter/with-daemontools" ]; then
__daemontools_service prometheus --run "setuidgid prometheus $GOBIN/prometheus $REAL_FLAGS"
ONCHANGE="&& svc -h /service/prometheus"
fi
FLAGS="config.file '$CONF'
storage.local.path '$storage_path'
storage.local.target-heap-size $(($target_heap_size)) # in bytes; should be 2/3 of available memory because it may be hungry
storage.local.retention $(($retention_days*24))h # golang doesn't have days :D
web.listen-address '$listen_address'
alertmanager.url '$alertmanager_url'
log.level $LOGLEVEL"
REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')"
__go_get github.com/prometheus/prometheus/cmd/...
__user prometheus --system
__directory "$storage_path" --owner prometheus
__directory "$CONF_DIR" --owner prometheus
require="$require __directory/$storage_path" \
__config_file $CONF \
--source $config \
--group prometheus --mode 640 \
--onchange "$GOBIN/promtool check-config $CONF $ONCHANGE"
for file in $rule_files; do
dest=$CONF_DIR/$(basename $file)
require="$require __directory/$CONF_DIR" \
__config_file "$dest" \
--source "$file" \
--owner prometheus \
--onchange "$GOBIN/promtool check-rules '$dest' $ONCHANGE"
done

View file

@ -0,0 +1 @@
with-daemontools

View file

@ -0,0 +1 @@
/data/prometheus

View file

@ -0,0 +1,4 @@
target-heap-size
retention-days
rule-files
storage-path

View file

@ -0,0 +1,3 @@
alertmanager-url
config
listen-address

View file

@ -54,6 +54,9 @@ case "$state_should" in
;;
esac
;;
devuan)
echo "update-rc.d \"$name\" defaults >/dev/null"
;;
gentoo)
echo rc-update add \"$name\" \"$target_runlevel\"
@ -90,7 +93,7 @@ case "$state_should" in
else
case "$os" in
debian|ubuntu)
debian|ubuntu|devuan)
echo update-rc.d -f \"$name\" remove
;;

View file

@ -22,7 +22,7 @@
os=$(cat "$__global/explorer/os")
case "$os" in
redhat|centos|ubuntu|debian|archlinux)
redhat|centos|ubuntu|debian|devuan|archlinux)
:
;;
*)

View file

@ -18,11 +18,4 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
os="$($__explorer/os)"
if [ "$os" = "netbsd" ]; then
echo netbsd
exit
fi
usermod --help | grep -q -- '-A group' && echo true || echo false

View file

@ -23,19 +23,6 @@ state_should="$(cat "$__object/parameter/state")"
oldusermod="$(cat "$__object/explorer/oldusermod")"
os=$(cat "$__global/explorer/os")
if [ "$os" = "netbsd" ]; then
# NetBSD does not have a command to remove a user from a group
oldusermod="true"
addparam="-G"
delparam=";;#"
elif [ "$oldusermod" = "true" ]; then
addparam="-A"
delparam="-R"
else
addparam="-a"
delparam="-d"
fi
mkdir "$__object/files"
# file has to be sorted for comparison with `comm`
sort "$__object/parameter/group" > "$__object/files/group.sorted"
@ -43,11 +30,9 @@ sort "$__object/parameter/group" > "$__object/files/group.sorted"
case "$state_should" in
present)
changed_groups="$(comm -13 "$__object/explorer/group" "$__object/files/group.sorted")"
action="$addparam"
;;
absent)
changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")"
action="$delparam"
;;
esac
@ -57,9 +42,25 @@ if [ -z "$changed_groups" ]; then
fi
for group in $changed_groups; do
if [ "$oldusermod" = "true" ]; then
echo "usermod $action \"$group\" \"$user\""
if [ "$os" = "netbsd" ]; then
case "$state_should" in
present) echo "usermod -G \"$group\" \"$user\"" ;;
absent) echo 'NetBSD does not have a command to remove a user from a group' >&2 ; exit 1 ;;
esac
elif [ "$os" = "freebsd" ]; then
case "$state_should" in
present) echo "pw groupmod \"$group\" -m \"$user\"" ;;
absent) echo "pw groupmod \"$group\" -d \"$user\"" ;;
esac
elif [ "$oldusermod" = "true" ]; then
case "$state_should" in
present) echo "usermod -A \"$group\" \"$user\"" ;;
absent) echo "usermod -R \"$group\" \"$user\"" ;;
esac
else
echo "gpasswd $action \"$user\" \"$group\""
case "$state_should" in
present) echo "gpasswd -a \"$group\" \"$user\"" ;;
absent) echo "gpasswd -d \"$group\" \"$user\"" ;;
esac
fi
done

View file

@ -29,6 +29,8 @@ import tempfile
import socket
import multiprocessing
from cdist.mputil import mp_pool_run
import atexit
import shutil
import cdist
import cdist.hostsource
@ -94,7 +96,6 @@ class Config(object):
"failed: %s" % e))
args.manifest = initial_manifest_temp_path
import atexit
atexit.register(lambda: os.remove(initial_manifest_temp_path))
# default remote cmd patterns
@ -177,8 +178,15 @@ class Config(object):
" ".join(failed_hosts))
@classmethod
def _resolve_remote_cmds(cls, args, host_base_path):
control_path = os.path.join(host_base_path, "ssh-control-path")
def _resolve_ssh_control_path(cls):
base_path = tempfile.mkdtemp()
control_path = os.path.join(base_path, "s")
atexit.register(lambda: shutil.rmtree(base_path))
return control_path
@classmethod
def _resolve_remote_cmds(cls, args):
control_path = cls._resolve_ssh_control_path()
# If we constructed patterns for remote commands then there is
# placeholder for ssh ControlPath, format it and we have unique
# ControlPath for each host.
@ -201,8 +209,7 @@ class Config(object):
log = logging.getLogger(host)
try:
remote_exec, remote_copy = cls._resolve_remote_cmds(
args, host_base_path)
remote_exec, remote_copy = cls._resolve_remote_cmds(args)
log.debug("remote_exec for host \"{}\": {}".format(
host, remote_exec))
log.debug("remote_copy for host \"{}\": {}".format(

View file

@ -153,7 +153,8 @@ class Manifest(object):
message_prefix = "initialmanifest"
self.local.run_script(initial_manifest,
env=self.env_initial_manifest(initial_manifest),
message_prefix=message_prefix)
message_prefix=message_prefix,
save_output=False)
def env_type_manifest(self, cdist_object):
type_manifest = os.path.join(self.local.type_path,
@ -178,4 +179,5 @@ class Manifest(object):
if os.path.isfile(type_manifest):
self.local.run_script(type_manifest,
env=self.env_type_manifest(cdist_object),
message_prefix=message_prefix)
message_prefix=message_prefix,
save_output=False)

View file

@ -149,6 +149,7 @@ class Local(object):
self.mkdir(self.global_explorer_out_path)
self.mkdir(self.object_path)
self.mkdir(self.bin_path)
self.mkdir(self.cache_path)
def create_files_dirs(self):
self._init_directories()
@ -231,7 +232,7 @@ class Local(object):
message.merge_messages()
def run_script(self, script, env=None, return_output=False,
message_prefix=None):
message_prefix=None, save_output=True):
"""Run the given script with the given environment.
Return the output as a string.
@ -240,7 +241,7 @@ class Local(object):
command.append(script)
return self.run(command=command, env=env, return_output=return_output,
message_prefix=message_prefix)
message_prefix=message_prefix, save_output=save_output)
def save_cache(self):
destination = os.path.join(self.cache_path, self.hostdir)

View file

@ -36,7 +36,7 @@ def inspect_ssh_mux_opts():
wanted_mux_opts = {
"ControlPath": "{}",
"ControlMaster": "auto",
"ControlPersist": "125",
"ControlPersist": "10",
}
mux_opts = " ".join([" -o {}={}".format(
x, wanted_mux_opts[x]) for x in wanted_mux_opts])

View file

@ -2,6 +2,30 @@ Changelog
---------
next:
* Type __golang_from_vendor: Install golang from https://golang.org/dl/ (Kamila Součková)
* Type __go_get: Install go packages using go get (Kamila Součková)
* Explorer kernel_name: uname -s (Kamila Součková)
* Type __sysctl: Add devuan support (Nico Schottelius)
* Type __start_on_boot: Add devuan support (Nico Schottelius)
* Core: Shorten ssh control path (Darko Poljak)
* Type __consul: Add new version and add http check (Kamila Součková)
* New types: __daemontools and __daemontools_service (Kamila Součková)
* New types: __prometheus_server and __prometheus_alertmanager (Kamila Součková)
* New type: __grafana_dashboard (Kamila Součková)
4.4.2: 2017-03-08
* Core: Fix suppression of manifests' outputs (Darko Poljak)
* Type __user_groups: Support FreeBSD (Andres Erbsen)
* Type __cron: Fix filter for new cron on sles12 sp2 (Daniel Heule)
* Type __docker: Support absent state (Dominique Roux)
* Type __docker_compose: Support absent state (Dominique Roux)
* New type: __hosts (Dmitry Bogatov)
* New type: __dot_file (Dmitry Bogatov)
4.4.1: 2016-12-17
* Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak)
* Type __cron: Remove '# marker' for raw_command due to cron security (Daniel Heule)
* New type: __docker_compose (Dominique Roux)
* Type __apt_mark: Check supported apt version and if package is installed (Ander Punnar)
* New type: __docker (Steven Armstrong)
* New type: __package_dpkg (Tomas Pospisek)

View file

@ -0,0 +1,5 @@
* After constructs don't exist
Flow as implemented on 2013-04-12 has the problem of not allowing
*after* constructs.
* "Type explorer & manifests only" is broken
Doesn't catch external dependencies

View file

@ -51,6 +51,19 @@ Example:
__myfancysingleton --colour green
Config types
------------
By default types are used with config command. These are types that are not
flagged by any known command flag. If a type is marked then it will be skipped
with config command.
Install types
-------------
If a type is flagged with 'install' flag then it is used only with install command.
With other commands, i.e. config, these types are skipped if used.
How to write a new type
-----------------------
A type consists of
@ -209,6 +222,18 @@ As you can see, the object ID is omitted, because it does not make any sense,
if your type can be used only once.
Install - type with install command
-----------------------------------
If you want a type to be used with install command, you must mark it as
install: create the (empty) file "install" in your type directory:
.. code-block:: sh
touch cdist/conf/type/__install_NAME/install
With other commands, i.e. config, it will be skipped if used.
The type explorers
------------------
If a type needs to explore specific details, it can provide type specific

Some files were not shown because too many files have changed in this diff Show more