Skip to content

Commit 6fa06ed

Browse files
Merge pull request #19 from Retro-I/systemd-startup-service
Systemd startup service
2 parents 1184032 + f6a6bcd commit 6fa06ed

File tree

7 files changed

+73
-28
lines changed

7 files changed

+73
-28
lines changed

SETUP.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ Im Plymouth Poweroff-Service muss eine Kleinigkeit ausgetauscht werden, damit da
2424
In der Datei `/usr/lib/systemd/system/plymouth-poweroff.service` muss `--mode=shutdown` durch `--mode=reboot` ersetzt werden.\
2525
Klingt nach einer Art "Trick-17"... Aber es funktioniert ;)
2626

27-
### Erstelle Autostart-Datei
28-
Damit die Software nach dem Systemstart von selbst startet, muss eine Autostart-Datei angelegt werden.\
29-
Unter `/etc/xdg/autostart/retroi.desktop` wird folgendes hinzugefügt:
27+
### User zur "audio" Gruppe hinzufügen
28+
Mit dem Befehl wird der aktuelle User zur `audio`-Gruppe hinzugefügt:
3029
```
31-
[Desktop Entry]
32-
Name=Retro.I
33-
Type=Application
34-
Exec=sh -c '$RETROI_DIR/scripts/start.sh >> $HOME/autostart.log 2>&1'
35-
Terminal=true
30+
sudo usermod -aG audio $USER
3631
```
3732

33+
### Systemd-Datei für Systemstart erstellen
34+
Damit die Software nach dem Systemstart von selbst startet, muss eine Autostart-Datei angelegt werden.\
35+
In `/etc/systemd/system/retroi.service` wird der Inhalt der Datei [`retroi.service`](scripts/retroi.service) hinzugefügt.
36+
3837
### Taskbar ausblenden
3938
Die Datei `$HOME/.config/wf-panel-pi.ini` wird angepasst und folgendes hinzugefügt:
4039
```

components/dialogs/SettingsShutdownDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self):
5353
ft.IconButton(
5454
ft.icons.HIGHLIGHT_OFF,
5555
icon_size=75,
56-
on_click=system_helper.stopp_app,
56+
on_click=system_helper.stop_app,
5757
),
5858
ft.Text(
5959
"App beenden",

helper/Audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def init_sound(self):
3030
def mixer(self):
3131
with open(self.mixers_path, "w") as f:
3232
f.write(str(a.mixers()))
33-
return a.Mixer()
33+
return a.Mixer("Master")
3434

3535
def update_sound(self, value):
3636
if 0 <= value <= 100:

helper/SystemHelper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def restart_system(self, _):
3535
time.sleep(3)
3636
os.system("sudo reboot")
3737

38-
def stopp_app(self, _):
38+
def stop_app(self, _):
3939
PageState.page.window_destroy()
4040
time.sleep(0.5)
4141
os._exit(0)

scripts/retroi.desktop

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/retroi.service

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Unit]
2+
Description=Retro.I Desktop App
3+
After=graphical.target
4+
5+
[Service]
6+
Type=simple
7+
User=pi
8+
Group=pi
9+
WorkingDirectory=$RETROI_DIR
10+
ExecStart=$RETROI_DIR/.venv/bin/python $RETROI_DIR/main.py
11+
Restart=no
12+
Environment=DISPLAY=:0
13+
Environment=XAUTHORITY=/home/pi/.Xauthority
14+
Environment=XDG_RUNTIME_DIR=/run/user/$user_id
15+
Environment=PULSE_SERVER=unix:/run/user/$user_id/pulse/native
16+
TimeoutStopSec=1
17+
KillSignal=SIGKILL
18+
KillMode=control-group
19+
20+
[Install]
21+
WantedBy=graphical.target

setup.sh

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,46 @@ remove_splashscreen() {
108108
fi
109109
}
110110

111-
create_autostart_file() {
112-
autostart_path="/etc/xdg/autostart/retroi.desktop"
113-
114-
sudo tee "$autostart_path" > /dev/null <<EOF
115-
[Desktop Entry]
116-
Name=Retro.I
117-
Type=Application
118-
Exec=sh -c '$RETROI_DIR/scripts/start.sh >> $HOME/autostart.log 2>&1'
119-
Terminal=true
111+
apply_audio_group() {
112+
sudo usermod -aG audio $USER
113+
}
114+
115+
create_systemd_service() {
116+
systemd_path="/etc/systemd/system/retroi.service"
117+
118+
user_id=$(id -u)
119+
120+
sudo tee "$systemd_path" > /dev/null <<EOF
121+
[Unit]
122+
Description=Retro.I Desktop App
123+
After=graphical.target
124+
125+
[Service]
126+
Type=simple
127+
User=pi
128+
Group=pi
129+
WorkingDirectory=$RETROI_DIR
130+
ExecStart=$RETROI_DIR/.venv/bin/python $RETROI_DIR/main.py
131+
Restart=no
132+
Environment=DISPLAY=:0
133+
Environment=XAUTHORITY=/home/pi/.Xauthority
134+
Environment=XDG_RUNTIME_DIR=/run/user/$user_id
135+
Environment=PULSE_SERVER=unix:/run/user/$user_id/pulse/native
136+
TimeoutStopSec=1
137+
KillSignal=SIGKILL
138+
KillMode=control-group
139+
140+
[Install]
141+
WantedBy=graphical.target
120142
EOF
121143

122144
# Verify creation
123-
if ! grep -q -- "^\[Desktop Entry\]" "$autostart_path"; then
124-
echo "Autostart file could not be created correctly!" >&2
145+
if ! grep -q -- "^\[Service\]" "$systemd_path"; then
146+
echo "Systemd file could not be created correctly!" >&2
125147
return 1
126148
fi
149+
150+
sudo systemctl enable retroi.service
127151
}
128152

129153
hide_taskbar() {
@@ -147,6 +171,11 @@ EOF
147171
remove_background_image() {
148172
pcmanfm --set-wallpaper "" --wallpaper-mode=color
149173

174+
mkdir -p "$HOME/.config/pcmanfm"
175+
176+
pcmanfm --reconfigure
177+
sleep 0.5
178+
150179
CONFIG_FILES=$(find "$HOME/.config/pcmanfm" -type f -name "desktop-items-*.conf" 2>/dev/null)
151180

152181
if [ -z "$CONFIG_FILES" ]; then
@@ -374,7 +403,8 @@ read -p "Drücke <ENTER> um das Setup zu beginnen..."
374403
set_project_path
375404
run_step "Entferne Splashscreen" remove_splashscreen
376405
run_step "System-Splashscreen ändern" sudo -E bash -c "$RETROI_DIR/update-system-splash.sh"
377-
run_step "Erstelle Autostart-Datei" create_autostart_file
406+
run_step "User zur \"audio\" Gruppe hinzufügen" apply_audio_group
407+
run_step "Systemd-Datei für Systemstart erstellen" create_systemd_service
378408
run_step "Taskbar ausblenden" hide_taskbar
379409
run_step "Hintergrund entfernen" remove_background_image
380410
run_step "Mülleimer entfernen" remove_trash_basket

0 commit comments

Comments
 (0)