element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Pas Home / Auto start OpenHAB
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: verrverr
  • Date Created: 20 Aug 2014 1:06 AM Date Created
  • Views 415 views
  • Likes 1 like
  • Comments 4 comments
  • forget_me_not
  • pas_home
Related
Recommended

Pas Home / Auto start OpenHAB

verrverr
verrverr
20 Aug 2014

Pas Home - Index

 

Hi, this is my lite script to start OpenHAB daemon at startup

 

Very usefull command during dev

sudo /etc/init.d/openhab.sh start

sudo /etc/init.d/openhab.sh stop

sudo /etc/init.d/openhab.sh restart

 

 

How to

 

#Transfert the openhab.sh script into /opt/openhab/openhab.sh or directly in /etc/init.d/openhab.sh

sudo cp /opt/openhab/openhab.sh /etc/init.d

 

# Make sure the script is executable (chmod again).

sudo chmod 777 /etc/init.d/openhab.sh

 

#At this point you should be able to start/stop/restart using the command

#   sudo /etc/init.d/openhab.sh start

#check its status with the status argument

#   /etc/init.d/openhab.sh status

#and stop it with

#   sudo /etc/init.d/openhab.sh stop

#and restart it with

#   sudo /etc/init.d/openhab.sh restart

 

# To make the Raspberry Pi use your init script at the right time, one more step is required: running the command

sudo update-rc.d openhab.sh defaults

#sudo update-rc.d -f openhab.sh remove

 

# This command adds in symbolic links to the /etc/rc.x directories so that the init script is run at the default times. you can see these links if you do

# ls -l /etc/rc?.d/*openhab.sh

 

openhab.sh script

#!/bin/sh
### BEGIN INIT INFO
# Provides:          openhab
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenHAB Daemon
# Description: Build your smart home in no time!
### END INIT INFO


ROOT_DIR=/opt/openhab


# set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/
eclipsehome="$ROOT_DIR/server";


# set ports for HTTP(S) server
HTTP_PORT=8080
HTTPS_PORT=8443


# get path to equinox jar inside $eclipsehome folder
cp=$(find $eclipsehome -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);




# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
#USER=root
DAEMON_USER=root
DAEMON_NAME=openhab


DAEMON=/usr/bin/java
DAEMON_ARGS="-Djna.boot.library.path=/usr/lib/jni -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0 -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$HTTP_PORT -Djetty.port.ssl=$HTTPS_PORT -Djetty.home=. -Dlogback.configurationFile=configurations/logback.xml -Dfelix.fileinstall.dir=addons -Djava.library.path=lib -Djava.security.auth.login.config=./etc/login.conf -Dorg.quartz.properties=./etc/quartz.properties -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Dfelix.fileinstall.active.level=4 -Djava.awt.headless=true -jar $cp $* -console "
PIDFILE=/var/run/$DAEMON_NAME.pid


. /lib/lsb/init-functions

do_start() {      
  log_daemon_msg "Starting system $DAEMON_NAME daemon"
  start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --chdir $ROOT_DIR --exec $DAEMON -- $DAEMON_ARGS
  log_end_msg $?
}
do_stop() {
  log_daemon_msg "Stopping system $DAEMON_NAME daemon"
  start-stop-daemon --stop --pidfile $PIDFILE --retry 10
  log_end_msg $?
}

case "$1" in

    start|stop)
        do_${1}
        ;;

    restart|reload|force-reload)
        do_stop
        do_start
        ;;

    status)
        status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
        ;;
    *)
        echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
        exit 1
        ;;

esac
exit 0

Attachments:
openhab.zip
  • Sign in to reply
  • verrverr
    verrverr over 7 years ago in reply to Former Member

    Do you run this command? sudo chmod 777 /etc/init.d/openhab.sh

    this command set the permission to file to be executable.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 7 years ago

    I somehow didn't had permission and had to enter root level with <<sudo su>> after that it copied the file fine...

    But the last point doesn't work becaue it prompts:

     

    root@raspberrypi:/home/pi# update-rc.d openhab.sh defaults

    update-rc.d: using dependency based boot sequencing

    insserv: script openhab.sh is not an executable regular file, skipped!

     

    what can i do about that?

    best regards, novski

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 8 years ago

    Very useful indeed!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ravi_butani
    ravi_butani over 8 years ago

    Thanks @Pascal_martin this really helps me... I need to reboot every time my pi for restart openhab...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube