How to restart a systemctl service from within the process

Chris Green cl at isbd.net
Mon Nov 23 10:07:04 UTC 2020


On Mon, Nov 23, 2020 at 09:21:54AM +0000, Colin Law wrote:
> On Sun, 22 Nov 2020 at 15:50, Chris Green <cl at isbd.net> wrote:
> >
> > You can have user processes run and handled by systemctl.
> 
> Does that mean that if I have a service running as a particular user
> that the user can 'systemctl restart' it without using sudo?
> Searching hasn't found anything relevant, likely because I am not
> using the right search terms.
> 
Yes. I run syncthing using systemd.

The configuration file for this is:-

    /etc/systemd/system/multi-user.target.wants/syncthing at chris.service

Which is:-

    [Unit]
    Description=Syncthing - Open Source Continuous File Synchronization for %I
    Documentation=man:syncthing(1)
    After=network.target

    [Service]
    User=%i
    ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
    Restart=on-failure
    RestartSec=5
    SuccessExitStatus=3 4
    RestartForceExitStatus=3 4

    # Hardening
    ProtectSystem=full
    PrivateTmp=true
    SystemCallArchitectures=native
    MemoryDenyWriteExecute=true
    NoNewPrivileges=true

    [Install]
    WantedBy=multi-user.target


There are a number of configuration files for various 'user' services
to be found in:-
    /usr/lib/systemd/system/multi-user.target.wants

-- 
Chris Green




More information about the ubuntu-users mailing list