Dariusz on Software

Methods and Tools

About This Site

Software development stuff


User Process Autostart Under Linux
Thu, 08 Dec 2011 21:52:49 +0000

Sometimes you want your user-level program to be automatically started on every Linux reboot. Scared of complicated SYSV startup scripts? Don't panic, this task is easier than you think!

First of all you need root access on a machine to install startup script. Default startup scripts are placed in /etc/init.d directory and special symbolic link must be created under /etc/rc5.d (at least on Debian-based systems).

First let's create startup script for your "daemon"-like program:

#! /bin/sh
case "$1" in
    su -c /home/darek/bin/myprogram.sh darek &
    killall myprogram.sh
    su -c /home/darek/bin/myprogram.sh darek &
    killall myprogram.sh
    echo "Usage: $0 start|stop" >&2
    exit 3

Note that "darek" is the user id that will be used for starting up the script.

Then: ensure it's executable and create symbolic link for default runlevel (5 on Debian):

chmod +x /etc/init.d/myprogram
cd /etc/rc5.d
ln -s ../init.d/myprogram S80myprogram

"S" means "start", "80" allows to ordered execution. Pretty simple!

SYSV init scripts are harded to setup than BSD-style, but are more flexible and easier to manage by installation tools (dpkg under Debian).

Tags: linux.


Created by Chronicle v3.5