45 lines
769 B
Bash
45 lines
769 B
Bash
#!/usr/bin/env bash
|
|
# Generate systemd service file
|
|
|
|
set -e
|
|
|
|
FILE=/etc/systemd/system/buttond.service
|
|
|
|
button=$(realpath button.py)
|
|
if [[ ! -f $button ]]; then
|
|
echo button.py not found
|
|
exit 1
|
|
fi
|
|
|
|
vpython=$(realpath venv/)/bin/python
|
|
if [[ ! -x $vpython ]]; then
|
|
echo venv not found
|
|
exit 1
|
|
fi
|
|
|
|
cat > "$FILE" << EOF
|
|
[Unit]
|
|
Description=Button Service 1. OG
|
|
StartLimitIntervalSec=60s
|
|
StartLimitBurst=10
|
|
|
|
[Service]
|
|
Type=exec
|
|
ExecStart=$vpython -u $button
|
|
User=root
|
|
WorkingDirectory=$(dirname "$button")
|
|
Restart=on-failure
|
|
RestartSec=3s
|
|
NoNewPrivileges=yes
|
|
PrivateTmp=yes
|
|
ProtectSystem=full
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
service=$(basename "$FILE")
|
|
systemctl daemon-reload
|
|
systemctl enable --now "$service"
|
|
systemctl --no-pager status "$service"
|