How to auto-execute a script during Linux startup?

2

I'm developing a program that should run automatically shortly after the Linux boot.

To be more specific I'm 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 before. For this, I'm doing the following:

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

Fill in 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-execute a script and then the program right after booting into Linux?

    
asked by anonymous 02.02.2014 / 21:04

1 answer

3

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

I do not quite understand if it is necessary to create the file every time it is booted, so I added the creation of the file in the solution. If you do not have to create the file at all, 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;

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

    
02.02.2014 / 21:23