How to create a Systemd service in Linux

 

At times you create a script and then you want to have the scripts controlled by systemd or in some cases you wish to have the scripts getting restarted by itself when it is killed due to some reason. In such cases systemd in Linux helps to configure services which can be managed. To do so follow the following steps.

  1. 1
    cd /etc/systemd/system
    

  2. Create a file named your-service.service and include the following:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    [Unit]
    Description=<description about this service>
    
    [Service]
    User=<user e.g. root>
    WorkingDirectory=<directory_of_script e.g. /root>
    ExecStart=<script which needs to be executed>
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    
     
  3. Reload the service files to include the new service.
    1
    sudo systemctl daemon-reload
    

  4. Start your service
    1
    sudo systemctl start your-service.service
    

  5. To check the status of your service
    1
    sudo systemctl status your-service.service
    

  6. To enable your service on every reboot
    1
    sudo systemctl enable your-service.service
    
     
  7. To disable your service on every reboot
    1
    sudo systemctl disable your-service.service
    


    That's it !

 [ Source: https://www.shubhamdipt.com/blog/how-to-create-a-systemd-service-in-linux/]

 

Keine Kommentare:

Kommentar veröffentlichen

Datei in einer windows.wim image ändern

 Um Dateien in einer Datei.wim zu ändern, und zwar nicht im 1. Index sondern 2. öffnet man Powershell (ich habs jetzt im admin Modus gestart...