Skip to content

Instantly share code, notes, and snippets.

@ahmed-abdelazim
Created September 15, 2019 21:27
Show Gist options
  • Select an option

  • Save ahmed-abdelazim/0e20e14fc86689cedf3d908f9dc2706c to your computer and use it in GitHub Desktop.

Select an option

Save ahmed-abdelazim/0e20e14fc86689cedf3d908f9dc2706c to your computer and use it in GitHub Desktop.
Create a service from bash script on Ubuntu ( for startup )
bootscript=/root/run.sh
servicename=customboot
cat > $bootscript <<EOF
#!/usr/bin/env bash
echo "$bootscript ran at $(date)!" > /tmp/it-works
EOF
chmod +x $bootscript
cat > /etc/systemd/system/$servicename.service <<EOF
[Service]
ExecStart=$bootscript
[Install]
WantedBy=default.target
EOF
systemctl enable $servicename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment