I’m really bad at remembering basic CLI stuff, but I feel like a cool hackerman when I use it so here we are.
(from Windows PowerShell or wherever)
ssh USER@IP(or host name)
Basic shit
| Command | Description |
|---|---|
nano |
Excellent lil text editor guy, often useful. |
ls |
List current directory |
cd (path) |
Change directory |
cd .. |
Go up a directory |
sudo shutdown |
RIP |
sudo reboot |
play it again sam |
rm -rf (path) |
Remove folder |
sudo apt update sudo apt upgrade song and dance.
Python stuff
python (path to .py)
Run the damn thing. Remember that most python scripts want a virtual environment.
sudo apt-get install python3-venv
Actually install virtual environment shit.
python3 -m venv my-virtual-env
Create a virtual environment in the current directory.
source my-virtual-env/bin/activate
Actually activate the virtual environment.
deactivate
Get the hell out.
Git stuff
git clone https://github.com/falco-wli/DiscordPhotoFrame
Can go right off of public repos. You’ll need gh for private stuff - a bit of a pain but once it is setup it works ok
git pull
Nabs from the current directories repo. It is very simple - git just makes a hidden file with the repo info, so you don’t need any specific creds or workspace or anything.
systemctl - IE services on debian
EZ method of getting services running IE stuff that runs in the background, often triggered on reboot. Perfect for IOT projects. Needs sudo usually. Also, it is systemctl, NOT “systemctrl” - super annoying.
sudo nano /etc/systemd/system/discordbot1.service
OK, so /etc/systemd/system/ is where services live - they are .service files, basically a json kinda thing. Edit / create them with nano.
[Unit]
Description=EInk Discord Bot
After=multi-user.target network-online.target
[Service]
WorkingDirectory=/home/pi/
ExecStart=/home/pi/.virtualenvs/pimoroni/bin/python /home/pi/DiscordPhotoFrame/DiscordPhotoFrame.py
Type=idle
Restart=on-failure
TimeoutStartSec=5
RestartSec=2
[Install]
WantedBy=multi-user.target
This is an example of what the discord photo frame uses. Remember that since it is python it uses a virtual environment, hence the double directory (first is the python executable in the virtual environment, second is the actual script.)
systemctl status
Shows all the services, mostly internal stuff.
systemctl daemon-reload
Reloads all the scripts from disk IE run this after changing any actual service files.
systemctl start (name of service)
systemctl stop (name of service)
Put it all together
For my basic IoT devices running headless Debian, a service lives in /etc/systemd/system/ starts on boot. It is handled by “systemd’, which confusingly uses systemctl commands. https://wiki.debian.org/systemd is a good resource here.
The “Unit” or service instructs the system to open a python virtual environment. This is setup in advance since python yells at you if you try to run things bare metal.
The service finally runs the script (.py), and is instructed to reboot the service on failure. EZ.
Updates are handled via git - write your code (on your dev machine!), submit to github, then cd to the folder and run git pull - assuming you ran git clone to put it there in the first place.
You may need a .env file (discord bot codes, etc). You can quick make one with nano .env to start a new file, write your variables, then ctrl+o to “write out”.