Score:0

systemd service doesnt start

mt flag

i have a problem with a systemd service and i cant find the problem.

I have script in the directory /home/username/test/ called battery.sh:

#!/bin/sh
max=99999
for i in `seq 1 $max`
do
    clear
    python3 batterie.py
    sleep 5
done

it starts a python script named batterie.py. This script gives out a log file in the directory. I want the sh script to be autostarted, so i added batterie.service in /etc/systemd/system:

[Unit]
Description=Batterie Script

[Service]
Type=simple
ExecStart=/bin/sh /home/username/test/batterie.sh
WorkingDirectory=/home/username/test
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Then i added service to autostart with "sudo systemctl enable batterie". Now systemctl status batterie gives:

batterie.service - Batterie Script
     Loaded: loaded (/etc/systemd/system/batterie.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-03-16 17:58:13 CET; 2min 17s ago
   Main PID: 1117 (sh)
      Tasks: 3 (limit: 18943)
     Memory: 45.3M
     CGroup: /system.slice/batterie.service
             ├─1117 /bin/sh /home/username/test/batterie.sh
             └─1123 python3.10 batterie.py
Mär 16 18:00:21 NUC8i3BEK sh[1263]: TERM environment variable not set.

But there is no logfile in the directory test. But there is a log file when i start the script manually from the directory.

What did i do wrong?

hr flag
I don't see evidence that the service fails to start - the `TERM environment variable not set` error is probably due to the `clear` command (which seems to have no purpose in a non-interactive context)
Demophobie avatar
mt flag
Ah right. Deleted it. After a fresh restart i get a log file now too. It there a way to execute the script in the name of a user and not root? The log file is owned by root now.
hr flag
Probably the right way is to install it as a systemd user service (in `~/.config/systemd/user`) but I don't know much about that
Demophobie avatar
mt flag
i had to do a freah reinstall of new linux mint (now 21.1). Now it works with above code.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.