0

I am trying to create the systemd service file using bash script so that I don't need to do it manually. I log in to the list of the host using ssh and want to run this script on them. I will just provide the script which will create the service file and try to write it.

#!/bin/bash
create_service_file(){
        dirname=genesis
        echo $password | sudo -S touch /etc/systemd/system/eos.service
        cd /etc/systemd/system/
        sudo chmod +rwx /etc/systemd/system/eos.service

        sudo printf "[Unit]\n"  >> eos.service &&
        sudo printf 'Description=Stop and Start the eos blockchain\n' >> eos.service &&
        sudo printf 'After=network.target shutdown.target reboot.target\n' >> eos.service &&
        sudo printf '[Service]\n' >> stopeos.service &&
        sudo printf 'RemainAfterExit=yes\n' >> stopeos.service &&
        sudo printf 'ExecStop=/home/doqubiz/biosboot/'$dirname'/stop.sh\n' >> eos.service &&
        printf 'ExecStart=/home/doqubiz/biosboot/'$dirname'/start.sh\n' >> eos.service &&
        printf 'WorkingDirectory=/home/doqubiz/biosboot/'$dirname'\n' >> eos.service &&
        printf '[Install]\n' >> eos.service &&
        printf 'WantedBy=multi-user.target\n' >> eos.service

        sudo systemctl daemon-reload
        sudo systemctl enable eos.service
        sudo systemctl start eos.service
        sudo systemctl status eos.service
}

create_service_file

This script creates eos.service file but didn't write anything in it. I tried changing the permission of this file to write but didn't work. Please help.

Varsh
  • 413
  • 9
  • 26

0 Answers0