Difference between revisions of "Automatically launch your application"
From ArmadeusWiki
(creation) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
==System startup== | ==System startup== | ||
First, a small remainder: when you start your board, here is how all things are started: | First, a small remainder: when you start your board, here is how all things are started: | ||
− | # U-Boot initializes the | + | # U-Boot initializes the processor, vital peripherals and then load Linux image from Flash, |
− | # Linux mounts its rootfs and launches ''/sbin/init'' | + | # U-Boot starts Linux image by passing it some parameters, the ''bootargs'', |
− | # ''init'' process checks its ''/etc/inittab'' config file and executes the instructions it contains | + | # Linux starts, mounts its rootfs and launches ''/sbin/init'', |
− | # this config | + | # ''init'' process checks its ''/etc/inittab'' config file and executes the instructions it contains, |
− | # ''/etc/init.d/rcS'' | + | # this config file generally asks ''init'' to launch ''/etc/init.d/rcS'' at some point, |
+ | # ''/etc/init.d/rcS'' look at all scripts in ''/etc/init.d/'' directory which start with a '''S''', and executes them in ascending order | ||
− | ==Adding your own | + | ==Adding your own application in the system start process== |
* creates a shell script in ''/etc/init.d/'': | * creates a shell script in ''/etc/init.d/'': | ||
<pre class="apf"> | <pre class="apf"> | ||
Line 24: | Line 25: | ||
#!/bin/sh | #!/bin/sh | ||
− | /usr/bin/your_app & | + | # Loading the modules needed by my app: |
+ | modprobe xxxxx | ||
+ | |||
+ | # Launching my app: | ||
+ | /usr/bin/your_app & # <-- Don't forget the "&" otherwise other system stuff won't start until you leave your app !!! | ||
exit 0 | exit 0 | ||
</source> | </source> | ||
− | * save your changes and | + | * save your changes and '''!! Test it !!''' |
+ | <pre class="apf"> | ||
+ | # /etc/init.d/S99app | ||
+ | </pre> | ||
+ | |||
+ | * That's it ! You can now reboot: | ||
+ | <pre class="apf"> | ||
+ | # sync | ||
+ | # reboot | ||
+ | </pre> | ||
+ | |||
+ | ==Launching an application only on user login== | ||
+ | * you may also prefer to launch your application only when a given user has logged in. | ||
+ | * indeed, after ''init'' has launched all the startup scripts, it generally gives the hand to getty and login tools that allow a user to login on the serial console or any other terminal. | ||
+ | * create a user account (here user ''test'') and assign it a password: | ||
+ | <pre class="apf"> | ||
+ | $ adduser test | ||
+ | Changing password for test | ||
+ | New password: | ||
+ | Retype password: | ||
+ | Password for test changed by root | ||
+ | </pre> | ||
+ | * leave root and log in as the new user: | ||
+ | <pre class="apf"> | ||
+ | $ exit | ||
+ | Welcome to the Armadeus development environment. | ||
+ | armadeus login: test | ||
+ | Password: | ||
+ | $ id | ||
+ | uid=1001(test) gid=1001(test) groups=1001(test) | ||
+ | </pre> | ||
+ | * ''/home/test/'' directory was automatically created. Add the instructions to execute in the ''/home/test/.profile'' file: | ||
+ | <pre class="apf"> | ||
+ | $ cat > /home/test/.profile <<EOF | ||
+ | echo "You just logged in !!" | ||
+ | EOF | ||
+ | </pre> | ||
==Links== | ==Links== | ||
* [[Linux_Boot_Logo| How to customize your boot Logo]] | * [[Linux_Boot_Logo| How to customize your boot Logo]] | ||
+ | |||
+ | [[Category:Startup]] |
Latest revision as of 19:16, 17 April 2013
You've just developed a state of the art application and want it to be launched each time you boot your APF ? Then this small tutorial is for you !
Contents
System startup
First, a small remainder: when you start your board, here is how all things are started:
- U-Boot initializes the processor, vital peripherals and then load Linux image from Flash,
- U-Boot starts Linux image by passing it some parameters, the bootargs,
- Linux starts, mounts its rootfs and launches /sbin/init,
- init process checks its /etc/inittab config file and executes the instructions it contains,
- this config file generally asks init to launch /etc/init.d/rcS at some point,
- /etc/init.d/rcS look at all scripts in /etc/init.d/ directory which start with a S, and executes them in ascending order
Adding your own application in the system start process
- creates a shell script in /etc/init.d/:
# touch /etc/init.d/S99app # chmod a+x /etc/init.d/S99app
- edit it
# vi /etc/init.d/S99app
- put in it the following content (replace /usr/bin/your_app with your application name & path):
#!/bin/sh
# Loading the modules needed by my app:
modprobe xxxxx
# Launching my app:
/usr/bin/your_app & # <-- Don't forget the "&" otherwise other system stuff won't start until you leave your app !!!
exit 0
- save your changes and !! Test it !!
# /etc/init.d/S99app
- That's it ! You can now reboot:
# sync # reboot
Launching an application only on user login
- you may also prefer to launch your application only when a given user has logged in.
- indeed, after init has launched all the startup scripts, it generally gives the hand to getty and login tools that allow a user to login on the serial console or any other terminal.
- create a user account (here user test) and assign it a password:
$ adduser test Changing password for test New password: Retype password: Password for test changed by root
- leave root and log in as the new user:
$ exit Welcome to the Armadeus development environment. armadeus login: test Password: $ id uid=1001(test) gid=1001(test) groups=1001(test)
- /home/test/ directory was automatically created. Add the instructions to execute in the /home/test/.profile file:
$ cat > /home/test/.profile <<EOF echo "You just logged in !!" EOF