Koozali.org: home of the SME Server

Syncthing on SME9 and others... and maybe a new contrib?

Offline gdbs

  • *
  • 96
  • +0/-0
Syncthing on SME9 and others... and maybe a new contrib?
« on: September 01, 2014, 11:25:23 AM »
Hi, i've install Syncthing on my SME. It works great :)
This is what i've done if it helps someone... I don't know how to build a RPM from this but maybe someone else if it's woth it?

Install
Add user specific for  Syncthing
Code: [Select]
[root@server ~]#useradd syncthing
Add log folder
Code: [Select]
[root@server ~]#mkdir /home/syncthing/log
Add bin folder for syncthing
Code: [Select]
[root@server ~]#mkdir /home/syncthing/bin
To download Syncthing, go to the website https://github.com/syncthing/syncthing/releases/latest
then copy/past the right link for your server arch (here, linux 64 bits)

Then, download from server:

Code: [Select]
[root@server ~]# wget https://github.com/syncthing/syncthing/releases/download/v0.9.10/syncthing-linux-amd64-v0.9.10.tar.gz
Extrat it:
Code: [Select]
[root@server ~]# tar -zxvf syncthing-linux-amd64-v0.9.10.tar.gz
Copy syncthing to the bin folder
Code: [Select]
[root@server ~]# cp syncthing-linux-amd64-v0.9.10/syncthing /home/syncthing/bin/
Change right to able syncthing user to launch it (and, later, upgrade it directly from web interface)
Code: [Select]
[root@server ~]#chown syncthing:syncthing -Rf /home/syncthing/*
Set Syncthing as a service

SME Script
Code: [Select]
[root@server ~]#nano /etc/rc.d/init.d/syncthingCopy/past this lines.
Note:
  • bin folder: SCRIPT=/home/syncthing/bin/syncthing
  • syncthing user: RUNAS=syncthing
  • service name: NAME=syncthing
  • log files folder: LOGFILE=/home/syncthing/log/$NAME.log

Code: [Select]
#!/bin/sh
### BEGIN INIT INFO
# Provides: Syncthing
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Syncthing to sync folders
### END INIT INFO

SCRIPT=/home/syncthing/bin/syncthing
RUNAS=syncthing
NAME=syncthing

PIDFILE=/var/run/$NAME.pid
LOGFILE=/home/syncthing/log/$NAME.log

start() {
 if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
echo 'Service already running' >&2
   return 1
fi
echo 'Starting serviceā€¦' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}

stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
  return 1
fi
echo 'Stopping serviceā€¦' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}

uninstall() {
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
  rm -f "$PIDFILE"
  echo "Notice: log file is not be removed: '$LOGFILE'" >&2
  update-rc.d -f <NAME> remove
  rm -fv "$0"
fi
}

status() {
      printf "%-50s" "Checking $NAME..."
  if [ -f $PIDFILE ]; then
      PID=$(cat $PIDFILE)
          if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
              printf "%s\n" "The process appears to be dead but pidfile still exists"
          else
              echo "Running, the PID is $PID"
          fi
  else
      printf "%s\n" "Service not running"
  fi
}


case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
status)
  status
  ;;
uninstall)
  uninstall
  ;;
restart)
  stop
  start
  ;;
*)
  echo "Usage: $0 {start|stop|status|restart|uninstall}"
esac

Script launchable
Code: [Select]
[root@server ~]#chmod u+x /etc/rc.d/init.d/syncthing
Add service
Code: [Select]
[root@server ~]#chkconfig syncthing --add
link for init 7 of SME
Code: [Select]
[root@server ~]#ln -f -s /etc/rc.d/init.d/e-smith-service /etc/rc7.d/S99syncthing
service Syncthing active in SME configuration
Code: [Select]
[root@server ~]#db configuration set syncthing service status enabled
Syncthing service configuration
To allow local network to access syncthing server:
Code: [Select]
[root@server ~]#db configuration setprop syncthing access privateOr for private+public acces:
Code: [Select]
[root@server ~]#db configuration setprop syncthing access public
Syncthing needs to open these ports:
Code: [Select]
[root@server ~]#db configuration setprop syncthing TCPPort 8080
[root@server ~]#db configuration setprop syncthing TCPPorts 8080,22000
[root@server ~]#db configuration setprop syncthing UDPPort 21025

Apply changes
Code: [Select]
[root@server ~]#signal-event remoteaccess-update
Then launch the service
Code: [Select]
[root@server ~]#service syncthing start
Syncthing configuration
Config files are in the folder /home/syncthing/.config/syncthing/

we gonna change config.xml

Code: [Select]
[root@server ~]#nano /home/syncthing/.config/syncthing/config.xml
Check these lignes:
Code: [Select]
<gui enabled="true" tls="false">
       <address>127.0.0.1:8080</address>

Here, we can only web interface from host server and unsecured.
Change these lignes like this to allow access from computer part of the network allowed above in service configuration, and force encrypted connexions
Code: [Select]
<gui enabled="true" tls="true">
       <address>0.0.0.0:8080</address>

Save and restart service
Code: [Select]
[root@server ~]#service syncthing restart
Syncthing configuration from the web interface
With your browser, https://ip_server:8080

Edit > Configuration, define a user with password allowed to access web interface for more secure.

You can know add folder and nodes. Folders will be added in /home/syncthing

Offline stephdl

  • *
  • 1,519
  • +0/-0
    • Linux et Geekeries
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #1 on: September 01, 2014, 12:00:40 PM »
I'm glad that you use the howto i made on how add custom service (some of informations came from stefano) :). Please record your knowledge in the wiki, others could do better with all informations.

Maybe you could do a relevant wiki page , like this other people could add more informations, but it is a nice shot you have done, TKY !!!!


FYI, it is easier to have someone who follow the software versions (eg like in epel repository) but if you want we can exchange about what is needed to do a rpm...

this is could be a good start : http://atlas.itx.pialasse.com/makecontrib/

RPM is like love, the first package is hard, after it is nice but less funny  :cool:
« Last Edit: September 01, 2014, 12:08:12 PM by stephdl »
See http://wiki.contribs.org/Koozali_Foundation
irc : Freenode #sme_server #sme-fr

!!! Please write your knowledge to the Wiki !!!

Offline gdbs

  • *
  • 96
  • +0/-0
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #2 on: September 01, 2014, 12:38:26 PM »
Thx stephdl for your reply.

I was about to add a contrib for syncthing on the wiki but, as mentioned:
"To be listed on this page, the contrib should comply with these rules:
Be available in the smecontrib repository
Have a wiki page with install and usage instructions, following the template listed on the talk page.
Have a Bugzilla Contribs Component"

ok i may add it on the how to page, but my goal is to talk about it here, and be able to build a smeserver-syncthing.rpm package and so... add it in the contrib page ;)

Before that, i needed to talk about some things in order to check if i'd made the right choices concerning using, for exemple:
  • a specific user for syncthing
  • the use of the default ports (8080 is used for example in dansguardian contribs :/)
  • as we can use the syncthing bin directly provides by syncthing devs, maybe that's better to only make a rpm in order to add syncthing service and configure it
  • do i have to use an other folder than /home
etc etc

but ok i'll add it in the how to for the moment if you think that i should :)
« Last Edit: September 01, 2014, 12:43:49 PM by gdbs »

Offline gdbs

  • *
  • 96
  • +0/-0
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #3 on: September 01, 2014, 12:39:40 PM »
ha! and thx for your "how to", it's help me a LOT to add syncthing service to my server :)

Offline stephdl

  • *
  • 1,519
  • +0/-0
    • Linux et Geekeries
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #4 on: September 01, 2014, 01:46:35 PM »
see below
« Last Edit: September 01, 2014, 01:55:58 PM by stephdl »
See http://wiki.contribs.org/Koozali_Foundation
irc : Freenode #sme_server #sme-fr

!!! Please write your knowledge to the Wiki !!!

Offline stephdl

  • *
  • 1,519
  • +0/-0
    • Linux et Geekeries
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #5 on: September 01, 2014, 01:54:58 PM »
Thx stephdl for your reply.

I was about to add a contrib for syncthing on the wiki but, as mentioned:
"To be listed on this page, the contrib should comply with these rules:
Be available in the smecontrib repository
Have a wiki page with install and usage instructions, following the template listed on the talk page.
Have a Bugzilla Contribs Component"

ok i may add it on the how to page, but my goal is to talk about it here, and be able to build a smeserver-syncthing.rpm package and so... add it in the contrib page ;)
for now sorry, but it should go to the howto page however it is surely the best way to do a rpm since you can talk and argue on the best way to do things.

A huge time consumer of a rpm packager is done by the search on how to do it.

Before that, i needed to talk about some things in order to check if i'd made the right choices concerning using, for exemple:
  • a specific user for syncthing
  • the use of the default ports (8080 is used for example in dansguardian contribs :/)
  • as we can use the syncthing bin directly provides by syncthing devs, maybe that's better to only make a rpm in order to add syncthing service and configure it
  • do i have to use an other folder than /home
etc etc
-a specific user for syncthing :  that can be done in the %pre or %post section of spec file, maybe a better idea can come. here some doc I made on spec file
-the use of the default ports (8080 is used for example in dansguardian contribs : if that port is already used, change it, you can also do a template with db command to change it on demand
-as we can use the syncthing bin directly provides by syncthing devs, maybe that's better to only make a rpm in order to add syncthing service and configure it : the best way is to have two packages, one with binary, and other with sme settings. But like I wrote above, it will be better if you can find a rpm already done by someone. Like this you will have only one rpm to maintain.
-do i have to use an other folder than /home: I would prefer /opt

but ok i'll add it in the how to for the moment if you think that i should :)

yes for now
« Last Edit: September 01, 2014, 02:03:17 PM by stephdl »
See http://wiki.contribs.org/Koozali_Foundation
irc : Freenode #sme_server #sme-fr

!!! Please write your knowledge to the Wiki !!!

guest22

Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #6 on: September 02, 2014, 05:52:41 AM »
some thoughts...

- Don't use a specific user that will show up in ldap address books or other normal user directory service lookups
- Definitely craft templates for config.xml, that will read the relevant db entries, and create config.xml upon expand
- I agree with the /opt suggestion from stephdl

again, just some thoughts.

guest

Offline stephdl

  • *
  • 1,519
  • +0/-0
    • Linux et Geekeries
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #7 on: September 02, 2014, 07:24:58 AM »
It could be better to change the default port mainly if it is well known, moreover you could do an apache  virtual host to redirect to the custom port and thus you could reach by an url like this
http://yourip_orhost.xx/syncthing

here some example

https://github.com/stephdl/smeserver-shellinabox/blob/master/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/61shellinabox-reverse-proxy
https://github.com/stephdl/smeserver-transmission/blob/master/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/61transmission-reverse-proxy

Due to minor change of binary path between sme8 and  and sme9, the files are different, among other for the architecture detection in sme8 (for sme9, a binary like pwauth is in /usr/bin)
« Last Edit: September 02, 2014, 07:33:23 AM by stephdl »
See http://wiki.contribs.org/Koozali_Foundation
irc : Freenode #sme_server #sme-fr

!!! Please write your knowledge to the Wiki !!!

Offline isinok

  • 1
  • +0/-0
Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #8 on: January 22, 2015, 01:42:15 PM »
Hi, following the discussion with GDBS I continued syncthing project on SME.



      I have taken note of your remarks on this topic. Here are the main changes made to Syncthing project:


               - Syncthing in the directory /opt working but the problem is that syncthing create a file config
        (config.xml) in the same place that user therefore it will be hard to create a template for the config.xml
       
               - change port 8080 by 4242 in the config.xml

               - access to panel webadmin from syncthing via this address:
 
                 http://domaine.xx/syncthing/
                 
                 in /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts  create a file "60port-directory"
                      add this code

                      {

                   
                         if ($port ne "443")


                      {


                         $OUT .= <<'HERE';


                         RewriteEngine on


                         RewriteRule ^/syncthing/(.*)$ https://%{HTTP_HOST}:8080/$1 [P,NC]


                         ## End Of Redirect
                         HERE

                      }


                      }



          - added to panel admin syncthing in the server-manager

 what is missing for create a RPM ?

sorry for my bad english :(

guest22

Re: Syncthing on SME9 and others... and maybe a new contrib?
« Reply #9 on: January 22, 2015, 01:52:21 PM »
Hi, following the discussion with GDBS I continued syncthing project on SME.
Hi and welcome!

bugzilla would be a good place to discuss further with devs. So I would suggest you open a new 'contrib' bug, add your code as attachment and start discussing :) 

You can simply open a new 'bug' report, jus like anyone else.

guest