You're really looking to use After=network-online.target instead of Requires=network.target. I'd recommend putting your custom script in /usr/local/bin/ instead of /usr/bin/. And then if your system is up for a while maybe use a timer service to rerun the script every 24 hours.
Create a systemd service unit file
Let's create a service unit file. You may create a file named wallpaper.service in the /etc/systemd/system/ directory. Note that you require root privileges to do so. Use a text editor like nano or vim to create and edit the file:
sudo nano /etc/systemd/system/wallpaper.service
Paste in the following, making sure to adjust paths if necessary:
[Unit]
Description=Downloads the APOD and saves it as Wallpaper
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/local/bin/bg.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save and close the file.
Create a systemd timer unit file
Now we'll create a corresponding timer for our service. Create a new file /etc/systemd/system/wallpaper.timer:
sudo nano /etc/systemd/system/wallpaper.timer
Paste in the following:
[Unit]
Description=Runs bg.sh every day
[Timer]
OnBootSec=0min
OnUnitActiveSec=24h
[Install]
WantedBy=timers.target
In the [Timer] section, OnBootSec=0min means the service will run immediately after the system boots. OnUnitActiveSec=24h means the service will rerun 24 hours after it was last activated.
Save and close the file.
Reload systemd daemon and enable the timer
Next, reload the systemd daemon to make it aware of your new service and timer. Then, enable and start the timer:
The /usr/bin and /usr/local/bin directories are part of the Unix/Linux filesystem hierarchy, and they both serve different purposes.
/usr/bin: This is the primary directory of executable commands on the system. It's managed by the system's package manager (apt, yum, dnf, etc.) and should only contain binaries provided and managed by the system's package management. When you update your system, updates to programs within this directory will be handled by your package manager.
/usr/local/bin: This is intended for executables that are local to the machine, i.e., not part of the system's standard distribution. This includes scripts and binaries installed manually by the system administrator. This directory is usually included in a user's PATH, meaning executables here can be run directly from the command line without specifying the full path.
The main reason for keeping custom scripts in /usr/local/bin instead of /usr/bin is to avoid interfering with the system's package manager.
If you were to place your custom scripts in /usr/bin, it could potentially be erased or overwritten when you update your system. Additionally, you might unintentionally replace a system command with one of your scripts, which could cause unexpected behavior.
Placing custom scripts in /usr/local/bin helps keep them separate from system-managed binaries and reduces the risk of conflicts.
You're really looking to use
After=network-online.targetinstead ofRequires=network.target. I'd recommend putting your custom script in/usr/local/bin/instead of/usr/bin/. And then if your system is up for a while maybe use a timer service to rerun the script every 24 hours.Create a systemd service unit file
Let's create a service unit file. You may create a file named
wallpaper.servicein the/etc/systemd/system/directory. Note that you require root privileges to do so. Use a text editor likenanoorvimto create and edit the file:Paste in the following, making sure to adjust paths if necessary:
Save and close the file.
Create a systemd timer unit file
Now we'll create a corresponding timer for our service. Create a new file
/etc/systemd/system/wallpaper.timer:Paste in the following:
In the
[Timer]section,OnBootSec=0minmeans the service will run immediately after the system boots.OnUnitActiveSec=24hmeans the service will rerun 24 hours after it was last activated.Save and close the file.
Reload systemd daemon and enable the timer
Next, reload the systemd daemon to make it aware of your new service and timer. Then, enable and start the timer:
Check the status of your timer
To make sure your timer is active and will trigger the service as expected, check its status:
That's it. Your script should now run at startup (with a delay until the network is up) and once daily.
The
/usr/binand/usr/local/bindirectories are part of the Unix/Linux filesystem hierarchy, and they both serve different purposes./usr/bin: This is the primary directory of executable commands on the system. It's managed by the system's package manager (apt,yum,dnf, etc.) and should only contain binaries provided and managed by the system's package management. When you update your system, updates to programs within this directory will be handled by your package manager./usr/local/bin: This is intended for executables that are local to the machine, i.e., not part of the system's standard distribution. This includes scripts and binaries installed manually by the system administrator. This directory is usually included in a user'sPATH, meaning executables here can be run directly from the command line without specifying the full path.The main reason for keeping custom scripts in
/usr/local/bininstead of/usr/binis to avoid interfering with the system's package manager.If you were to place your custom scripts in
/usr/bin, it could potentially be erased or overwritten when you update your system. Additionally, you might unintentionally replace a system command with one of your scripts, which could cause unexpected behavior.Placing custom scripts in
/usr/local/binhelps keep them separate from system-managed binaries and reduces the risk of conflicts.https://wiki.archlinux.org/index.php/GDM#Hide_user_from_login_list
https://github.com/elFarto/nvidia-vaapi-driver/issues/126
https://wiki.archlinux.org/index.php/LightDM#Hiding_system_and_services_users