How to autorun a script during Linux inialization?

Asked

Viewed 1,677 times

2

I am developing a program that should run automatically soon after the startup of Linux.

To be more specific I am developing for Debian and to run on Beaglebone Black. I need to run some shell commands and then run the program.

Currently I can only run the program, but I need to run a script first. For that, I’m doing the following:

cd /lib/systemd/system/
sudo nano autorun.service

I fill with:

[Unit]
Description=Auto start software.

[Service]
WorkingDirectory=/home/debian/App/
ExecStart=/home/debian/Texas/App
KillMode=process

[Install]
WantedBy=multi-user.target

And finally:

systemctl enable rtu.service

In short, how do I auto-run a script and then the program right after booting on Linux?

  • 1

    The file has to be created every time you boot?

  • 1

    @Victorhugo I checked here and apparently does not need, the program is initiated since I have already activated it. In this case, the script is summarized only the other commands that I will add.

1 answer

3


You can put your script on /etc/rc.local. The rc.local is a script run on Linux boot to automate the start of the services desired by the user.

I didn’t understand very well if it is necessary to create the file every time it is booted, so I also added the creation of the file in the solution. If you do not need to create the file always, just remove the lines.

#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0″ on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing

# criando o arquivo autorun.service
echo "[Unit]
Description=Auto start software.

[Service]
WorkingDirectory=/home/debian/App/
ExecStart=/home/debian/Texas/App
KillMode=process

[Install]
WantedBy=multi-user.target" > /lib/systemd/system/autorun.service

# executa o comando
systemctl enable rtu.service

exit 0;

The echo writes to the default output that is redirected to the file autorun.service using >.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.