{"id":1856,"date":"2016-06-29T22:47:08","date_gmt":"2016-06-30T06:47:08","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1856"},"modified":"2016-06-29T22:47:08","modified_gmt":"2016-06-30T06:47:08","slug":"neorouter-and-syncthing","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2016\/06\/29\/neorouter-and-syncthing\/","title":{"rendered":"NeoRouter and Syncthing startup and thaw\/resume from sleep\/hibernation"},"content":{"rendered":"<p>NeoRouter and Syncthing at boot time<\/p>\n<p>Create start scripts in \/etc\/init.d\/<\/p>\n<p>Direct \/etc\/PM\/sleep.d\/ scripts to the \/etc\/init.d\/ scripts<\/p>\n<p>Syncthing script, NeoRouter script, followed by sleep.d scripts<\/p>\n<p>Create files in the folders indicated. For the init.d files make them executable<\/p>\n<p>================================================<\/p>\n<p><em><strong>In the <\/strong><\/em><code>init.d\/syncthing<\/code><em><strong> script below replace <\/strong><\/em><code>&lt;an_admin_username&gt;<\/code><em><strong> 27 lines down with your username.<\/strong><\/em><\/p>\n<p>Also checkout the line preceeding that for the path to the syncthing daemon (default \/usr\/bin\/syncthing).<\/p>\n<p>=====<code> \/etc\/init.d\/syncthing <\/code>=====================<\/p>\n<p style=\"padding-left: 30px;\"><code>#! \/bin\/sh<br \/>\n### BEGIN INIT INFO<br \/>\n# Provides:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 syncthing<br \/>\n# Required-Start:\u00a0\u00a0\u00a0 $remote_fs $syslog<br \/>\n# Required-Stop:\u00a0\u00a0\u00a0\u00a0 $remote_fs $syslog<br \/>\n# Default-Start:\u00a0\u00a0\u00a0\u00a0 2 3 4 5<br \/>\n# Default-Stop:\u00a0\u00a0\u00a0\u00a0\u00a0 0 1 6<br \/>\n# Short-Description: Controls Syncthing execution<br \/>\n# Description:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Used for starting the decentralized syncthing platform<br \/>\n### END INIT INFO<\/code><\/p>\n<p style=\"padding-left: 30px;\"># Author: john statler<br \/>\n#<br \/>\n# Please remove the &#8220;Author&#8221; lines above and replace them<br \/>\n# with your own name if you copy and modify this script.<\/p>\n<p style=\"padding-left: 30px;\"># Do NOT &#8220;set -e&#8221;<\/p>\n<p style=\"padding-left: 30px;\"># PATH should only include \/usr\/* if it runs after the mountnfs.sh script<br \/>\nPATH=\/sbin:\/usr\/sbin:\/bin:\/usr\/bin<br \/>\nDESC=&#8221;Syncthing decentralized file sync platform&#8221;<br \/>\nNAME=syncthing<br \/>\nDAEMON=\/usr\/bin\/$NAME<br \/>\nDAEMON_ARGS=&#8221;&#8221;<br \/>\nPIDFILE=\/var\/run\/$NAME.pid<br \/>\nSCRIPTNAME=\/etc\/init.d\/$NAME<br \/>\nUSER=&lt;an_admin_username&gt;<\/p>\n<p style=\"padding-left: 30px;\"># Exit if the package is not installed<br \/>\n[ -x &#8220;$DAEMON&#8221; ] || exit 0<\/p>\n<p style=\"padding-left: 30px;\"># Read configuration variable file if it is present<br \/>\n[ -r \/etc\/default\/$NAME ] &amp;&amp; . \/etc\/default\/$NAME<\/p>\n<p style=\"padding-left: 30px;\"># Load the VERBOSE setting and other rcS variables<br \/>\n. \/lib\/init\/vars.sh<\/p>\n<p style=\"padding-left: 30px;\"># Define LSB log_* functions.<br \/>\n# Depend on lsb-base (&gt;= 3.2-14) to ensure that this file is present<br \/>\n# and status_of_proc is working.<br \/>\n. \/lib\/lsb\/init-functions<\/p>\n<p style=\"padding-left: 30px;\">#<br \/>\n# Function that starts the daemon\/service<br \/>\n#<br \/>\ndo_start()<br \/>\n{<br \/>\n# Return<br \/>\n#\u00a0\u00a0 0 if daemon has been started<br \/>\n#\u00a0\u00a0 1 if daemon was already running<br \/>\n#\u00a0\u00a0 2 if daemon could not be started<br \/>\nstart-stop-daemon &#8211;start &#8211;quiet &#8211;pidfile $PIDFILE &#8211;exec $DAEMON &#8211;chuid $USER &#8211;background &#8211;test &gt; \/dev\/null \\<br \/>\n|| return 1<br \/>\nstart-stop-daemon &#8211;start &#8211;quiet &#8211;pidfile $PIDFILE &#8211;exec $DAEMON &#8211;chuid $USER &#8211;background &#8212; \\<br \/>\n$DAEMON_ARGS \\<br \/>\n|| return 2<br \/>\n}<\/p>\n<p style=\"padding-left: 30px;\">#<br \/>\n# Function that stops the daemon\/service<br \/>\n#<br \/>\ndo_stop()<br \/>\n{<br \/>\n# Return<br \/>\n#\u00a0\u00a0 0 if daemon has been stopped<br \/>\n#\u00a0\u00a0 1 if daemon was already stopped<br \/>\n#\u00a0\u00a0 2 if daemon could not be stopped<br \/>\n#\u00a0\u00a0 other if a failure occurred<br \/>\nstart-stop-daemon &#8211;stop &#8211;quiet &#8211;retry=TERM\/30\/KILL\/5 &#8211;pidfile $PIDFILE &#8211;chuid $USER &#8211;name $NAME<br \/>\nRETVAL=&#8221;$?&#8221;<br \/>\n[ &#8220;$RETVAL&#8221; = 2 ] &amp;&amp; return 2<br \/>\n# Wait for children to finish too if this is a daemon that forks<br \/>\n# and if the daemon is only ever run from this initscript.<br \/>\n# If the above conditions are not satisfied then add some other code<br \/>\n# that waits for the process to drop all resources that could be<br \/>\n# needed by services started subsequently.\u00a0 A last resort is to<br \/>\n# sleep for some time.<br \/>\nstart-stop-daemon &#8211;stop &#8211;quiet &#8211;oknodo &#8211;retry=0\/30\/KILL\/5 &#8211;chuid $USER &#8211;exec $DAEMON<br \/>\n[ &#8220;$?&#8221; = 2 ] &amp;&amp; return 2<br \/>\n# Many daemons don&#8217;t delete their pidfiles when they exit.<br \/>\nrm -f $PIDFILE<br \/>\nreturn &#8220;$RETVAL&#8221;<br \/>\n}<\/p>\n<p style=\"padding-left: 30px;\">#<br \/>\n# Function that sends a SIGHUP to the daemon\/service<br \/>\n#<br \/>\ndo_reload() {<br \/>\n#<br \/>\n# If the daemon can reload its configuration without<br \/>\n# restarting (for example, when it is sent a SIGHUP),<br \/>\n# then implement that here.<br \/>\n#<br \/>\nstart-stop-daemon &#8211;stop &#8211;signal 1 &#8211;quiet &#8211;pidfile $PIDFILE &#8211;chuid $USER &#8211;name $NAME<br \/>\nreturn 0<br \/>\n}<\/p>\n<p style=\"padding-left: 30px;\">case &#8220;$1&#8221; in<br \/>\nstart)<br \/>\n[ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_daemon_msg &#8220;Starting $DESC&#8221; &#8220;$NAME&#8221;<br \/>\ndo_start<br \/>\ncase &#8220;$?&#8221; in<br \/>\n0|1) [ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_end_msg 0 ;;<br \/>\n2) [ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_end_msg 1 ;;<br \/>\nesac<br \/>\n;;<br \/>\nstop)<br \/>\n[ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_daemon_msg &#8220;Stopping $DESC&#8221; &#8220;$NAME&#8221;<br \/>\ndo_stop<br \/>\ncase &#8220;$?&#8221; in<br \/>\n0|1) [ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_end_msg 0 ;;<br \/>\n2) [ &#8220;$VERBOSE&#8221; != no ] &amp;&amp; log_end_msg 1 ;;<br \/>\nesac<br \/>\n;;<br \/>\nstatus)<br \/>\nstatus_of_proc &#8220;$DAEMON&#8221; &#8220;$NAME&#8221; &amp;&amp; exit 0 || exit $?<br \/>\n;;<br \/>\n#reload|force-reload)<br \/>\n#<br \/>\n# If do_reload() is not implemented then leave this commented out<br \/>\n# and leave &#8216;force-reload&#8217; as an alias for &#8216;restart&#8217;.<br \/>\n#<br \/>\n#log_daemon_msg &#8220;Reloading $DESC&#8221; &#8220;$NAME&#8221;<br \/>\n#do_reload<br \/>\n#log_end_msg $?<br \/>\n#;;<br \/>\nrestart|force-reload)<br \/>\n#<br \/>\n# If the &#8220;reload&#8221; option is implemented then remove the<br \/>\n# &#8216;force-reload&#8217; alias<br \/>\n#<br \/>\nlog_daemon_msg &#8220;Restarting $DESC&#8221; &#8220;$NAME&#8221;<br \/>\ndo_stop<br \/>\ncase &#8220;$?&#8221; in<br \/>\n0|1)<br \/>\ndo_start<br \/>\ncase &#8220;$?&#8221; in<br \/>\n0) log_end_msg 0 ;;<br \/>\n1) log_end_msg 1 ;; # Old process is still running<br \/>\n*) log_end_msg 1 ;; # Failed to start<br \/>\nesac<br \/>\n;;<br \/>\n*)<br \/>\n# Failed to stop<br \/>\nlog_end_msg 1<br \/>\n;;<br \/>\nesac<br \/>\n;;<br \/>\n*)<br \/>\n#echo &#8220;Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}&#8221; &gt;&amp;2<br \/>\necho &#8220;Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}&#8221; &gt;&amp;2<br \/>\nexit 3<br \/>\n;;<br \/>\nesac<\/p>\n<p style=\"padding-left: 30px;\">:<\/p>\n<p>===== <code>end syncthing <\/code>===========<\/p>\n<p>===== <code>\/etc\/init.d\/nrservice<\/code> ======<\/p>\n<p style=\"padding-left: 30px;\"><code>#!\/bin\/bash<br \/>\n### BEGIN INIT INFO<br \/>\n# Provides:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 nrservice<br \/>\n# Required-Start:\u00a0\u00a0\u00a0 $all<br \/>\n# Should-Start:<br \/>\n# Required-Stop:<br \/>\n# Should-Stop:<br \/>\n# Default-Start:\u00a0\u00a0\u00a0\u00a0 2 3 4 5<br \/>\n# Default-Stop:\u00a0\u00a0\u00a0\u00a0\u00a0 0 1 6<br \/>\n# Short-Description: Start and Stop NeoRouter client service<br \/>\n# Description:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 NeoRouter client service connects this computer into NeoRouter virtual network<br \/>\n#\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 contact support@neorouter.com<br \/>\n### END INIT INFO<\/code><\/p>\n<p style=\"padding-left: 30px;\">set -e<\/p>\n<p style=\"padding-left: 30px;\">NAME=nrservice<br \/>\nDAEMON=\/usr\/bin\/$NAME<\/p>\n<p style=\"padding-left: 30px;\">test -x $DAEMON || exit 0<br \/>\n. \/lib\/lsb\/init-functions<\/p>\n<p style=\"padding-left: 30px;\">case &#8220;$1&#8221; in<br \/>\nstart)<br \/>\nlog_begin_msg &#8220;Starting NeoRouter client service: $NAME&#8221;<br \/>\nstart-stop-daemon &#8211;start &#8211;background -m &#8211;pidfile \/var\/run\/nrservice.pid &#8211;exec $DAEMON &gt;\/dev\/null &amp;&amp; log_end_msg 0 || log_end_msg 1<br \/>\n;;<br \/>\nstop)<br \/>\nlog_begin_msg &#8220;Stopping NeoRouter client service: $NAME&#8221;<br \/>\nstart-stop-daemon &#8211;stop &#8211;pidfile \/var\/run\/nrservice.pid &#8211;oknodo &#8211;exec $DAEMON &amp;&amp; log_end_msg 0 || log_end_msg 1<br \/>\nrm -f \/var\/run\/nrservice.pid<br \/>\n;;<br \/>\nrestart)<br \/>\n$0 stop<br \/>\n$0 start<br \/>\n;;<br \/>\n*)<br \/>\nlog_success_msg &#8220;Usage: \/etc\/init.d\/$0 {start|stop|restart}&#8221;<br \/>\nexit 1<br \/>\n;;<br \/>\nesac<\/p>\n<p style=\"padding-left: 30px;\">exit 0<\/p>\n<p>====== <code>end nrserver.sh<\/code> =======<\/p>\n<p>===== <code>\/etc\/pm\/00_syncthing_onresume.sh<\/code> ========those are zeros ==<\/p>\n<p style=\"padding-left: 30px;\"><code>#! \/bin\/bash<\/code><\/p>\n<p style=\"padding-left: 30px;\">case &#8220;$1&#8221; in<br \/>\nthaw)<br \/>\nsu &#8211; tech -c &#8220;\/etc\/init.d\/syncthing restart&#8221;<br \/>\n;;<br \/>\nresume)<br \/>\nsu &#8211; tech -c &#8220;\/etc\/init.d\/syncthing restart&#8221;<br \/>\n;;<\/p>\n<p style=\"padding-left: 30px;\">esac<\/p>\n<p>====== <code>end 00_syncthing_onresume.sh<\/code> =====<\/p>\n<p>===== <code>\/etc\/pm\/00_neorouter_onresume.sh<\/code> ===<\/p>\n<p style=\"padding-left: 30px;\">#! \/bin\/bash<\/p>\n<p style=\"padding-left: 30px;\">case &#8220;$1&#8221; in<br \/>\nthaw)<br \/>\nsu &#8211; tech -c &#8220;\/etc\/init.d\/nrservice.sh restart&#8221;<br \/>\n;;<br \/>\nresume)<br \/>\nsu &#8211; tech -c &#8220;\/etc\/init.d\/nrservice.sh restart&#8221;<br \/>\n;;<\/p>\n<p style=\"padding-left: 30px;\">esac<\/p>\n<p>====== <code>end 00_neorouter_onresume.sh<\/code> =======<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NeoRouter and Syncthing at boot time Create start scripts in \/etc\/init.d\/ Direct \/etc\/PM\/sleep.d\/ scripts to the \/etc\/init.d\/ scripts Syncthing script, NeoRouter script, followed by sleep.d scripts Create files in the folders indicated. For the init.d files make them executable ================================================ In the init.d\/syncthing script below replace &lt;an_admin_username&gt; 27 lines down with your username. Also checkout [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1856","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1856\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}