How can I run my own script every time I load

My question is how can I run my own bash script every time I run it in Ubuntu. Suppose I have a script that does a specific job. Now I want it to start automatically when my Ubuntu system starts.

+3
linux bash ubuntu startup
source share
4 answers

You should learn to use the upstart. See this .

+5
source share

Currently, Linux systems (including Ubuntu) support two ways to achieve this: Upstart scripts and SysV. Upstart is a "new" way.

SysV scripting can be done as follows:

update-rc.d <your script> defaults 

This will create links to start the service at runlevel 2345 and stop the service at runlevel 016 and create the appropriate SysV style scripts inside /etc/rc?.d/

Another way would be to write an upstart job. Accelerated jobs are under / etc / init. The easiest way is to copy an existing task and try to change it for the script. The stanzas upstart is explained here.

+1
source share

There are two options. Easy, edit /etc/rc.local and call the script from there. Another option is to use an upstart. Locate the /etc/init/hostname.conf file. You can use this file as a template, copy it as /etc/init/yourscript.conf, adapt the content and work.

0
source share

Recently, I came across a situation where one job ideally began with an upstart, and the other with rc.local. Although both methods will execute your script, the upstart makes sense when demonstrating the script at run time; rc.local, on the other hand, allows you to run a script.

For example, if the script is already a daemon process, for example. server, it can be called by rc.local, since it does not stay in the foreground and blocks the terminal.

But if the script itself is not demonized, the upstart will give it the ability to gracefully start and stop during system events. This is useful for running a non-exiting PHP script in the background. Although you can use the upstart to launch, say, Apache httpd, the process "exits right away" in Upstart's eyes, which makes Upstart pointless because it is already "completed".

0
source share

All Articles