Run a Shell Script (http server) as Systemd Service in Linux
Download http Script (Example)
cd /root/
mkdir webserver
cd /webserver/
git clone https://github.com/xsukax/ipfs-tools.git
Create bash script to start http server
nano /root/webserver/ipfs-tools.sh
Paste bash script code
#!/bin/bash
python3 -m http.server 8080 -d /root/webserver/ipfs-tools/ -b 0.0.0.0 > /var/log/ipfstools.txt
-b ADDRESS, –bind ADDRESS bind to this address (default: all interfaces)
-d DIRECTORY, –directory DIRECTORY serve this directory (default: current directory)
Make the file executable by running the following command
chmod +x /root/webserver/ipfs-tools.sh
Make a service for running the script
nano /etc/systemd/system/ipfstools.service
Description=IPFS Tools Web Server
Documentation=https://xsukax.com/ipfs
[Service]
Type=simple
User=root
Group=root
TimeoutStartSec=0
Restart=on-failure
RestartSec=30s
#ExecStartPre=
ExecStart=/root/webserver/ipfstools.sh
SyslogIdentifier=Diskutilization
#ExecStop=
[Install]
WantedBy=multi-user.target
Alias=ipfstools.service
Save the file and start the service using the systemctl command
systemctl enable ipfstools.service
systemctl start ipfstools.service
systemctl status ipfstools.service
Open url on the opened port