Start a own written program at boot

If none of the more specific forums is the right place to ask

Start a own written program at boot

Postby rasidrasid » 2018-09-14 12:22

Hello,

I am using wheezy as a server (without a Desktop). I wrote a program that I want to start at startup/at boot. This program is actually in my home directory. So please, how can I link it, move it or do it somehow to start it in the boot phase? Thanks.

Regards
rasidrasid
 
Posts: 4
Joined: 2018-09-14 12:14

Re: Start a own written program at boot

Postby None1975 » 2018-09-14 12:33

Hello. Check this. Maybe you will find this link helpful.
OS: Debian 9.5 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 668
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: Start a own written program at boot

Postby rasidrasid » 2018-09-14 12:40

Thank you. I thought it would be easy like link it to any runlevel or so :D
It could be that I be wrong.
rasidrasid
 
Posts: 4
Joined: 2018-09-14 12:14

Re: Start a own written program at boot

Postby GarryRicketson » 2018-09-14 13:14

Some more details on this "program" would help, is it really a program or
just a script, ?
You might be able to start it using the '/etc/rc.local'
also " init.d " or ' crontab ' are options.
Code: Select all
man init.d

Code: Select all
man crontab


Did you try searching, using these :
Code: Select all
How to make a program start at boot on Debian 7 wheezy
key words ?
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Start a own written program at boot

Postby HankB » 2018-09-14 13:25

You can run something from cron at boot from the man page for crontab(5)
Code: Select all
man 5 crontab
...
 Instead of the first five fields, one of eight special strings may appear:

              string         meaning
              ------         -------
              @reboot        Run once, at startup.
              @yearly        Run once a year, "0 0 1 1 *".
              @annually      (same as @yearly)
              @monthly       Run once a month, "0 0 1 * *".
              @weekly        Run once a week, "0 0 * * 0".
              @daily         Run once a day, "0 0 * * *".
              @midnight      (same as @daily)
              @hourly        Run once an hour, "0 * * * *".
...

You can put this in your crontab file with the command `crontab -e` or in the root crontab by running that command as root.
If you haven't worked with cron before, be aware that it runs the commands with a stripped down environment - not your login environment. For example if your program is ~/bin/command you would need to specify '/home/username/bin/command' in the crontab file. It is also wise to redirect output somewhere you can look at it in case the job doesn't produce the desired results. '>/tmp/command.txt 2>&1` will work for sh or bash shells. I'm afraid I don't recall which shell cron uses to run commands.

/etc/rc.local would be the easiest way but I don't see it on my systems so I don't know if it still works.

You can also configure this using systemd but that takes a bit more work. However it can provide the benefit of restarting your program if it crashes.

HTH,
hank
HankB
 
Posts: 46
Joined: 2012-03-07 15:15

Re: Start a own written program at boot

Postby rasidrasid » 2018-09-14 13:36

Hello.

Thank you all.
The program is a script, yes thas true :D

Until now I tried this: I put a softlink (ln -s) in every runlevel with a "S" letter at start of the name. But it wont worked. I did the same in /etc/init.d, but without success.

I overcome such a problem in former times exactly like that, but the os was ubuntu. Now I want to do this with debian :wink:

regards
rasidrasid
 
Posts: 4
Joined: 2018-09-14 12:14

Re: Start a own written program at boot

Postby GarryRicketson » 2018-09-14 13:54

Ok, well, here is one that applies to Bash scripts, and using /etc/rc.local :
https://serverfault.com/questions/735621/debian-how-to-run-a-script-on-startup-without-having-to-write-30-lines-of-shell

If it is not a bash script, but perl (for example), it still could be used, with some
modification.
This might be of help to you as well:
https://debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Start a own written program at boot

Postby rasidrasid » 2018-09-14 14:57

Thanks. I will try it.
rasidrasid
 
Posts: 4
Joined: 2018-09-14 12:14

Re: Start a own written program at boot

Postby debiman » 2018-09-15 10:32

please be aware that wheezy has been outdated & EOL for a long while now.
you really should upgrade.
in any case, no solution involving systemd will work.
User avatar
debiman
 
Posts: 3008
Joined: 2013-03-12 07:18


Return to General Questions

Who is online

Users browsing this forum: flipjargendy and 13 guests

fashionable