Skip to content

Instantly share code, notes, and snippets.

@mccun934
mccun934 / gist:6711c249ab077dfa8d7d526dcc501a8a
Created February 13, 2018 13:41
delete orphan dynflow data
cat <<EOF | foreman-rake console
persistence = ForemanTasks.dynflow.world.persistence
adapter = persistence.adapter
batch_size = 5
total = adapter.db.fetch("select count(dynflow_execution_plans.uuid) from dynflow_execution_plans left join foreman_tasks_tasks on (dynflow_execution_plans.uuid = foreman_tasks_tasks.external_id) where foreman_tasks_tasks.id IS NULL").first[:count]
deleted = 0
puts "about to delete #{total} execution plans"
while (plans_without_tasks = adapter.db.fetch("select dynflow_execution_plans.uuid from dynflow_execution_plans left join foreman_tasks_tasks on (dynflow_execution_plans.uuid = foreman_tasks_tasks.external_id) where foreman_tasks_tasks.id IS NULL LIMIT #{batch_size}").all.map { |x| x[:uuid] }) && !plans_without_tasks.empty?
persistence.delete_execution_plans({ 'uuid' => plans_without_tasks }, batch_size)
#!/bin/bash
###################################
# USAGE:
# ./subs-export.csv.bash <ORG NAME>
#
# NOTE: If you run this without the
# organization name as a parameter
# it will return 0 results.
###################################
@mccun934
mccun934 / task-cleanup.bash
Created February 8, 2018 15:42
Common task cleanup commands
# Delete all paused
foreman-rake foreman_tasks:cleanup TASK_SEARCH='label ~ *' AFTER='0d' STATES=paused VERBOSE=true
# Delete all stopped
foreman-rake foreman_tasks:cleanup TASK_SEARCH='label ~ *' AFTER='0d' STATES=stopped VERBOSE=true
# Delete everything
#!/bin/bash
SIZES="SELECT relname AS objectname,
relkind AS objecttype,
reltuples AS "entries", pg_size_pretty(relpages::bigint*8*1024) AS size
FROM pg_class
WHERE relpages >= 8
ORDER BY relpages DESC;"
#!/bin/bash
TABLE_COUNTS="select count(*) as foreman_tasks_tasks from foreman_tasks_tasks;
select count(*) as foreman_tasks_locks from foreman_tasks_locks;
select count(*) as dynflow_execution_plans from dynflow_execution_plans;
select count(*) as dynflow_actions from dynflow_actions;
select count(*) as dynflow_steps from dynflow_steps;"
echo ""
echo "Table counts :"
<pre><font color="#06989A"><b>Upgrade Step: correct_repositories (this may take a while) ...</b></font>
<font color="#CC0000"><b>rake aborted!</b></font>
<font color="#CC0000"><b>Not all the services have been started. Check the status report above and try again.</b></font>
<font color="#CC0000"><b>/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.0.158/lib/katello/tasks/reimport.rake:8:in `block (2 levels) in &lt;top (required)&gt;&apos;</b></font>
<font color="#CC0000"><b>Tasks: TOP =&gt; katello:correct_repositories =&gt; katello:check_ping</b></font>
<font color="#CC0000"><b>(See full trace by running task with --trace)</b></font>
<font color="#CC0000"><b>{:status=&gt;&quot;FAIL&quot;,</b></font>
<font color="#CC0000"><b> :services=&gt;</b></font>
<font color="#CC0000"><b> {:pulp=&gt;{:status=&gt;&quot;ok&quot;, :duration_ms=&gt;&quot;46&quot;},</b></font>
<font color="#CC0000"><b> :pulp_auth=&gt;{:status=&gt;&quot;ok&quot;, :duration_ms=&gt;&quot;57&quot;},</b></font>
@mccun934
mccun934 / gist:424daee4f2edb7c6850fc25ffb6e3346
Last active January 24, 2018 17:48
Upgrade just candlepin
1) stop services:
# katello-service stop
# systemctl start postgresql
2) Upgrade RPMs
# yum update candlepin candlepin-tomcat candlepin-selinux
3) Update the candlepin database:
@mccun934
mccun934 / enable-pcp.bash
Last active January 12, 2018 14:59
Enable PCP
yum -y install pcp pcp-system-tools
systemctl start pmcd pmlogger
systemctl enable pmcd pmlogger
subscription-manager repos --enable rhel-7-server-optional-rpms
yum -y install pcp-webapi pcp-webapp-grafana \
pcp-webapp-graphite pcp-webapp-vector
systemctl start pmwebd
@mccun934
mccun934 / task-cleanup-61.bash
Last active December 11, 2017 17:15
Cleanup tasks older than 5 days on Satellite 6.1
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# This will delete all tasks and associated task data from anything older than
# the number of days specified below defaulting to 120 days.
#DAYS_AGO=120
DAYS_AGO=16
echo ""
echo "DELETING All tasks and associated data from [$DAYS_AGO] days ago"
@mccun934
mccun934 / gencerts.sh
Created November 14, 2017 20:10 — forked from JacobCallahan/gencerts.sh
Satellite certificate generator script
#! /bin/bash
git clone https://github.com/iNecas/ownca.git
cd ownca
yes "" | ./generate-ca.sh
yes | ./generate-crt.sh $(hostname)
certdir="$(pwd)/$(hostname)/"
cp cacert.crt $(hostname)/
cd $(hostname)
katello-certs-check -c "$(hostname).crt" -k "$(hostname).key" -r "$(hostname).crt.req" -b cacert.crt