Recent Notes
Poetry Uploads
Uploading Packages to PyPi With Poetry
Setting a pypi repository token:
-
create a token on pypi. Create a specific token for each package.
-
copy the token and put it somewhere safe.
-
Save your token with poetry. Poetry will try to use keyring to store the token:
poetry config pypi-token.dover-test
poetry config pyi-token.pypi my-token
this is what poetry does
-
fetches the repo url from your local config file (On Linux Mint this is located here: ~/.config/pypoetry/config.toml. )
tmux stuff
N.B. I always reset the tmux command option from ctrl + b to ctrl + a.
Sessions
- List all tmux sessions:
tmux lsorctrl + a s:
... tmux ls
... 0: 4 windows (created Sat Nov 23 08:44:49 2019) [158x78] (attached)
Windows
-
New Window:
ctrl + a n -
Switch/select window:
ctrl + a 0...9 -
Move window:
ctrl + a :and:swap-window -t [window-number|+/-move-positions]Swap window:ctrl + a :and:swap-window -s [window-number] -t [window-number]
Linux and My Apple SuperDrive
I have an Apple SuperDrive 2 that would not work on Linux Mint 19. The drive was visible when it plugged it, but would not accept disks. Fortunately I found this article with instruction on how to wake up Apple’s drive and start working.
Here’s the basics:
-
Install
sg3-utils:... sudo apt-get install sg3-utils -
Find the device id (likely
sr0orsr1). Mine wassr0:... ls -al /dev | grep sr lrwxrwxrwx 1 root root 3 Nov 10 11:46 cdrom -> sr0 lrwxrwxrwx 1 root root 3 Nov 10 11:46 cdrw -> sr0 lrwxrwxrwx 1 root root 3 Nov 10 11:46 dvd -> sr0 lrwxrwxrwx 1 root root 3 Nov 10 11:46 dvdrw -> sr0 brw-rw----+ 1 root cdrom 11, 0 Nov 10 11:46 sr0 -
Wake the drive up:
Working With Poetry
Installing A Working Environment With An Existing Project
This always messes me up.
-
Run
poetry install. This will create a new virtual env and install all your dependencies in it.... poetry install -
Now to use it properly, you need to be in the shell:
... poetry shell -
From here any application commands you have registered in your poetry
pyproject.tomlfile should work:... app-cmd --helpIn theory, you should be able to run this outside the shell:
Manage Static Sites
-
On the server run:
... python3.6 nginx_site.py create my.sitename.com -
Change the access for the root of the site folder so we can easily push changes:
... sudo chown user:user /var/www/com_sitename_my -
Now we can push the static files generated by Pelican to the server:
# the manual way ... scp -r output/* mark.staticsites:/var/www/thebitsilo_com_notes # or via pelican ... inv publish
Linux Server Maintenance
Updating Ubuntu:
```bash
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt autoremove
reboot
```
Listing user groups:
```bash
... getent group | sort
```
Web Application Setup - Application Prerequisits
Create Application User & Directory Structure
-
Create application user:
www-appname... sudo adduser www-appname --disabled-login \ --disabled-password \ --ingroup www-data \ --home /var/lib/www/appname \ --shell /bin/false -
Create application directory:
... sudo mkdir -p /var/www/appname -
Set ownership of this directory:
... sudo chown appname:www-data /var/www/appnameAlso add admin user access:
# not sure what the [d:efalut] option does, but alone, that doesn't grant access ... sudo setfacl -R -m d:u:adminuser:rwx /var/www/appname # this grants access ... sudo setfacl -R -m u:adminuser:rwx /var/www/appname -
Create the rest of the basic directory structure:
Web Application Setup - Build The Server
New Ubuntu VPS Set Up
We’ve assuming we’ve created the initial droplet and that we are able to ssh as root into the box. Next steps are as follows:
Add Admin User Account
-
SSH into the droplet as root:
Run these commands on the server
# create your admin user ... adduser usrnme # set up ssh key # this was the old way: # ... mkdir /home/usrnme/.ssh # ... chmod 700 /home/usrnme/.ssh # ... cp /root/.ssh/authorized_keys /home/usrnme/.ssh # ... chown -R usrnme:usrnme /home/usrnme/.ssh/authorized_keys # ... chmod 600 /home/usrnme/.ssh/authorized_keys # this is shorter and : ... rsync --archive --chown=usrnme:usrnme ~/.ssh /home/usrnme # add user to sudo ... usermod -aG sudo usrnme -
Push any user config files necessary from your local computer to the new server from your development environment:
Web Application Setup - Django Setup
DJANGO SITE SETUP
-
Create virutualenv for you application:
... cd /var/www/appname ... python3 -m virtualenv --python=python3 venv -
Copy the basic application files to your new app directory:
From your development machine:
-
scp manage.py wsgi.py adminusr@server:/var/www/appname
-
scp django.settings.ini adminusr@server:/var/www/appname/config
-
scp requirements.txt adminusr@server:/var/www/appname/packages
-
scp appsite-0.1.0.tar.gz adminusr@server:/var/www/appname/packages
-
scp app-plugin-0.1.0.tar.gz adminusr@server:/var/www/appname/packages
Your directory structure should now look like:
appname ├── config │ ├── django.settings.ini ├── data ├── logs ├── manage.py ├── packages │ ├── appsite-0.1.0.tar.gz │ ├── app-plugin-0.1.0.tar.gz │ ├── requirements.txt ├── static └── wsgi.pyWe’ll describe these files in more detail later.
-