lus / pasty

pasty is a fast and lightweight code pasting server
https://pasty.lus.pm
MIT License
200 stars 27 forks source link

Weird error when running on systemd #36

Closed Fastidious closed 2 years ago

Fastidious commented 2 years ago

When I run pasty from the command line, and use Caddy to proxy to it, it works fine, no issues. Of course, I want to run it with systemd. This is my systemd file:

[Unit]
Description=Pastie
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
StartLimitBurst=5
StartLimitInterval=100
User=www-data
Group=www-data
ExecStart=/usr/local/bin/pasty
EnvironmentFile=/usr/local/etc/pasty/.env

[Install]
WantedBy=multi-user.target

Pasty will start fine, and run, but when I try accessing it, I get Cannot open requested path. Any idea of what could be happening?

lus commented 2 years ago

The issue there is that pasty serves the web frontend by reading the ./web/ folder which does not exist in your environment.

Fastidious commented 2 years ago

It does. See EnvironmentFile.

Fastidious commented 2 years ago

There is also a .env where pasty is as well. Same result.

lus commented 2 years ago

I am not talking about the .env file, the issue is the ./web/ directory which has to contain the web frontend. I wrote that part when go did not have static file embedding so I had to accept that trade-off.

Fastidious commented 2 years ago

Oh! Hmm, so pasty is not fully self-contained, it requires the web directory? How can I achieve this? I even changed paths, like this:

[Unit]
Description=Pastie
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
StartLimitBurst=5
StartLimitInterval=100
User=www-data
Group=www-data
ExecStart=/usr/local/src/pasty/pasty
EnvironmentFile=/usr/local/src/pasty/.env

[Install]
WantedBy=multi-user.target

Which points to pasty on the repo itself, where the other files are, as still the same.

lus commented 2 years ago

Yes, that's a bad solution, but it was not possible otherwise when I wrote that part of pasty. I opened #37 which addresses this. I will take a look into this now and notify you here if I can reach a solution. That may take several minutes, an hour or a day, I'm not sure how complex that will be.

lus commented 2 years ago

Further status updates will be posted to the just-linked issue. As it will take some time to embed the frontend into the binary I pushed a temporary workaround which is messy but could help you. You can now build pasty (please clone the develop branch) using this command:

go build \
        -o pasty \
        -ldflags "\
            -X github.com/lus/pasty/internal/static.TempFrontendPath=/your/frontend/path" \
        ./cmd/pasty/main.go

If you use the binary that gets built by that command, pasty will use /your/frontend/path instead of ./web to load the frontend. You can use this solution to define an absolute path to the frontend directory.

This is not meant to be a long-term solution but could help you to continue with your setup so that you are not stuck until I manage to make the binary fully self-contained.

Please let me know if this helps you or if you need any further support from my side.

Fastidious commented 2 years ago

Never mind, that worked! The actual command I used was:

go build -o pasty -ldflags "-X github.com/lus/pasty/internal/static.TempFrontendPath=/usr/local/pasty/
web" ./cmd/pasty/main.go

And that did the trick. Thanks for the workaround!

Fastidious commented 2 years ago

Could I suggest, once you achieve the long-term solution for this, to pack everything in it that is currently being pulled from CDNs (I counted four items)? Thanks again!

lus commented 2 years ago

Yes, I'll open a separate issue for that. I'll close this one then. If there are any further questions feel free to open another one!