How do i create a new service using systemd-run?



  • Man page for systemd-run.

    You need to have a command that will continuously run. This is will allow you to see it running.

    $ sudo systemd-run --unit=training --slice=training vmstat 2
    Running as unit training.service.
    

    Verify the service is running.

    $ systemctl status training.service
    * training.service - /bin/vmstat 2
       Loaded: loaded (/run/systemd/system/training.service; static; vendor preset: disabled)
      Drop-In: /run/systemd/system/training.service.d
               `-50-Description.conf, 50-ExecStart.conf, 50-Slice.conf
       Active: active (running) since Sat 2019-02-02 15:00:13 GMT; 12min ago
     Main PID: 6491 (vmstat)
       CGroup: /training.slice/training.service
               `-6491 /bin/vmstat 2
    
    Feb 02 15:12:25 centos-linux.shared vmstat[6491]: 1  0   1792 259028      0 8...
    Feb 02 15:12:27 centos-linux.shared vmstat[6491]: 1  0   1792 258428      0 8...
    ...
    ...
    ...
    

    Remember to stop the service.

    $ sudo systemctl stop training.service
    

Log in to reply
 

© Lightnetics 2019