How to run a command as a specific user in an init script?

后端 未结 6 2030
南方客
南方客 2020-12-29 03:26

I\'m writing an init script which is supposed to execute a single command as a user different than root. This is how I\'m doing it currently:
sudo -u username comm

6条回答
  •  生来不讨喜
    2020-12-29 03:51

    For systemd style init scripts it's really easy. You just add a User= in the [Service] section.

    Here is an init script I use for qbittorrent-nox on CentOS 7:

    [Unit]
    Description=qbittorrent torrent server
    
    [Service]
    User=
    ExecStart=/usr/bin/qbittorrent-nox
    Restart=on-abort
    
    [Install]
    WantedBy=multi-user.target
    

提交回复
热议问题