Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a script at the start up of Ubuntu? [closed]

I want to run some Java programs in the background when the system boots in Ubuntu. I have tried to add a script in /etc/init.d directory but failed to start a program. i.e programs are not started. What should I do for that?

like image 938
Anand Soni Avatar asked Dec 01 '11 10:12

Anand Soni


People also ask

How do I get a script to run on startup Ubuntu?

The Ubuntu 20.04 is based on Systemd hence the simplest and recommended way to run a script on startup is to create a Systemd service file and execute any script such as bash, python etc, via this service during the system boot.

How do I get a script to run on startup?

On Windows, the simplest way of running a program at startup is to place an executable file in the Startup folder. All the programs that are in this folder will be executed automatically when the computer opens. You can open this folder more easily by pressing WINDOWS KEY + R and then copying this text shell:startup .


1 Answers

First of all, the easiest way to run things at startup is to add them to the file /etc/rc.local.

Another simple way is to use @reboot in your crontab. Read the cron manpage for details.

However, if you want to do things properly, in addition to adding a script to /etc/init.d you need to tell ubuntu when the script should be run and with what parameters. This is done with the command update-rc.d which creates a symlink from some of the /etc/rc* directories to your script. So, you'd need to do something like:

update-rc.d yourscriptname start 2 

However, real init scripts should be able to handle a variety of command line options and otherwise integrate to the startup process. The file /etc/init.d/README has some details and further pointers.

like image 57
opqdonut Avatar answered Sep 19 '22 13:09

opqdonut