Skip to content

Instantly share code, notes, and snippets.

@yookoala
Last active April 17, 2020 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yookoala/b8d2e38d48ff3041545c9c3e6fa61b72 to your computer and use it in GitHub Desktop.
Save yookoala/b8d2e38d48ff3041545c9c3e6fa61b72 to your computer and use it in GitHub Desktop.
SPEC for a general useless ticking service with systemd unit and overridable rpm macros
# Variables that can be override on build time.
%{!?sleep: %define sleep 5}
%{!?name: %define name tick%{sleep}}
%{!?version: %define version 0.0}
%{!?release: %define release 1}
%{!?systemdinstalldir: %define systemdinstalldir /etc/systemd/system}
%{!?message: %define message come on, James}
# Some metadata required by an RPM package
Name: %name
Summary: Print a message every %{sleep}s
Version: %version
Release: %release
License: MIT
%description
%{name} is a simple useless script that echos a message every %{sleep} seconds.
%install
# create the executable from scratch in buildroot.
%{__mkdir} -p %{buildroot}%{_prefix}/bin
%{__cat} <<EOF> %{buildroot}/usr/bin/%{name}
#!/bin/bash
# say something, with timestamp, every %{sleep} seconds
while echo "\$@"; do
sleep %{sleep}s
done
EOF
%{__chmod} 755 %{buildroot}%{_prefix}/bin/%{name}
# generate the systemd unit file to buildroot.
%{__mkdir} -p %{buildroot}%{systemdinstalldir}
%{__cat} <<EOF> %{buildroot}%{systemdinstalldir}/%{name}.service
[Unit]
[Install]
WantedBy=multi-user.target
[Service]
ExecStart=%{_prefix}/bin/%{name} %{message}
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=%n
EOF
%files
%{_prefix}/bin/%{name}
%{systemdinstalldir}/%{name}.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment