L
L
Li_Lynch2016-03-20 06:50:57
linux
Li_Lynch, 2016-03-20 06:50:57

Why doesn't script work after running unit in systemd?

There is a small script, there is a unit. The unit starts and no errors occur, but the result of the script is not observed. I think the problem is that the script only runs with superuser rights, that is, if you type

sudo myscript

then everything works great.
If you type with pens
sudo systemctl start myunit.service
then again everything works fine. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2016-03-20
@Li_Lynch

there are three options:

  1. The unit belongs to and works only from the superuser, but the script/program itself can be launched by the unit itself from the specified user if the following lines are added to the [Service] section:
    User=юзер
    Group=группа

    usually the unit is in /etc/systemd/system/XXX.service
    $ sudo systemctl enable XXX.service
    $ sudo systemctl start XXX.service
    ...

  2. The unit belongs to the superuser, but any user can work with it:
    the unit is located in /etc/systemd/user/XXX.service .
    You can work with it in the same way as with a regular unit, you just need to specify the --user parameter , for example:
    $ systemctl --user enable XXX.service
    $ systemctl --user start XXX.service
    ...

  3. The unit is owned and operated by only one specific user:
    Located in the user's home folder ~/.config/systemd/user/XXX.service .
    To work, you also need to specify the --user parameter .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question