Skip to content

Instantly share code, notes, and snippets.

@clburlison
Last active February 28, 2018 19:36
Show Gist options
  • Save clburlison/83a0753810e110cbef967a4cc3f0ef74 to your computer and use it in GitHub Desktop.
Save clburlison/83a0753810e110cbef967a4cc3f0ef74 to your computer and use it in GitHub Desktop.
A dirty mwa2 ubuntu 16 guide.

A dirty guide to setup MWA2 on Ubuntu 16. I want to convert this into a blog just haven't found the time.

Go full yolo sudo su

Install packages apt-get install git nginx python-pip python-dev

Let's create our mwa2 web config (no ssl so it's easier & using root because yolo) This is also bad practice since we're writing directly to sites-enabled. You might need to make changes to this config so it doesn't fight with other configurations you might have.

nano /etc/nginx/sites-enabled/mwa2.conf

server {
  listen 80; # Might need an alternative port like 8080 if no DNS access
  server_name admin.example.com; # Change this

  location = /favicon.ico { access_log off; log_not_found off; }

  location / {
    proxy_pass http://127.0.0.1:8001;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    port_in_redirect off;
    proxy_connect_timeout  300s;
    proxy_send_timeout  600s;
    proxy_read_timeout  600s;
  }
}

A script to install mwa2. So read the commands if you want to know what is happening. First lets write the script to disk. This script does the installation.

mkdir /setup

nano /setup/mwa2_install.sh

Make sure and change the very last echo line to match the info you want. Default account is U: admin P: password

#!/bin/bash
set -x
useradd -M mwa2_user
usermod -L mwa2_user
pip install virtualenv
cd /usr/local/
virtualenv mwa2_env
cd mwa2_env
source bin/activate
pip install Django==1.9.1
pip install django-wsgiserver==0.8.0rc1
pip install gunicorn==19.4.5
sed -i "s/self.validate(display_num_errors=True)/self.check(display_num_errors=True)/" lib/python2.7/site-packages/django_wsgiserver/management/commands/runwsgiserver.py
git clone https://github.com/munki/mwa2.git
git clone https://github.com/munki/munki.git
cp mwa2/munkiwebadmin/settings_template.py mwa2/munkiwebadmin/settings.py
sed -i "s/'\/Users\/Shared\/munki_repo'/'\/usr\/local\/munki_repo'/" mwa2/munkiwebadmin/settings.py
sed -i "s/'\/usr\/local\/munki\/makecatalogs'/'\/usr\/local\/mwa2_env\/munki\/code\/client\/makecatalogs'/" mwa2/munkiwebadmin/settings.py
python mwa2/manage.py migrate --noinput
python mwa2/manage.py collectstatic --noinput
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', '[email protected]', 'password')" | python mwa2/manage.py shell
deactivate
chown -R mwa2_user:mwa2_user /usr/local/mwa2_env

Add execute bit chmod +x /setup/mwa2_install.sh

Run the script /setup/mwa2_install.sh

Let's create a service to run mwa2 nano /etc/systemd/system/mwa2.service

[Unit]
Description=MunkiWebAdmin2
After=network.target

[Service]
ExecStart=/usr/local/mwa2_env/bin/python /usr/local/mwa2_env/mwa2/manage.py runwsgiserver port=8001 host=127.0.0.1
Restart=always

[Install]
WantedBy=multi-user.target

Start and enable the serivce systemctl start mwa2

systemctl enable mwa2

Restart our web server systemctl restart nginx


Troubleshooting

Disable nginx sudo systemctl stop nginx

Run the mwa2 service directly with NOTE this is on port 80

/usr/local/mwa2_env/bin/python /usr/local/mwa2_env/mwa2/manage.py runwsgiserver port=80 host=0.0.0.0
@babgond
Copy link

babgond commented Mar 22, 2017

Hello,
I think it is better to specify port 8080 directly instead of 80.
If we followed the tutorial "https://clburlison.com/munkirepo-guide-part-1/" port 80 is already used in "/etc/nginx /sites-enabled / default"
Thank you for your work !

server {
  listen 80; # Might need an alternative port like 8080 if no DNS access
  server_name admin.example.com; # Change this

  location = /favicon.ico { access_log off; log_not_found off; }

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