V
V
vasyaputin2014-02-10 19:26:05
linux
vasyaputin, 2014-02-10 19:26:05

Why doesn't autoload work in linux (other ways to autostart ssh tunnel)?

Hello. I am familiar with Linux for the fourth day, I hate it. I hate it when everything should work, but for some reason it doesn't. However, I did everything I needed to and stopped one step away from the task.
It is necessary to execute the command automatically at system startup (connect to the server via ssh).
1. To do this, I created a script in init.d according to the sample
sudo cp /etc/init.d/skeleton /etc/init.d/myscript && vi /etc/init.d/myscript
2. Edited it, it turned out like this ( the script runs when I run /etc/init.d/myscript start):

#! /bin/sh

### BEGIN INIT INFO

# Provides:          ssh
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: Foo Bar <[email protected]>

. /lib/lsb/init-functions

# Function that starts the daemon/service

perform_start()
{
  log_daemon_msg "start tunnel"	
  sleep 20 && ssh [email protected]5X.2XX.1XX.9X -R 5544:localhost:22  -i ~/.ssh/mykeys.pem
  return 0
}

# Function that stops the daemon/service

perform_stop()
{	
  log_daemon_msg "navernoe ne nuzhno"	
}

case "$1" in  
  start)
    perform_start
    ;;
  stop)
    perform_stop
    ;;
  *)
    echo "Usage: /etc/init.d/mysc {start|stop}"
    exit 3
    ;;
esac

:

3. Added a script to runlevels like this:
sudo update-rc.d myscript start 99 2 3 4 5 . stop 01 0 1 6 .
To which I was answered:
using dependency based boot sequensing, which, as I found in Google, is a message, not an error. (Although according to the instructions, the Adding system startup for /etc/init.d/slave ... reaction should have followed). Suspicion at this stage.
4. Added execution rights like this:
sudo chmod +x /etc/init.d/myscript
Doesn't work automatically. I run the script myself - it works. There are no boot logs in the var/logs folder. When the system starts, scripts that run are shown, my script is not there. I tried to add my own line at the end of the last loaded script - it doesn't work.
Put sysv-tc-conf: my script is there, the levels are set. The bamt 1.3 system is some kind of debian, as I understand it. There is no /etc/init folder in my system.
I really need to solve the problem of auto-connecting the machine via ssh to the server (it is behind nat). If there are considerations on my method or other methods, I will listen with pleasure.

Answer the question

In order to leave comments, you need to log in

9 answer(s)
V
vasyaputin, 2014-02-11
@vasyaputin

Report for lovers of detectives. Sherlock is resting.
In general, the system does not start. Either it starts or it doesn’t start, depending on how many seconds you choose to boot into the countdown.
Started in failsafe mode. I connect via ssh through the terminal to the server - it connects. Now, through port 5544 from my home computer, I connect through this server to the one on which the witchcraft was discussed here. And I get connection refused, although before everything was always connected without problems.
I go back to the object of witchcraft and notice that in the terminal, before connecting to the server, there is a message that nothing passes through port 5544. Attention, the moment of autumn. I understand that port 5544 is already in use. But I removed everything in crontab! So what about the port? Well, it's already in use! So the original script worked all this time! I thought that if the script works, then a terminal window with a connected server should pop up on the desktop. But it turns out that all this is happening somewhere in the background (right now I don’t understand how I can get into this terminal if it starts in the background, it’s good that I don’t need it). This is where things begin to unravel, I understand that the problems with booting the system were due to the autossh startup interval of 20 seconds. Those. if I had time to quickly enter the system, then it loaded, if I waited 5 seconds,
And now another joke. From crontab, when the system boots, my script does not appear to be executed, but another program (btsync) is executed. I did not know this and therefore decided that this method suits me. At the same time, via ssh, the connection was made from a script from init.d via update-rc.d autoload.
That's it.

J
jcmvbkbc, 2014-02-10
@jcmvbkbc

-i ~/.ssh/mykeys.pem

It looks for the private key in the current user's home directory. When you run the script from yourself - in yours, when from init - in /root

I
Ilya Maltsev, 2014-02-10
@i_maltsev

You can add to /etc/crontab (possibly also using the crontab -e command) the line:
@reboot root /etc/init.d/myscript
use "root" as the path to the script, at your discretion.
If by the time the cron starts something else has not had time to load, you can do this:
@reboot root sleep 60 && /etc/init.d/myscript

D
dnsaur, 2014-02-10
@dnsaur

Set path to executable file in /etc/rc.local ?

K
ky0, 2014-02-10
@ky0

Try changing sh to bash and putting absolute paths everywhere.

Z
ZloyHobbit, 2014-02-10
@ZloyHobbit

There is a problem in ~/ hike, either write the absolute path, or put the command somewhere here: rus-linux.net/MyLDP/consol/hdrguide/rusman/profile.htm

V
vasyaputin, 2014-02-10
@vasyaputin

The last tip helped. Thanks i_maltsev ! I thought a terminal window would pop up and everything would happen in the usual way. Therefore, I spent a lot of time figuring out which of the tips helped me.

V
vasyaputin, 2014-02-10
@vasyaputin

Thank you all for responding.

V
Vlad Zhivotnev, 2014-02-10
@inkvizitor68sl

update-rc.d script defaults

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question