Main PID: 5860 (code=exited, status=0/SUCCESS) Process: 5860 ExecStart=/usr/local/bin/update-repositories-on-bootup (code=exited, status=0/SUCCESS) Loaded: loaded (/etc/systemd/system/rvice enabled vendor preset: enabled)Īctive: inactive (dead) since Sun 02:05:07 CET 8s ago rvice - Update package repositories on bootup after network is up.Then, we can check the status of the service using the systemctl status command: $ sudo systemctl status update-repositories-on-bootup $ sudo systemctl start update-repositories-on-bootup Furthermore, the condition After=network-online.target ensures that the service runs after the system is online. Additionally, the service runs the /usr/local/bin/update-repositories-on-bootup script on starts up. The unit file above defines a SystemD service unit update-repositories-on-bootup. Importantly, we’ll specify that our service is dependent on the network connectivity being up using the After=network-online.target construct: $ cat /etc/systemd/system/rviceĭescription=Update package repositories on bootup after network is upĮxecStart=/usr/local/bin/update-repositories-on-bootup In the file, we point the ExecStart directive to our update-repositories-on-bootup script. Concretely, we’ll create an rvice unit file in the /etc/systemd/system directory. SystemD Serviceįirstly, we must create a service unit for our update-repositories-on-bootup script. ![]() This allows our script to always run on a fresh boot. On subsequent runs in the same boot session, the presence of the flag file will cause the script to not invoke the main command.Ĭritically, we put this flag file in the /var/run directory to ensure that it doesn’t survive a reboot. Otherwise, we’ll run the command as usual and create the flag file /var/run/has_update_repositories_run before we return. In our enhancement, we added a condition to skip the execution if the has_update_repositories flag file exists. Touch /var/run/has_update_repositories_run Sudo apt-get update &> /var/run/update-repositories-on-bootup-output-$.log ![]() If test -e /var/run/has_update_repositories_run then Subsequently, the script will skip if it detects the presence of the flag file: $ cat /etc/network/if-up.d/update-repositories-on-bootup Concretely, we can create a flag file after we first run the script. One trick we can use to ensure that the script only runs once in a single boot session is to utilize a flag file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |