Created
February 15, 2019 11:54
-
-
Save gheja/6a190283ab1d396183c7f21a151c0d3c to your computer and use it in GitHub Desktop.
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 | |
if [ $# != 3 ]; then | |
echo "$0 <name> <user> <command>" | |
exit 1 | |
fi | |
name="$1" | |
user="$2" | |
command="$3" | |
file="/etc/systemd/system/$name.service" | |
if [ -e "$file" ]; then | |
echo "$file: exists, exiting." | |
exit 1 | |
fi | |
cat > $file <<EOF | |
[Unit] | |
Description=$name | |
After=network.target | |
[Service] | |
Type=simple | |
User=$user | |
ExecStart=$command | |
Restart=on-failure | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl enable $name | |
systemctl start $name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment