LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2011, 03:50 PM   #1
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Question Adding start up script in rcX.d --> Via update-rc SCRIPT defaults .... :-(


I am trying to learn how to add start up scripts and I am not quote getting it. So far -->

1. Wrote a basic functional script ( well it works when invoked in bash)
2. ran update-rc Linkup defaults
3. checked sysv-rc & it is set to run in the correct run levels.

-----> No dice.

I have done some research on the LSB style headers that are required but I am not sure I am 100% on target.


Any & all direction would be appreciated.

Process commands:

Quote:

sudo vi Linkup # Drafted script

sudo cp -v /home/joe/Scripts/Linkup /etc/init.d/ # moved to the needed directory

sudo update-rc.d Linkup defaults # set up for rcXd sequencing.

sysv-rc-conf : checked if it was working

sudo shutdown -r now # rebooted

No dice .....................................................

Script :

Quote:
#! /bin/bash

### BEGIN INIT INFO
# Provides: linkup
# Required-Start: $remote_fs $syslog $ssh $sshfs
# Required-Stop: $remote_fs $syslog $ssh $sshfs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: sshfs - Needed drives
# Description: Lan - Needed drives
### END INIT INFO


# Little-Tux

sshfs amy@192.168.1.6:/ /media/Little-Tux/

# XMBC

sshfs media@192.168.1.3:/ /media/XMBC/

Distro : Debian Testing
 
Old 07-02-2011, 04:55 PM   #2
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
LSB headers look good. It is rather that your script lacks start and stop functions.

On a system with SysV init scripts, the init process executes the script given on the sysinit action line, and after the script on the runlevel line.
On debian :
Code:
si::sysinit:/etc/init.d/rcS
[...]
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
[...]
/etc/init.d/rcS script invokes /etc/init.d/rc script

Look at /etc/init.d/rc script.
You will see that, according to the runlevel parameter, all scripts in /etc/rc$runlevel/S (for start) or /etc/rc$runlevel/K (for stop) will be executed, with start (or stop) as first parameter.

So, add your own start and stop functions in your script, and all will be fine
 
Old 07-02-2011, 05:39 PM   #3
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Exclamation

Thanks for the reply and assistance. Can you offer any suggestions on syntax / code ?

I made an attempt but no dice.


Quote:

#! /bin/bash

### BEGIN INIT INFO
# Provides: linkup
# Required-Start: $remote_fs $syslog $ssh $sshfs
# Required-Stop: $remote_fs $syslog $ssh $sshfs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: sshfs - Needed drives
# Description: Lan - Needed drives
### END INIT INFO



# Start the service
start() {
/etc/init.d/Linkup &
}

# Restart the service Linkup
stop() {
/etc/init.d/Linkup stop
}



# Little-Tux

sshfs amy@192.168.1.6:/ /media/Little-Tux/

# XMBC

sshfs media@192.168.1.3:/ /media/XMBC/




 
Old 07-02-2011, 06:58 PM   #4
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
Thumbs up

Well, after reading myself, what I said is really true only for the stop case... Sorry for the mistake.

Anyway, it is better to write an SysVInit script according to usual standards (managing parameters start, stop, ...) like this one (not tested) :
Code:
#! /bin/bash
### BEGIN INIT INFO
# Provides: linkup
# Required-Start: $remote_fs $syslog $ssh $sshfs
# Required-Stop: $remote_fs $syslog $ssh $sshfs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: sshfs - Needed drives
# Description: Lan - Needed drives
### END INIT INFO

SCRIPTNAME=linkup
PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "$1" in
  start)
        echo -n "Starting $SCRIPTNAME"
        # Little-Tux
        #you could need to give the absolute path to sshfs
        sshfs amy@192.168.1.6:/ /media/Little-Tux/
        # XMBC
        #you could need to give the absolute path to sshfs
        sshfs media@192.168.1.3:/ /media/XMBC/

        # Alternative, if you need to execute it from another user, for example called toto :
        # Little-Tux
        #you could need to give the absolute path to sshfs
        #/bin/su - toto -c "sshfs amy@192.168.1.6:/ /media/Little-Tux/"
        # XMBC
        #you could need to give the absolute path to sshfs
        #/bin/su - toto -c "sshfs media@192.168.1.3:/ /media/XMBC/"

        echo "$SCRIPTNAME started"
        ;;
  stop)
        echo -n "Stopping $SCRIPTNAME"
        umount -a -t fuse.sshfs

        echo "$SCRIPTNAME stopped"
        ;;

  *)
        echo "Usage: /etc/init.d/$SCRIPTNAME {start|stop}"
        exit 1
esac

exit 0

BUT, what could still be a problem is :
- sshfs command may not be in the PATH during init (so change the PATH variable or give the full path)
- Do you have created a public key with no passphrase between the local root user (which should be the one executing the script during init) and the amy user of 192.168.1.6 ?
Otherwise, the script will wait for an interactive user input, which cannot be done at boot time
- Same question and remark, this time between the local root user and the media user of 192.168.1.3

Remarks :
- If the sshfs command is not intended to be executed by the root user, you will have to use something like su -c, as shown in the script
- What miss in this script is a mechanism to forbid to execute several times this script (ans so mounting several times the same filesystems)
 
Old 07-03-2011, 05:03 AM   #5
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
Edit #1 :
umount -a -t fuse.sshfs
could be replaced by
fusermount -u /media/Little-Tux/
fusermount -u /media/XMBC/
in stop function

Edit #2 :
Rather than using an init script, you could directly add relevant lines in /etc/fstab
For example, with yourlocaluid and yourlocalgid to be replaced :
sshfs#amy@192.168.1.6:/ /media/Little-Tux/ fuse user,uid=yourlocaluid,gid=yourlocalgid,exec,idmap=user,noauto,allow_other 0 0
sshfs#media@192.168.1.3:/ /media/XMBC/ fuse user,uid=yourlocaluid,gid=yourlocalgid,exec,idmap=user,noauto,allow_other 0 0

Edit #3 :
mmh, the /etc/fstab solution does not work (the network must not be up. I added noauto option, so that it does not automatically mount at boot time

Last edited by aysheaia; 07-03-2011 at 05:43 AM.
 
Old 07-04-2011, 05:47 AM   #6
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Thanks for taking the time to help me. I appreciate the effort. I tried your modified version and still no dice.

Quote:

BUT, what could still be a problem is :
- sshfs command may not be in the PATH during init (so change the PATH variable or give the full path)
- Do you have created a public key with no passphrase between the local root user (which should be the one executing the script during init) and the amy user of 192.168.1.6 ?
Otherwise, the script will wait for an interactive user input, which cannot be done at boot time
- Same question and remark, this time between the local root user and the media user of 192.168.1.3

Remarks :
- If the sshfs command is not intended to be executed by the root user, you will have to use something like su -c, as shown in the script
- What miss in this script is a mechanism to forbid to execute several times this script (ans so mounting several times the same filesystems)
07-02-11 06:39 PM
I shared my key with the machines in question & I can ssh or sshfs without a password. However I just thought that I would need to do that for root?


............ I am going to give that a try.....
 
Old 07-04-2011, 06:19 AM   #7
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Original Poster
Rep: Reputation: 106Reputation: 106
Cool

I tried generating a key (ssh-keygen ) for root then passing to the ".ssh/authorized_keys" of the two machines and it worked, sort of.

But it would only let root access. I could not even change owner or mode as root. So I then took the route of changing the script to your second suggestion ( su to another user to process the commands) and it worked like a charm



Thanks again for all of your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Start-Up Script & Shutdown/Kill Script needed guggilamsandeep Red Hat 1 05-11-2011 08:58 AM
Shell script adding autostart gnome script Coolrunr Programming 3 01-01-2009 02:23 PM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration