forked from ungleich-public/cdist
Merge branch 'master' into __jail
This commit is contained in:
commit
ace13f3582
34 changed files with 564 additions and 129 deletions
|
|
@ -35,14 +35,25 @@ month::
|
|||
See crontab(5). Defaults to *
|
||||
day_of_week::
|
||||
See crontab(5). Defaults to *
|
||||
raw::
|
||||
Take whatever the user has given instead of time and date fields.
|
||||
If given, all other time and date fields are ignored.
|
||||
Can for example be used to specify cron EXTENSIONS like reboot, yearly etc.
|
||||
See crontab(5) for the extensions if any that your cron implementation
|
||||
implements.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
# add cronjob
|
||||
__cron some-id --user root --command "/path/to/script"
|
||||
# run Monday to Saturday at 23:15
|
||||
__cron some-id --user root --command "/path/to/script" \
|
||||
--hour 23 --minute 15 --day_of_week 1-6
|
||||
|
||||
# run on reboot
|
||||
__cron some-id --user root --command "/path/to/script" \
|
||||
--raw @reboot
|
||||
|
||||
# remove cronjob
|
||||
__cron some-id --user root --command "/path/to/script" --state absent
|
||||
|
|
|
|||
|
|
@ -23,44 +23,23 @@ user="$(cat "$__object/parameter/user")"
|
|||
command="$(cat "$__object/parameter/command")"
|
||||
|
||||
# set defaults
|
||||
if [ ! -f "$__object/parameter/state" ]; then
|
||||
echo "present" > "$__object/parameter/state"
|
||||
fi
|
||||
if [ -f "$__object/parameter/minute" ]; then
|
||||
minute="$(cat "$__object/parameter/minute")"
|
||||
test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state"
|
||||
|
||||
if [ -f "$__object/parameter/raw" ]; then
|
||||
raw="$(cat "$__object/parameter/raw")"
|
||||
entry="$raw $command"
|
||||
else
|
||||
minute="*"
|
||||
echo "$minute" > "$__object/parameter/minute"
|
||||
fi
|
||||
if [ -f "$__object/parameter/hour" ]; then
|
||||
hour="$(cat "$__object/parameter/hour")"
|
||||
else
|
||||
hour="*"
|
||||
echo "$hour" > "$__object/parameter/hour"
|
||||
fi
|
||||
if [ -f "$__object/parameter/day_of_month" ]; then
|
||||
day_of_month="$(cat "$__object/parameter/day_of_month")"
|
||||
else
|
||||
day_of_month="*"
|
||||
echo "$day_of_month" > "$__object/parameter/day_of_month"
|
||||
fi
|
||||
if [ -f "$__object/parameter/month" ]; then
|
||||
month="$(cat "$__object/parameter/month")"
|
||||
else
|
||||
month="*"
|
||||
echo "$month" > "$__object/parameter/month"
|
||||
fi
|
||||
if [ -f "$__object/parameter/day_of_week" ]; then
|
||||
day_of_week="$(cat "$__object/parameter/day_of_week")"
|
||||
else
|
||||
day_of_week="*"
|
||||
echo "$day_of_week" > "$__object/parameter/day_of_week"
|
||||
minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
|
||||
hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
|
||||
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"
|
||||
fi
|
||||
|
||||
# NOTE: if changed, also change in explorers
|
||||
prefix="#cdist:__cron/$name"
|
||||
suffix="#/cdist:__cron/$name"
|
||||
echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry"
|
||||
echo "$minute $hour $day_of_month $month $day_of_week $command" >> "$__object/parameter/entry"
|
||||
echo "$entry" >> "$__object/parameter/entry"
|
||||
echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry"
|
||||
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ hour
|
|||
day_of_month
|
||||
month
|
||||
day_of_week
|
||||
raw
|
||||
|
|
|
|||
|
|
@ -22,6 +22,15 @@
|
|||
#
|
||||
|
||||
name=$__object_id
|
||||
os_version="$($__explorer/os_version)"
|
||||
|
||||
getent gshadow "$name" || true
|
||||
case "$os_version" in
|
||||
"Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*)
|
||||
# TODO: find a way to get this information
|
||||
echo "$os_version does not have getent gshadow"
|
||||
;;
|
||||
*)
|
||||
getent gshadow "$name" || true
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
|||
|
|
@ -23,23 +23,36 @@
|
|||
#
|
||||
|
||||
name="$__object_id"
|
||||
os_version="$(cat "$__global/explorer/os_version")"
|
||||
|
||||
cd "$__object/parameter"
|
||||
if grep -q "^${name}:" "$__object/explorer/group"; then
|
||||
for property in $(ls .); do
|
||||
new_value="$(cat "$property")"
|
||||
# argument to pass the groupmod command for this property (exceptions
|
||||
# are made in the case statement below)
|
||||
proparg="--$property"
|
||||
|
||||
case "$property" in
|
||||
password)
|
||||
current_value="$(awk -F: '{ print $2 }' < "$__object/explorer/gshadow")"
|
||||
case "$os_version" in
|
||||
"Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*)
|
||||
# TODO: Use gpasswd? Need to fix gshadow explorer first.
|
||||
echo "group/$name: '$os_version' groupmod does not support password modification" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
gid)
|
||||
# set to -g to support older redhat/centos
|
||||
proparg="-g"
|
||||
current_value="$(awk -F: '{ print $3 }' < "$__object/explorer/group")"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$new_value" != "$current_value" ]; then
|
||||
set -- "$@" "--$property" \"$new_value\"
|
||||
set -- "$@" "$proparg" \"$new_value\"
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
|
|||
55
conf/type/__mysql_database/gencode-remote
Executable file
55
conf/type/__mysql_database/gencode-remote
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2012 Benedikt Koeppel (code@benediktkoeppel.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/>.
|
||||
#
|
||||
#
|
||||
|
||||
# if --database was specified
|
||||
if [ -f "$__object/parameter/name" ]; then
|
||||
database="$(cat "$__object/parameter/name")"
|
||||
else # otherwise use the object id as database name
|
||||
database="$__object_id"
|
||||
fi
|
||||
|
||||
cat <<-EOFF
|
||||
mysql -u root <<-EOF
|
||||
CREATE DATABASE IF NOT EXISTS $database
|
||||
EOF
|
||||
EOFF
|
||||
|
||||
# if --user was specified
|
||||
if [ -f "$__object/parameter/user" ]; then
|
||||
user="$(cat "$__object/parameter/user")"
|
||||
|
||||
# if --password was specified
|
||||
if [ -f "$__object/parameter/password" ]; then
|
||||
password="$(cat "$__object/parameter/password")"
|
||||
cat <<-EOFF
|
||||
mysql -u root <<-EOF
|
||||
GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost' IDENTIFIED BY '$password';
|
||||
EOF
|
||||
EOFF
|
||||
else
|
||||
password=""
|
||||
cat <<-EOFF
|
||||
mysql -u root <<-EOF
|
||||
GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost';
|
||||
EOF
|
||||
EOFF
|
||||
fi
|
||||
fi
|
||||
49
conf/type/__mysql_database/man.text
Normal file
49
conf/type/__mysql_database/man.text
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
cdist-type__mysql_database(7)
|
||||
=============================
|
||||
Benedikt Koeppel <code@benediktkoeppel.ch>
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__mysql_database - Manage a MySQL database
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type allows you to install a MySQL database.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
name::
|
||||
The name of the database to install
|
||||
defaults to the object id
|
||||
|
||||
user::
|
||||
A user that should have access to the database
|
||||
|
||||
password::
|
||||
The password for the user who manages the database
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
__mysql_database "cdist" --name "cdist" --user "myuser" --password "mypwd"
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist-type(7)
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
||||
3
conf/type/__mysql_database/parameter/optional
Normal file
3
conf/type/__mysql_database/parameter/optional
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
name
|
||||
user
|
||||
password
|
||||
|
|
@ -30,6 +30,10 @@ fi
|
|||
# Don't produce "no pkgs installed" output -- breaks things
|
||||
PKG_OUTPUT=$(pkg_info 2>&1)
|
||||
if [ ! "$PKG_OUTPUT" = "pkg_info: no packages installed" ]; then
|
||||
echo "$(echo "$PKG_OUTPUT" | grep "^$name-" | cut '-d ' -f1 | sed "s/$name-//g")"
|
||||
echo -n "$(echo "$PKG_OUTPUT" \
|
||||
| awk '{print $1}' \
|
||||
| sed 's/^\(.*\)-\([^-]*\)$/name:\1 ver:\2/g' \
|
||||
| grep "name:$name ver:" \
|
||||
| sed 's/^.*ver:\(.*\)/\1/g')"
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -44,14 +44,13 @@ case "$os" in
|
|||
done
|
||||
;;
|
||||
|
||||
debian|ubuntu)
|
||||
debian|ubuntu|openwrt)
|
||||
state="present"
|
||||
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
|
||||
;;
|
||||
|
||||
centos|fedora|owl|redhat)
|
||||
state="present"
|
||||
state=$(chkconfig --level "$runlevel" \"$name\" || echo absent)
|
||||
amazon|centos|fedora|owl|redhat)
|
||||
state=$(chkconfig --level "$runlevel" "$name" || echo absent)
|
||||
[ "$state" ] || state="present"
|
||||
;;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,17 @@ case "$state_should" in
|
|||
# echo rc-update add \"$name\" default
|
||||
# ;;
|
||||
|
||||
centos|fedora|owl|redhat)
|
||||
amazon|centos|fedora|owl|redhat)
|
||||
echo chkconfig \"$name\" on
|
||||
;;
|
||||
|
||||
openwrt)
|
||||
# 'enable' can be successful and still return a non-zero exit
|
||||
# code, deal with it by checking for success ourselves in that
|
||||
# case (the || ... part).
|
||||
echo "/etc/init.d/\"$name\" enable || [ -f /etc/rc.d/S??\"$name\" ]"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unsupported os: $os" >&2
|
||||
exit 1
|
||||
|
|
@ -74,6 +81,10 @@ case "$state_should" in
|
|||
echo chkconfig \"$name\" off
|
||||
;;
|
||||
|
||||
openwrt)
|
||||
echo "\"/etc/init.d/$name\" disable"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unsupported os: $os" >&2
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue