Skip to content

Instantly share code, notes, and snippets.

@Justman100
Created October 9, 2024 17:56
Show Gist options
  • Save Justman100/83265aefefe95c727c34f4ad0d168012 to your computer and use it in GitHub Desktop.
Save Justman100/83265aefefe95c727c34f4ad0d168012 to your computer and use it in GitHub Desktop.
Generate simply system.d files
#!/bin/bash
read -p "Name: " name
read -p "Exec: " exec
read -p "Working Directory: " wd
read -p "Debug? [y/N] " debug
if [[ -z $name || -z $exec ]]; then
echo "You must enter the name and command"
exit 1
fi
cat << EOF > /etc/systemd/system/${name,,}.service
[Unit]
Description=$name
After=network.target
Wants=network-online.target
[Service]
Restart=always
Type=simple
ExecStart=$exec
WorkingDirectory=$wd
Environment=
[Install]
WantedBy=multi-user.target
EOF
systemctl enable ${name,,}.service
systemctl start ${name,,}.service
[[ ! -z $debug ]] && journalctl -f -u ${name,,}.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment