Adding an easy discourse command

pr-welcome

(Ani) #1

I recommend adding the following code to .bash_profile as it grants easier and faster access to discourse.

function discourse {
	if [ "$1" = "cleanup" ]; then 
		echo "CLEANUP INITIATED"
		~/discourse_cleanup.sh
		echo "CLEANUP COMPLETE"
	elif [ "$1" = "goto" ]; then 
		if [ "$2" = "c" ] || [ "$2" = "container" ]; then
			cd /var/discourse/containers/
		else
			cd /var/discourse/
		fi
	elif [ "$1" = "dir" ]; then
		if [ "$2" = "c" ] || [ "$2" = "container" ]; then
			echo "/var/discourse/containers/"
		else
			echo "/var/discourse/"
		fi
	else 
		/var/discourse/launcher "$@"
	fi
}

The contents of ~/discourse_cleanup.sh are…

docker inspect -f '{{.Id}},{{.State.Running}},{{.State.FinishedAt}}' $(docker ps -qa) | \
  awk -F, 'BEGIN { TIME=strftime("%FT%T.000000000Z",systime()-60*60*24); } $2=="false" && $3 < TIME {print $1;}' | \
  xargs --no-run-if-empty docker rm >/dev/null 2>/dev/null
docker images --no-trunc| grep none | awk '{print $3}' | xargs -r docker rmi

All users have the same IP (the Servers IP)?
(Sam Saffron) #2

I just want ./launcher to support this natively … ./launcher cleanup should clean up. PR welcome.


(Ani) #3

PR created… Added cleanup command by Supermathie by LuaTenshi · Pull Request #128 · discourse/discourse_docker · GitHub


(Sam Saffron) #4

updated the PR with some comments, I want to get it in just want to make sure its super usable.