S
S
sportik1742021-10-24 12:01:12
linux
sportik174, 2021-10-24 12:01:12

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


The contents of the file /var/www/djangotest/testproject/test.sh
#!/bin/bash
echo "Скрипт работает"


Permissions for the file /var/www/djangotest/testproject/test.sh
-rwxrwxrwx
When checking the status with the command , it gives the following errorsystemctl -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.

What could be the problem? The second day I suffer, I can not understand what is the reason, Help please!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-10-24
@sportik174

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 question

Ask a Question

731 491 924 answers to any question