Skip to content

Instantly share code, notes, and snippets.

@TanyaCouture
Last active February 15, 2016 16:32
Show Gist options
  • Save TanyaCouture/b5eead349fb5f7070d29 to your computer and use it in GitHub Desktop.
Save TanyaCouture/b5eead349fb5f7070d29 to your computer and use it in GitHub Desktop.
logrotate packaging plans
`mantl-logrotate`
tasks/main.yml
// set logrotate interval to daily
// in file /etc/logrotate.conf
// look for reg expression '^weekly'
// replace last matching line of reg expression with "daily"
packaging solutions:
sed 's/\(.*\)^weekly/daily/' /etc/logrotate.conf
// set logrotate retention period to 7 days
// in file /etc/logrotate.conf
// replace last matching line of reg expression '^rotate 4' with "rotate 7"
packaging solutions:
sed 's/\(.*\)^rotate 4/rotate 7/' /etc/logrotate.conf
// copy component logrotate configurations
// when mesos=true docker=true and in zookeeper role == 'control'
// copy component to logrotate configurations
/etc/logrotate/component
// set mode to 0644
packaging solutions:
// call on script: when mesos and docker are installed on all nodes and zookeeper is on leader nodes, copy components to logrotate
script:
#!/bin/bash
for component in "mesos" "docker" "zookeeper"; do
systemctl status $component
if[ $? == 0 ]; then
cp $component /etc/logrotate/
chmod 0644 /etc/logrotate/$component
else
echo $component not active
fi
done
// create component archives
// same conditions as above
// copy components to archives
// /var/log/component/archive
packaging solutions:
// call on script: when mesos and docker are installed on all nodes and zookeeper is on leader nodes, copy components to archive
script:
#!/bin/bash
for component in "mesos" "docker" "zookeeper"; do
systemctl status $component
if[ $? == 0 ]; then
sudo cp $component /var/log/$component/archive
sudo chmod 0644 /var/log/$component/archive
else
echo $component not active
fi
done
+ 3 template files
@sehqlr
Copy link

sehqlr commented Feb 15, 2016

In Bash, when you are making a reference to a variable, you need to append $ to it's name. But, you don't when you are assigning it.
So, for component in blah .. will work, but systemctl status component won't. It needs to be systemctl status $component.

Also, on line 14, there is a \ right before the second rotate. I haven't run the code, but it looks like it won't work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment