Using Pipenv with Systemd

So I’ve been doing a bit of Python recently for a project I’m working on on a Raspberry Pi. There will be a longer blog post about that in the next few weeks. But one thing I ran up against was that I wanted to start my daemon, written in Python, using a systemd service on Raspbian.

Normally, you would just shove a script invocation into a systemd unit and call it good, but in my case I had made use of Pipenv, which is a bit like Bundler in the Ruby world and Composer in the PHP world, to manage my project’s dependencies.

And the way you invoke a program using Pipenv is different from just invoking the script:

$ pipenv run python3 src/foo.py

So you might try something like this in a systemd unit:

ExecStart=/usr/local/bin/pipenv run python3 /path/to/src/foo.py

But that doesn’t work. This is because Pipenv relies on the current working directory to look for the Pipfile. Fortunately, with systemd, you can specify the current working directory in the unit file using the WorkingDirectory directive. So your systemd unit file might look something like this:

[Unit]
Description=My Python Service
After=network.target

[Service]
User=user
Restart=always
Type=simple
WorkingDirectory=/path/to
ExecStart=/usr/local/bin/pipenv run python3 /path/to/src/foo.py

[Install]
WantedBy=multi-user.target
Did something I wrote help you out?

That's great! I don't earn any money from this site - I run no ads, sell no products and participate in no affiliate programs. I do this solely because it's fun; I enjoy writing and sharing what I learn.

All the same, if you found this article helpful and want to show your appreciation, here's my Amazon.com wishlist.

Read More

Archiving A Yahoo Group

I’ve been on the Internet a long time, since the early to mid 1990s. And when you are on the Internet that long, you tend to leave a pretty long trail behind you. But over the years that trail gets overgrown as sites close, lists vanish, and machines crash. There is precious little left from those early years. One thing that has persisted to this time, despite being pretty heavily neglected over the years, is Yahoo Groups. Those who remember the first dot-com boom may remember that Yahoo Groups was not originally Yahoo Groups. It was eGroups, which Yahoo bought and merged into their own sprawling empire. eGroups basically made it possible for anyone to set up a mailing list without needing access to a listserv service. Well, it looks like the end has finally come for Yahoo Groups. Verizon, the new owner of the rotting corpse of Yahoo, has announced that all groups will disappear on December 14th. I was on tons of mailing lists during my early Internet years, and I would really like to archive and preserve those messages if I could. But how could I get them out of Yahoo?