Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically run a program on startup under Linux Ubuntu [closed]

People also ask

How can you make a service run automatically after boot in Linux?

To make a service start automatically after a crash or reboot, you can add the respawn command in its service configuration files, as shown below for the cron service.

How do I make a file run at startup in Linux?

Create a script such as "startup.sh" using your favorite text editor. Save the file in your /etc/init. d/ directory. Change the permissions of the script (to make it executable) by typing "chmod +x /etc/init.


sudo mv /filename /etc/init.d/
sudo chmod +x /etc/init.d/filename 
sudo update-rc.d filename defaults 

The script should now start on boot. Note that this method also works with both hard links and symbolic links (ln).

At this point in the boot process PATH isn't set yet, so it is critical that absolute paths are used throughout. But, as pointed out in the comments by Steve HHH, explicitly declaring the full file path (/etc/init.d/filename) for the update-rc.d command is not valid in most versions of Linux. Per the manpage for update-rc.d, the second parameter is a script located in /etc/init.d/*.

Also as pointed out in the comments (by Charles Brandt), /filename must be an init style script. A good template was also provided - System V init script template.

As pointed out in the comments (by Russell Yan), this works only on default mode of update-rc.d.

According to the manual of update-rc.d, it can run on two modes: "the machines using the legacy mode will have a file /etc/init.d/.legacy-bootordering", in which case you have to pass sequence and runlevel configuration through command line arguments.

The equivalent argument set for the above example is

sudo update-rc.d filename start 20 2 3 4 5 . stop 20 0 1 6 .