Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A How to create systemd unit that depends on a website being up?

I'm going to write some systemd services. All of these can only be run if a certain website is up. I thought I could create a ~/.config/systemd/user/website.service this: [Unit] Description=Confi...

1 answer  ·  posted 9mo ago by matthewsnyder‭  ·  last activity 7mo ago by Iizuki‭

Question systemd
#1: Initial revision by user avatar matthewsnyder‭ · 2023-08-09T02:42:04Z (9 months ago)
How to create systemd unit that depends on a website being up?
I'm going to write some systemd services. All of these can only be run if a certain website is up. I thought I could create a `~/.config/systemd/user/website.service` this:

```
[Unit]
Description=Confirm that example is up
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
ExecStart=curl --head example.com
```

And then I can make my actual units have `Requires=website.service`.

When I run `systemctl --user start website`, it just exits. When I check `systemctl --user status website` I see the header in the logs. But the status just says "inactive", not success or fail (based on exit code of fail).

When I tell systemd to run my other units, it should first run `website.service`, and only if it succeeds should the target units run. Otherwise they should fail. How do I accomplish this?