banner



How To Make A Systemd Service File

Systemd is a software application that provides an array of organization components for Linux operating systems. It is the first service to initialize the boot sequence. This e'er runs with pid ane. This also helps utilise to manage system and application service on our Linux operating organization.

We can besides run whatever custom script as systemd service. It helps the script to start on system boot. This can be helpful for you to run any script which required to run at kicking time only or to run always.

In our previous tutorial we have provides you instructions to run a Python script using Systemd. This tutorial coverts to run a shell script as Systemd service.

Step one – Create a Crush Script

First of all, create a sample shell script to run e'er until the system is running. We will use fustigate while loop to run infinitely.

          sudo nano /usr/bin/script.sh                  

Add the following sample script.

Salvage script and set execute permission.

          sudo chmod +10 /usr/bin/script.sh                  

To run a script once during organisation kicking fourth dimension doesn't required whatever infinite loop. Instead of the to a higher place script, yous tin can use your shell script to run every bit Systemd service.

Step 2 – Create A SystemD File

Side by side, create a service file for the systemd on your system. This file must take .service extension and saved under the nether /lib/systemd/system/ directory

          sudo nano /lib/systemd/system/shellscript.service                  

Now, add the following content and update the script filename and location. You can likewise alter the description of the service.

[Unit] Clarification=My Shell Script  [Service] ExecStart=/usr/bin/script.sh  [Install] WantedBy=multi-user.target        

Relieve the file and shut information technology.

Step three – Enable New Service

Your arrangement service has been added to your service. Let's reload the systemctl daemon to read new file. You demand to reload this deamon each time after making whatsoever changes in in .service file.

          sudo systemctl daemon-reload                  

At present enable the service to beginning on system boot, also commencement the service using the post-obit commands.

          sudo systemctl enable shellscript.service                    sudo systemctl start shellscript.service                  

Finally verify the script is upwardly and running as a systemd service.

          sudo systemctl status shellscript.service                  

Output looks like below:

Running shell script as systemd service

Conclusion

This tutorial helped you lot to configure a crush script as systemd service.

How To Make A Systemd Service File,

Source: https://tecadmin.net/run-shell-script-as-systemd-service/

Posted by: rodriguezcortiferet.blogspot.com

0 Response to "How To Make A Systemd Service File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel