Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Debian Run commands at boot in init script

Tags:

linux

init

debian

I'm new to Linux (obviously) and I need to run some commands whenever my Linux server boots without typing them into the console manually.

I have this file called overpass.conf that runs on boot perfectly:

description 'Overpass API dispatcher daemon'

env DB_DIR=/var/www/osm/db/
env EXEC_DIR=/var/www/osm/

start on (local-filesystems and net-device-up)
stop on runlevel [!2345]

pre-start script
    rm $DB_DIR/osm3s* || true
    rm /dev/shm/osm3s* || true
end script

exec $EXEC_DIR/bin/dispatcher --osm-base --db-dir=$DB_DIR 

However, I want to also run the following:

cp -pR "/root/osm-3s_v0.7.4/rules" "/var/www/osm/db/"

nohup /var/www/osm/bin/dispatcher --areas --db-dir="/var/www/osm/db/" & 

chmod 666 "/var/www/osm/db/osm3s_v0.7.4_areas"

nohup /var/www/osm/bin/rules_loop.sh "/var/www/osm/db/" &

I have tried adding them to the bottom of the file, adding exec to the execution commands and even tried removing the quotes, then testing with start overpass but it throws errors if I add any commands to the original ones.

How can I go about executing those 4 commands after the original ones? I'm a noob in distress. Thanks!

Edit

I solved it with these commands:

vi /etc/init.d/mystartup.sh

-Add commands to the script

chmod +x /etc/init.d/mystartup.sh    
update-rc.d mystartup.sh defaults 99
like image 201
Gmeister4 Avatar asked Aug 16 '14 23:08

Gmeister4


People also ask

How do I make a script run on startup Debian?

To define a script to run at boot, you need to create a new unit for this script. To create a unit under /etc/systemd/system, you can use nano as shown in the example below, in which I create a unit named script. service, you can name it as you consider convenient to identify your script.

How do I run a command at startup?

On Windows, the simplest way of running a program at startup is to place an executable file in the Startup folder. All the programs that are in this folder will be executed automatically when the computer opens. You can open this folder more easily by pressing WINDOWS KEY + R and then copying this text shell:startup .


1 Answers

There's also

/etc/rc.local
that is executed at the end of the boot process.
like image 77
wfr Avatar answered Nov 13 '22 00:11

wfr