Linux Service - The-GNTL-Project/Documentation GitHub Wiki
Description
This is an example of a Service file, which is used to run a bash script located in our home location, in a detached screen session. We will be using Ubuntu as our distribution, the commands may differ for other distributions.
Where you see USERNAME
, substitute this to your username being used to log into the system, e.g. bkdilse
Installation
Pre-requisites
These are all required before you proceed:
- Basic Linux knowledge.
- Bash script setup with the commands you want run.
Configure the Service
Let's configure our Service, by creating the contents in the ExampleService
file, using nano
as our editor:
sudo nano /etc/systemd/system/ExampleService.service
[Unit]
Description=Example Service
After=network-online.target
[Service]
LimitMEMLOCK=infinity
Type=forking
RemainAfterExit=yes
User=USERNAME
WorkingDirectory=/home/USERNAME
ExecStart=/usr/bin/screen -dmS TestScreen /home/USERNAME/ExampleBashScript
KillMode=none
[Install]
WantedBy=multi-user.target
Let's grant execute permissions to our service, reload the content, and enable it:
sudo chmod 0755 /etc/systemd/system/ExampleService.service
sudo systemctl daemon-reload
sudo systemctl enable ExampleService