abiosoft/autoplank

Recommended Systemd Services

Opened this issue · 3 comments

I thought of contributing here as I like this autoplank instance. From how I had it before by using another autoplank iteration, using systemd is probably the better way to go about it.

If you like my recommendations, feel free to add it to your README @abiosoft

Here are my suggestions and take them for what is worth.

  1. Create the service file as user, and the desired polling. Do not enable this service:
$ cat $HOME/.config/systemd/user/autoplank.service
[Unit]
Description=Autoplank Service

[Service]
ExecStart=/usr/local/bin/autoplank -p 200
Restart=always

[Install]
WantedBy=default.target
  1. Create a systemd timer for this service and make the timer trigger the service:
$ cat $HOME/.config/systemd/user/autoplank.timer  
[Unit]
Description=Timer for the AutoPlank user-mode service

[Timer]
OnActiveSec=5
Unit=autoplank.service

[Install]
WantedBy=timers.target

Additionally:
3. Create a new service to rescan and configure it to run once:

$ cat $HOME/.config/systemd/user/autoplank_scan.service 
[Unit]
Description=Autoplank Monitor Scan Service
Wants=autoplank_scan.timer

[Service]
Type=oneshot
ExecStart=/usr/local/bin/autoplank -r

[Install]
WantedBy=default.target
  1. Create a new systemd timer to trigger this rescanner. I set this to run every minute, be persistent, and to depend on the autoplank.service:
$ cat $HOME/.config/systemd/user/autoplank_scan.timer 
[Unit]
Description=Timer for the AutoPlank Scan user-mode service
Requires=autoplank.service
After=autoplank.service

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true
AccuracySec=1s

Unit=autoplank_scan.service

[Install]
WantedBy=timers.target
  1. Enable ONLY the timers and not the services and start them. Consider the dependency when starting the timers:
$ systemctl enable autoplank.timer --user
$ systemctl enable autoplank_scan.timer --user
$ systemctl start autoplank.timer --user
$ systemctl start autoplank_scan.timer --user

Note: the services will show up as Loaded but inactive, and this is fine. Both services should show they are triggered by their timers:

  • Service status:

image

image

  • Timer Status:

image

image

Thanks :)

I actually had no idea this is being used by anyone, let alone inspiring another option olback/autoplank.

Yeah, I'd probably incorporate this and add a Makefile for easy setup.

Not a problem at all. I was using Olback's but I find this one in go more stable. By the way, just to make notes on my back and forth tuning process with systemd, I find this to be a better setup:

  • Allow autoplank launch plank, and do not launch plank first by using 'startup applications' or as a user-mode service.
  • Instead of using a timer for the autoplank.service, just enable autoplank.service, which will launch plank, and set autoplank.service as follows (Enable this Service):
    File: $HOME/.config/systemd/user/autoplank.service
[Unit]                                                                
Description=Autoplank Service                                         
Before=autoplank_scan.timer                                           
                                                                      
[Service]                                                             
Type=simple                                                           
                                                                      
# Wait 5 seconds before the unit starts.                              
ExecStartPre=/bin/sleep 5                                             
                                                                      
ExecStart=/usr/local/bin/autoplank -p 200                             
                                                                      
# Using KillMode=process to stop only the main process from Autoplank.                                   
KillMode=process                                                      
Restart=always                                                        
RestartSec=15                                                         
                                                                      
[Install]                                                             
WantedBy=graphical.target                                             
  • Use a timer for the autoplank rescan (autoplank_scan.timer) as follows (Enable timer not service):
    File: $HOME/.config/systemd/user/autoplank_scan.timer
[Unit]
Description=Timer for the AutoPlank Scan user-mode service
Wants=autoplank.service                                                                                  
After=autoplank.service
     
[Timer]
#Run every 1 minute
OnCalendar=*-*-* *:*:00
Persistent=true
AccuracySec=1s
     
Unit=autoplank_scan.service
     
[Install]
WantedBy=timers.target
  • Create the autoplank rescan service (autoplank_scan.service) as follows (only enable the timer):
    File: $HOME/.config/systemd/user/autoplank_scan.service
[Unit]          
Description=Autoplank Monitor Scan Service
                
[Service]       
Type=oneshot    
                
# Wait 10 seconds before the unit starts.
ExecStartPre=/bin/sleep 10
                
ExecStart=/usr/local/bin/autoplank -r
                
# Using KillMode=process to stop only the main process from Autoplank.
KillMode=process                                                                                         
                
[Install]       
WantedBy=graphical.target

@abiosoft, again this is per my tuning which has been a work in progress but great to try and work on. Basically if we use it this way, autoplank.service will start with a 5 second delay, it will launch plank, and then the autoplank_scan.timer, which has autoplank.service as a dependency (it's a 'Wants' not a 'Requires'), will trigger autoplank_scan.service every minute with a 10 second delay. These delays are to allow autoplank.service to launch first, so it is the plank trigger and not the rescan service.

I hope it makes sense and if anything I'll post another fix to this.

Not necessarily related to this "issue" but from what I see in the execution, autoplank calls plank through the searchable path, instead of calling it through its install location (/usr/bin/plank). Not sure how much interest in maintaining it you have, but if there is appetite, I would recommend switching this call from plank -> /usr/bin/plank. Same with xdotool, xrandr, dconf, etc.