How to Manage Startup Applications on Ubuntu

[ad_1]

We often find ourselves launching certain programs immediately after logging into our systems. It is a time-consuming process to manually search and launch each of those programs every time Ubuntu boots up.


Some of the Linux programs are set to launch at startup. However, it is also possible to set your favorite programs, script, or commands to run automatically when Ubuntu starts up.


Launch Programs at Startup Using systemd

systemd, also known as system or service manager, is the first process that starts when Ubuntu boots. A systemd service is usually included with most Linux programs by default.

With systemd, you can also configure your programs to launch automatically when your system boots. You can use the systemctl command to manage the systemd services.

To check if the systemd unit file exists for your program, use the following command:

 systemctl list-unit-files | grep <program-name> 

Let’s say you want to automatically start Apache at system startup. Use the following command to check if a systemd unit file exists for it:

 systemctl list-unit-files | grep apache2 

If it exists, you will see an output like this:

list systemd unit files

Now, to set Apache to launch automatically on startup, run:

 sudo systemctl enable apache2 

To verify if the Apache service is enabled to run on startup, use the following command:

 sudo systemctl is-enabled apache2 

The output should return enabled if the service is set to run automatically on system startup.

check service status-1

To remove a program from running automatically when Ubuntu boots, disable its service using:

 sudo systemctl disable apache2 

If a certain program does not ship with a systemd unit (system service), you can create its systemd unit file to run it on system startup. To create a unit file, let’s say test.service, run the following command:

 sudo nano /lib/systemd/system/test.service 

Then, add the following lines of code in the unit file. Make sure to change the value of the ExecStart directive by adding the path to the program that you wish to run at startup.

In addition to a program, you can also run a command or a script at startup by specifying its path in the ExecStart directive.

 [Unit]
Description=This is a test service file.

[Service]
Type=simple
ExecStart=<Full-Path-of-Command-or-Script-or-Program>

[Install]
WantedBy=multi-user.target

Once done, save and close the unit file.

Then, assign this unit file the necessary permissions:

 sudo chmod 644 /etc/systemd/system/test.service 

Now the systemd unit file is created and you are ready to manage your program at startup using the commands described above.

Using GNOME’s Startup Applications on Ubuntu

Another way to launch frequently-used programs at startup is to use GNOME’s Startup Applications. You can launch it from the applications menu by pressing Super and typing “startup applications.” Or you can launch it by pressing Alt + F2 and typing the following command in the Run a Command dialog box:

 gnome-session-properties 
gnome session properties

This will launch the Startup Applications Preferences window where you will see a list of programs already set to run at startup.

To add a new program to the list, click Add. This will open the Add Startup Program window.

Add startup program

In the Name field, type a name for the program you want to add. Then in the Command field, provide the full path to the program’s executable binary.

To find the full path to the program, use the which command followed by the program name. For instance, to find the executable binary for Slack, the command would be:

 which slack 

Alternatively, you can click Browse and locate the program executable. You can also add any comment related to the program, although it’s optional. Once done, click Add.

You will now see the program listed in the startup programs list. The selected programs will automatically start when you sign in to your Ubuntu machine.

Startup applications list

Delay Startup Programs on Ubuntu

There might be some applications you want to launch automatically at startup, but you don’t need them immediately after login. You can add a delay in launching these applications so all of them don’t start at the same time. This will also lessen the load on your computer.

In the Startup Applications Preferences window, select the program you want to delay and click Edit. In the Command field, add sleep x before the command, where x is the amount of time (in seconds) to wait before opening the application.

Let’s say you want to start Slack 120 seconds after the system startup, so you would add:

 sleep 120; slack 
delay startup program

To remove a program from the startup programs list, launch Startup Applications Preferences window, select the application, and click Remove.

Launch Programs at Ubuntu Startup Using cron Jobs

A cron job in Linux provides a way to schedule programs, commands, or scripts to automatically run at specified times or intervals. Using cron jobs, you can also run an Ubuntu program automatically at system startup without any manual interaction.

cron jobs are defined as entries in the crontab file. Don’t edit the crontab file directly using any text editor. Instead, use the following command to edit it:

 crontab -e 

Choose the editor in which you want to edit the crontab file. Then, to add the cron job that runs after startup, use the following syntax:

 @reboot <command-or-script> 

For instance, the following cron job tells the system to check the disk space and save the output in the ~/disk-space.txt file after the system boots:

 @reboot df -h >> ~/disk-space.txt  

Save the crontab file and exit.

To remove a program from running when Ubuntu starts, simply remove its cron job entry from the crontab file.

Enable Necessary Programs to Launch at Startup on Ubuntu

Having your favorite programs already open up on startup can be very convenient as you can start using them right away after logging in to your system. However, too many startup programs can prolong the boot process.

Therefore, it is recommended to enable only the necessary programs on startup and disable occasionally used programs that are enabled by default.

[ad_2]

Source link

Leave a Reply

%d bloggers like this: