LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-26-2008, 12:21 PM   #1
smt52
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 0
Script to make Hamachi run reliably under Linux


#! /bin/sh
#

# Used to reliably log in/out of Hamachi
# (c) 2008 Shane Tolmie of www.microchipc.com

# set your specific network here
NICKNAME="linux-usa"
NETWORK="testing123#"
PASSWORD="234ksdjf342"
CONFIG_FOLDER="/hamachi"
DELAY_SEC="1" # used if there is connection problems

# There are two obstacles to running Hamachi reliably under Linux:
# 1) not using delays between commands (the Hamachi server does not respond in time, and the login fails)
# 2) not logging out of the Hamachi server properly before an OS reboot.
# So, if you encounter issues, try execute the command "hamachi logout" before rebooting.
# This script can be added to /etc/init.d/ (under SuSE) to automatically log in/out of Hamachi.
# Once you copy the file to /etc/init.d/ you have to activate it (make it run on startup/shutdown)
# - On SuSE, go into Administrator settings, then System..System Services (RunLevel).
# - On other Linux distributions, there is a command add the script to the startup/shutdown sequence.
#
# Usage:
# hamachi-daemon.sh config # adds this machine to the network (network must already exist)
# hamachi-daemon.sh start # starts services
# hamachi-daemon.sh stop # stops services
# hamachi-daemon.sh restart # restarts services (used if there is issues connecting)
# hamachi-daemon.sh list # lists machines on the network

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting Hamachi"
tuncfg >null
hamachi -c $CONFIG_FOLDER start
hamachi -c $CONFIG_FOLDER login
hamachi -c $CONFIG_FOLDER go-online $NETWORK
exit 0
;;
stop)
echo "Stopping Hamachi"
sleep $DELAY_SEC # if start was executed immediately before stop it might fail
hamachi -c $CONFIG_FOLDER go-offline $NETWORK
hamachi -c $CONFIG_FOLDER logout
hamachi -c $CONFIG_FOLDER stop
exit 0
;;
#this method has been tested and works well
#this method does not seem to work without the delays
restart)
echo "Stopping Hamachi"
hamachi -c $CONFIG_FOLDER go-offline $NETWORK
sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER leave $NETWORK
sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER logout
#sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER stop
sleep $DELAY_SEC #wait for timeout
echo "Starting Hamachi"
tuncfg >null
hamachi -c $CONFIG_FOLDER start
#sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER login
sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER join $NETWORK $PASSWORD
sleep $DELAY_SEC
hamachi -c $CONFIG_FOLDER go-online $NETWORK
exit 0
;;
config)
echo "Configuring Hamachi for the first time - network must already exist"
tuncfg >null
hamachi-init -c $CONFIG_FOLDER -f
hamachi -c $CONFIG_FOLDER stop >null
hamachi -c $CONFIG_FOLDER start
hamachi -c $CONFIG_FOLDER login
hamachi -c $CONFIG_FOLDER set-nick $NICKNAME
#hamachi -c /hamachi create $NETWORK
hamachi -c $CONFIG_FOLDER join $NETWORK $PASSWORD
hamachi -c $CONFIG_FOLDER go-online $NETWORK
exit 0
;;
list)
echo "Hamachi list"
tuncfg >null
hamachi -c /hamachi
exit 0
;;
*)
echo "Usage: /etc/init.d/hamachi {start|stop|restart|config|list}"
exit 1
;;
esac

exit 0

Last edited by smt52; 06-26-2008 at 12:30 PM. Reason: updated script
 
Old 06-26-2008, 12:42 PM   #2
smt52
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Hamachi is not running?

Quote:
It says "hamachi doesn't seem to be running", though, it seems, that it is running.
the script uses a custom config file with the "-c <filename>" option, so use:

hamachi -c /hamachi list

or:

./hamachi-daemon list
 
  


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
How do I make a simple script and make it run on bootup?? coolblue Programming 5 12-18-2006 09:55 PM
make script run on startup pytheas22 Fedora 1 11-08-2006 10:35 PM
Make a script run at reboot Braynid Linux - Newbie 10 06-26-2006 10:10 AM
Can't make a script run hanasi Linux - Newbie 14 08-27-2005 03:14 PM
How do I make a script run at boot? ToothlessRebel Linux - Newbie 9 04-27-2005 01:46 AM

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

All times are GMT -5. The time now is 08:23 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