On demand activation with systemd-sockets

Overview

Actual service

[Unit]
Description=ScriptWapper
Requires=check-deactivate.service

[Service]
Type=simple
ExecStart=/usr/bin/roflcopter.sh
ExecStop=pkill roflcopter

[Install]
WantedBy=multi-user.target

Systemd socket proxy

[Unit]
Description=Socket Proxy for script-wrapper
After=script-wrapper.service
Requires=script-wrapper.service

[Service]
ExecStart=/lib/systemd/systemd-socket-proxyd 127.0.0.1:ANYPORT

[Install]
WantedBy=multi-user.target

Systemd socket

[Unit]
Description=Socket activator for roflcopter.sh
PartOf=script-wrapper-proxy.service

[Socket]
ListenStream=ANYPORT
BindIPv6Only=both
Accept=false

[Install]
WantedBy=multi-user.target

Checking if the service can be deactivated

/usr/bin/checker.sh
if [ users -gt o]
systemctl stop ScriptWrapper
-----------------------------------------[Unit]
Description=check if unit can be stopped

[Service]
Type=oneshot
ExecStart=/usr/local/bin/checker.sh
[Unit]
Description=call checker-service
After=script-wrapper.service
PartOf=script-wrapper.service

[Timer]
OnUnitActiveSec=15min
OnActiveSec=14min
Persistent=false
Unit=script-wrapper-checker.service

Timeouts when waiting for the application to start

Costs of start and stop

Racecondition between shutdown and startup request

--

--

--

Python programmer at heart, Linux Expert at work, GameDev on my good days, web developer on the bad days.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

View Components in ASP.NET Core

CS373 Spring 2021: Tanmay Singh

What is the DRY principle?

The Epitome Heist: Creating a SkyBox In Unity

CS 373 Spring 2021 Week 7: Tanmay Singh

The Meaning of Hue in the Angular Palette Context

Knowledge Sharing Leads to Developer Team Productivity

⏰ IDO ON DareNFT: IN 3 HOURS ⏰

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yannik Schmidt

Yannik Schmidt

Python programmer at heart, Linux Expert at work, GameDev on my good days, web developer on the bad days.

More from Medium

Setting Up Proxychains Linux

what happens when you type ls -l *.c and hit Enter in a shell?

PyCharm Run and Debug

Hashing vs Encryption In Less Than 5 Minutes