Created
October 9, 2024 17:56
-
-
Save Justman100/83265aefefe95c727c34f4ad0d168012 to your computer and use it in GitHub Desktop.
Generate simply system.d files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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