Skip to content

Commit

Permalink
Add Plug-in enabled systemd services/target
Browse files Browse the repository at this point in the history
Contributes-To: #21
  • Loading branch information
nephros committed Nov 27, 2022
1 parent af35a90 commit 6256ffa
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README_logcollect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Bugger! log collect plugin system

In order to add your script for collecting logs to the Bugger! log collector, do the following:


1. create a shell script which outputs logging to standard output
2. place the script into `/usr/share/harbour-bugger/scripts`
3. name the script `gather-logs-$YOURNAME.sh`
4. use the systemd template service `[email protected]` to add your script to the plugin service.
5. e.g. do `systemctl --user enable harbour-bugger-gather-logs-plugin@$YOURNAME.service`

Notes:

- log output will be written to `~/Documents/YYYY-MM-DD-harbour-bugger-gather-logs-plugin_$YOURNAME.log`
- `[email protected]` uses `Protectsystem=full`, so don't expect any location to be writable in your script.
- scripts are run in systemd user scope. You can't be root. If you need to be root, use `pkexec` to prompt users for the lock code/fingerprint.
- Bugger! will run the log creation, but will not add the created log files in the app. Users will have to select them manually.
5 changes: 5 additions & 0 deletions harbour-bugger.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ qml.path = /usr/share/$${TARGET}

INSTALLS += qml

readme.files = README_logcollect.md
readme.path = /usr/share/$${TARGET}/scripts

INSTALLS += readme

OTHER_FILES += $$files(rpm/*)

include(translations/translations.pri)
Expand Down
13 changes: 12 additions & 1 deletion rpm/harbour-bugger.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Name: harbour-bugger
# << macros

Summary: Bug reporting helper
Version: 0.10.1
Version: 0.10.2
Release: 1
Group: Applications
License: ASL 2.0
Expand Down Expand Up @@ -90,17 +90,26 @@ desktop-file-install --delete-original \

%preun
# >> preun
%systemd_user_preun harbour-bugger-gather-logs.target
%systemd_user_preun harbour-bugger-gather-logs.service
%systemd_user_preun [email protected]
%systemd_user_preun harbour-bugger-gather-android-logs.service
# << preun

%post
# >> post
%systemd_user_post harbour-bugger-gather-logs.target
%systemd_user_post harbour-bugger-gather-logs.service
%systemd_user_post [email protected]
%systemd_user_post harbour-bugger-gather-android-logs.service
# << post

%postun
# >> postun
%systemd_user_postun harbour-bugger-gather-logs.target
%systemd_user_postun harbour-bugger-gather-logs.service
%systemd_user_postun [email protected]
%systemd_user_postun harbour-bugger-gather-android-logs.service
# << postun

%files
Expand All @@ -110,6 +119,8 @@ desktop-file-install --delete-original \
%config %{_sysconfdir}/sailjail/permissions/%{name}.profile
%config %{_sysconfdir}/firejail/%{name}.local
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/scripts
%{_datadir}/%{name}/scripts/README_logcollect.md
%{_datadir}/%{name}/translations/*.qm
%{_datadir}/%{name}/qml/*
%{_userunitdir}/*.target
Expand Down
4 changes: 3 additions & 1 deletion rpm/harbour-bugger.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: harbour-bugger
Summary: Bug reporting helper
Version: 0.10.1
Version: 0.10.2
Release: 1
Group: Applications
License: ASL 2.0
Expand Down Expand Up @@ -84,6 +84,8 @@ Files:
- '%config %{_sysconfdir}/sailjail/permissions/%{name}.profile'
- '%config %{_sysconfdir}/firejail/%{name}.local'
- '%dir %{_datadir}/%{name}'
- '%dir %{_datadir}/%{name}/scripts'
- '%{_datadir}/%{name}/scripts/README_logcollect.md'
- '%{_datadir}/%{name}/translations/*.qm'
- '%{_datadir}/%{name}/qml/*'
- '%{_userunitdir}/*.target'
Expand Down
18 changes: 18 additions & 0 deletions systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Collect Logfiles
Documentation=https://github.com/sailfishos-chum/bugger/README_logcollect.md
Documentation=/usr/share/harbour-bugger/scripts/README_logcollect.md
Before=harbour-bugger-gather-logs.target

[Service]
Type=oneshot
ProtectSystem=full
ReadWritePaths=%h/Documents
ExecStart=/bin/sh -c "\
/usr/share/harbour-bugger/scripts/gather-logs-%i.sh > %h/Documents/$(date -I)_%N_%i.log; \
/usr/bin/chmod 0600 %h/Documents/$(date -I)_%N*json %h/Documents/$(date -I)_%N*log; \
/usr/bin/chown %u %h/Documents/$(date -I)_%N*json %h/Documents/$(date -I)_%N*log; \
"

[Install]
WantedBy=harbour-bugger-gather-logs.target
3 changes: 3 additions & 0 deletions systemd/harbour-bugger-gather-logs.target
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[Unit]
Description=Collect Log files for Bugger!
Documentation=https://github.com/sailfishos-chum/bugger/README_logcollect.md
Documentation=/usr/share/harbour-bugger/scripts/README_logcollect.md
DefaultDependencies=no
After=user-session.target
2 changes: 2 additions & 0 deletions systemd/systemd.pri
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
OTHER_FILES += $${TARGET}-gather-logs.target\
$${TARGET}-gather-logs.service\
$${TARGET}-gather-logs-plugin@.service \
$${TARGET}-gather-android-logs.service

INSTALLS += sdservice

sdservice.files = $$PWD/$${TARGET}-gather-logs.target \
$$PWD/$${TARGET}-gather-logs.service \
$$PWD/$${TARGET}-gather-logs-plugin@.service \
$$PWD/$${TARGET}-gather-android-logs.service
sdservice.path = $$INSTALL_ROOT/usr/lib/systemd/user

0 comments on commit 6256ffa

Please sign in to comment.