Skip to content

Instantly share code, notes, and snippets.

@gheja
Created February 15, 2019 11:54
Show Gist options
  • Save gheja/6a190283ab1d396183c7f21a151c0d3c to your computer and use it in GitHub Desktop.
Save gheja/6a190283ab1d396183c7f21a151c0d3c to your computer and use it in GitHub Desktop.
#!/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