c(s, py | man)
is The CS Python Course Manager is module used to automate multiple teaching actions related to assignment submission, website publishing and logging.
###Setup & Installation
c(s, py | man)
is based on the the git_hook Flask app. For detailed installation and setup instructions, follow the steps outlined in that repo's readme file.
####Extra Packages Due to issues with sending bulk email, we are currently using Mandrill and its API to send emails. To install Mandrill, you run:
sudo pip install mandrill
####Configuration
cspy_man.uwsgi.ini
- used to deploy the webapp ( no need to edit this file )cspy_man.conf.ini
- used to configure the app behaviours ( must edit )$WEBSITE_NAME
- is a variable that should be replaced with the actual website name
####Basic Setup
- Rename
cspy_man.conf.sample.ini
tocspy_man.conf.ini
- Update
cspy_man.conf.ini
to reflect your configuration - Install required software
- Configure your web server
location = /git { rewrite ^ /git/; }
location /git { try_files $uri @git; }
location @git {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /git;
uwsgi_modifier1 30;
uwsgi_pass unix:/tmp/uwsgi-cspy_man.uwsgi.sock;
}
- Configure supervisor
[program:cspy_man]
command=/usr/local/bin/uwsgi --ini /home/www/$WEBSITE_NAME/cspy_man/cspy_man.uwsgi.ini
directory=/home/www/$WEBSITE_NAME/cspy_man
;user=www-data
numprocs=1
autostart=true
autorestart=true
stdout_logfile=/home/www/$WEBSITE_NAME/logs/uwsgi-supervisord.log
redirect_stderr=true
stopsignal=INT
- Install
c(s, py | man)
cd
git clone git@github.com:usc-csci104-spring2014/cspy_man.git
sudo chown -R $USER:www-data cspy_man
sudo mv cspy_man /home/www/$WEBSITE_NAME/
##Implemented Services:
This is written as a git post-receive hook. Note that this hook expects the GitHub JSON payload. When a commit is (or set of commits are) pushed to the repository, the following happens:
- The [head] commit is parsed.
- The
website_deploy.sh
script is executed. - An email using the
website_deployed.txt
template is prepared
####Deployment script
website_deploy.sh
is written to be compatible with aludra.usc.edu
and must have the following variables properly set:
$HOME
directory for thewww-data
user. You can set that by
sudo usermod -d /home/www www-data
WEBSITE_REPO
- course_website git repowww-data
must have read/write access to the repo
git clone git@github.com:usc-csci104-spring2014/course_website.git
cd course_website
git checkout -b deploy remotes/origin/deploy
git checkout master
cd ..
export WORKSPACE=/home/www/$WEBSITE_NAME/cspy_man_workspace
sudo mkdir -p $WORKSPACE
sudo mv course_website $WORKSPACE
sudo chown -R www-data:www-data $WORKSPACE
SSH_REMOTE_USER
- username onaludra
SSH_REMOTE_SERVER
- default:aludra.usc.edu
- Generate SSH Keys for
www-data
(with no passphrase)
#Generate Keyparis
sudo su - www-data -c 'ssh-keygen -t rsa -b 4096 -C "www-data@$(hostname -f)"'
- Add the public key to:
- GitHub, and
- aludra's authorized keys
sudo cat $(cat /etc/passwd | grep ^www-data | cut -d: -f6)/.ssh/id_rsa.pub
- Disable Host Key Checking
sudo su - www-data -s /bin/bash -c 'echo -e "Host *\n\tStrictHostKeyChecking no" | tee -a $HOME/.ssh/config'
- Setup git user profile for
www-data
to be a bot, in this casealghanmi-bot
sudo su - www-data -s /bin/bash -c 'git config --global user.name "alghanmi-bot"'
sudo su - www-data -s /bin/bash -c 'git config --global user.email "alghanmi+bot@usc.edu"'
sudo su - www-data -s /bin/bash -c 'git config --global core.editor vim'
sudo su - www-data -s /bin/bash -c 'git config --global merge.tool vimdiff'
sudo su - www-data -s /bin/bash -c 'git config --global core.autocrlf input'
sudo su - www-data -s /bin/bash -c 'git config --global push.default simple'
- Turn off the app and all its services
sudo service supervisor stop; sudo pkill -9 uwsgi
- Check Running Services
ps -ef | grep -v 'tail -f' | grep uwsgi && echo '' && ps -ef | grep -v 'tail -f' | grep super
- Check Logs
sudo tail -f /home/www/$WEBSITE_NAME/logs/error.log /home/www/$WEBSITE_NAME/logs/access.log /home/www/$WEBSITE_NAME/logs/uwsgi-supervisord.log /var/log/uwsgi/cspy_man.log /var/log/uwsgi/cspy_man.uwsgi.log /var/log/supervisor/cspy_man-*.log /var/log/supervisor/supervisord.log
- Run script as another user
sudo su -c "bash /home/www/$WEBSITE_NAME/cspy_man/scripts/website_deploy.sh" -s /bin/bash www-data
alias cspystatus='sudo su - www-data -c '"'"'cd ~/$WEBSITE_NAME/cspy_man; git status'"'"''
alias cspypull='sudo su - www-data -c '"'"'cd ~/$WEBSITE_NAME/cspy_man; git pull'"'"''