Last active
July 8, 2023 02:06
-
-
Save lexmart/9ac22337c77ef3ce7143fa6e6a51076a to your computer and use it in GitHub Desktop.
Install system service bash script
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/sh | |
fullpath=$(realpath $1) | |
dirpath=$(dirname $fullpath) | |
name=$(basename $1) | |
service_file=/etc/systemd/system/$name.service | |
echo "[Unit]" > $service_file | |
echo "Description=$name" >> $service_file | |
echo "After=network.target" >> $service_file | |
echo "[Service]" >> $service_file | |
echo "User=$USER" >> $service_file | |
#echo "Group=www-data" >> $service_file | |
echo "WorkingDirectory=$dirpath" >> $service_file | |
echo "ExecStart=$fullpath" >> $service_file | |
for ((i=2; i<=$#; i++)) | |
do | |
echo "Environment=\"${!i}\"" >> $service_file | |
done | |
echo "[Install]" >> $service_file | |
echo "WantedBy=multi-user.target" >> $service_file | |
sudo systemctl daemon-reload | |
systemctl enable $name.service | |
systemctl start $name.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment