Answer the question
In order to leave comments, you need to log in
How to properly run bash script with systemctl in Ubuntu?
Hello!
Ubuntu 18.04
There is a /etc/systemd/system/test.service file with the following content:
[Unit]
Description=test
After=network.target
[Service]
Type=forking
User=root
ExecStart=/var/www/djangotest/testproject/test.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
echo "Скрипт работает"
-rwxrwxrwx
systemctl -l status test
* test.service - test
Loaded: loaded (/etc/systemd/system/test.service; disabled; vendor preset: enabled)
Active: inactive (dead)
systemd[1]: Starting test...
systemd[6112]: test.service: Failed to execute command: Permission denied
systemd[6112]: test.service: Failed at step EXEC spawning /var/www/djangotest/testproject/test.sh: Permission denied
systemd[1]: test.service: Control process exited, code=exited status=203
systemd[1]: test.service: Failed with result 'exit-code'.
systemd[1]: Failed to start test.
systemd[1]: Starting test...
test.sh[6153]: Ск?<80>ип?<82> ?<80>або?<82>ае?<82>
systemd[1]: Started test.
Answer the question
In order to leave comments, you need to log in
You're lying about something about execution rights.
[email protected]:~# chmod +x /var/www/djangotest/testproject/test.sh
[email protected]:~# systemctl daemon-reload
[email protected]:~# systemctl enable test.service
[email protected]:~# systemctl start test.service
[email protected]:~# systemctl status test.service
● test.service - test
Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: enabled)
Active: inactive (dead)
окт 24 14:05:34 xeon systemd[1]: Starting test...
окт 24 14:05:34 xeon test.sh[15951]: Скрипт работает
окт 24 14:05:34 xeon systemd[1]: Started test.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question