Proper systemd escaped mount name

Due dash in my mount names I need to escape them and to avoid error I searched for proper solution, more at https://stackoverflow.com/a/53954762/289404 and https://sleeplessbeastie.eu/2019/09/23/how-to-mount-nfs-share-using-systemd/

$ systemd-escape -p --suffix=mount "/media/usb-5tb-old"
media-usb\x2d5tb\x2dold.mount

Or if mounted you might check systemctl list-units --type=mount

$ systemctl list-units --type=mount
  UNIT                                                              LOAD   ACTIVE SUB     DESCRIPTION                                        
  -.mount                                                           loaded active mounted Root Mount
  boot.mount                                                        loaded active mounted /boot
  dev-hugepages.mount                                               loaded active mounted Huge Pages File System
  dev-mqueue.mount                                                  loaded active mounted POSIX Message Queue File System
  home.mount                                                        loaded active mounted /home
  media-usb\x2d4tb.mount                                            loaded active mounted /media/usb-4tb
  media-usb\x2d5tb.mount                                            loaded active mounted /media/usb-5tb
  media-usb\x2d5tb\x2dold.mount                                     loaded active mounted /media/usb-5tb-old

as I solved it before in the past https://michalzuber.wordpress.com/2021/05/06/transmission-daemon-wait-for-mount/

Prevent sleep on Suspend key press in Linux

With my new keyboard I was almost always hitting the Fn combination for computer Suspend/Sleep.

Today I decided to tackle this annoying issue.

After hitting the Suspend key combination I checked journalctl

Feb 04 14:01:57 mike-desktop root[3764759]: SleepButton pressed
Feb 04 14:01:57 mike-desktop systemd-logind[718]: Suspend key pressed short.
Feb 04 14:01:57 mike-desktop systemd-logind[718]: Suspending...

After checking out first two entries from search results my mind came up to ask at chat.openai.com

His first result was the solution for me. Edit /etc/systemd/logind.conf and set the following

HandlePowerKey=ignore
HandleSuspendKey=ignore

After restart, victory. Suspend key press is no more suspending the computer.

Transmission daemon wait for mount

After reboot I had to manually start transmission due ConditionPathIsDirectory=/media/usb-4tb/torrent

Finally found the solution at https://unix.stackexchange.com/a/247547/39470

With systemctl list-units --type=mount just list your mounts and add the unit name to After=

My /etc/systemd/system/transmission.service looks the following now

[Unit]
Description=Transmission BitTorrent Daemon
After=network.target systemd-networkd-wait-online.service media-usb\x2d4tb.mount
ConditionPathIsDirectory=/media/usb-4tb/torrent

StartLimitIntervalSec=500
StartLimitBurst=3 # Only 3 retries of restart

[Service]
User=transmission
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error
ExecReload=/bin/kill -s HUP $MAINPID
NoNewPrivileges=true
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Overwriting httpd.service PrivateTmp

While setting up Xdebug I had to change the httpd.service systemd unit file to don’t use private tmp dir in /tmp

For locating the unit file I just used

locate httpd.service

Then needed to copy it, edit and reload the daemon config.

sudo cp /usr/lib/systemd/system/httpd.service /etc/systemd/system
sudo vim /etc/systemd/system/httpd.service
sudo systemctl daemon-reload
sudo systemctl restart httpd.service

systemd user timers (cron alternative)

After system reinstall I had some issues fixing my user systemd timers. Because I copied the files from backup to .config/systemd/user/ the system yell at me with Failed to execute operation: Invalid argument
After googling I found solution at http://stackoverflow.com/a/33363732/289404

I had disabled timer-{daily,weekly,hourly}.timer

$ systemctl --user list-unit-files
UNIT FILE                  STATE
dbus.service               indirect
mpd.service                disabled
mpdas.service              enabled 
systemd-bus-proxyd.service static
systemd-exit.service       static
dbus.socket                disabled
systemd-bus-proxyd.socket  static
basic.target               static
bluetooth.target           static
busnames.target            static
default.target             static
exit.target                static
paths.target               static
printer.target             static
shutdown.target            static
smartcard.target           static
sockets.target             static
sound.target               static
timer-daily.target         static
timer-hourly.target        static
timer-weekly.target        static
timers.target              static
timer-daily.timer          disabled
timer-hourly.timer         disabled
timer-weekly.timer         disabled

So after

$ rm ~/.config/systemd/user/basic.target.wants/timer-*

and

$ systemctl --user enable timer-weekly.timer
$ systemctl --user enable timer-daily.timer
$ systemctl --user enable timer-hourly.timer

I got the timers enabled

 $ systemctl --user list-unit-files |grep timer
timer-daily.target         static  
timer-hourly.target        static  
timer-weekly.target        static  
timers.target              static  
timer-daily.timer          enabled 
timer-hourly.timer         enabled 
timer-weekly.timer         enabled

Great how-to is at https://blog.higgsboson.tk/2013/06/09/use-systemd-as-a-cron-replacement/

systemd timer daily at specific time

I had to change the daily timers time of execution, I wanted it to start at 8am so had to change ~/.config/systemd/user/timer-daily.timer from monotonic to realtime.

[Unit]
Description=Daily Timer

[Timer]
# OnBootSec=10min
# OnUnitActiveSec=1d
# Daily at 8am
OnCalendar=*-*-* 08:00:00
Persistent=True
Unit=timer-daily.target

[Install]
WantedBy=basic.target

Next daemon-reload

$ systemctl --user daemon-reload

And voila:

$ systemctl --user list-timers
NEXT                         LEFT        LAST                         PASSED        UNIT               ACTIVATES
Sun 2015-02-15 09:47:17 CET  18min left  Sun 2015-02-15 08:47:17 CET  41min ago     timer-hourly.timer timer-hourly.target
Mon 2015-02-16 08:00:00 CET  22h left    Sun 2015-02-15 09:28:14 CET  25s ago       timer-daily.timer  timer-daily.target
Fri 2015-02-20 10:21:17 CET  5 days left Fri 2015-02-13 10:21:17 CET  1 day 23h ago timer-weekly.timer timer-weekly.target

For more about systemd.timer check http://www.freedesktop.org/software/systemd/man/systemd.timer.html

logrotate error: stat of /var/log/xferlog failed

In Arch Linux the logrotate service was failing:

user@host# systemctl start logrotate.service 
Job for logrotate.service failed. See "systemctl status logrotate.service" and "journalctl -xe" for details.

So I ran it by hand to debug:

user@host# logrotate /etc/logrotate.conf

And the following error appeared:

logrotate error: stat of /var/log/xferlog failed

I fired up a grep for xferlog in the /etc directory:

user@host:/etc# grep -r xferlog *
logrotate.d/proftpd:/var/log/xferlog

Solution was commenting the xferlog rule in logrotate.d/proftpd. I don’t need the transfer log.