Start Hamachi as a System Service

***Update*** – Just made a new blog post about the current situation with Hamachi’s Linux Support. I highly suggest reading this here instead of messing with LogMeIn’s disregard for Linux support.

Now that we’ve been able to get Hamachi installed.  We are ready to create a startup script to allow it to start automatically when the computer boots.  You may have noticed that during the installation process we ran the ‘hamachi‘ command with ‘-c /etc/hamachi’ .  This was simply to force Hamachi to place the configuration files into a directory of our choice.  Otherwise it would have placed them in a hidden directory in the home directory of the user who installed and configured Hamachi.

  1. To begin we must create an new file
  2. $ sudo touch /etc/init.d/hamachi
  3. Open the newly created file.
  4. $ sudo nano /etc/init.d/hamachi
  5. Insert the following script into the ‘hamachi’ file via copy and paste.
  6. #!/bin/sh
     
    hamachi_start() {
     echo "Starting hamachi..."
     /sbin/tuncfg
     /usr/bin/hamachi -c /etc/hamachi start
     /bin/chmod 760 /var/run/tuncfg.sock
     /bin/chgrp hamachi /var/run/tuncfg.sock
    }
     
    hamachi_stop() {
     echo "Stopping hamachi..."
     killall tuncfg
     /usr/bin/hamachi -c /etc/hamachi stop
    }
     
    hamachi_restart() {
     hamachi_stop
     sleep 1
     hamachi_start
    }
     
    case "$1" in
    'start')
     hamachi_start
     ;;
    'stop')
     hamachi_stop
     ;;
    'restart')
     hamachi_restart
     ;;
    *)
     hamachi_start
    esac
  7. Save and exit nano (Ctrl-O to save, Ctrl-X to exit). Now set the ‘hamachi’ file as executable.
  8. $ sudo chmod +x /etc/init.d/hamachi
  9. Add the ‘hamachi’ script to the defaults startup process
  10. $ sudo update-rc.d hamachi defaults

    Expected output

    update-rc.d: warning: /etc/init.d/hamachi missing LSB information
    update-rc.d: see
     Adding system startup for /etc/init.d/hamachi ...
       /etc/rc0.d/K20hamachi -> ../init.d/hamachi
       /etc/rc1.d/K20hamachi -> ../init.d/hamachi
       /etc/rc6.d/K20hamachi -> ../init.d/hamachi
       /etc/rc2.d/S20hamachi -> ../init.d/hamachi
       /etc/rc3.d/S20hamachi -> ../init.d/hamachi
       /etc/rc4.d/S20hamachi -> ../init.d/hamachi
       /etc/rc5.d/S20hamachi -> ../init.d/hamachi

That should complete the process.  Now when you reboot your computer it will now start Hamachi automatically as the root user.  Remember that if you do wish to manually run any of the Hamachi commands, you must run them with the ‘-c /etc/hamachi’ prefix.  Otherwise it will not be looking in the right place for the configuration data.  Below is good example and a bad example.

  • Good…
  • $ sudo hamachi -c /etc/hamachi start
  • Bad…
  • $ sudo hamachi start

Pages: 1 2 3 4

Tags: