Koozali.org: home of the SME Server

Contribs.org Forums => Development => Topic started by: MScapin on May 19, 2015, 11:35:01 AM

Title: Create a RPM
Post by: MScapin on May 19, 2015, 11:35:01 AM
Hey !

I'd like to know if someone could help me creating a RPM to put Syncthing install in ! :)
Thanks alot !
Title: Re: Create a RPM
Post by: TerryF on May 19, 2015, 11:49:10 AM
Start here: http://wiki.contribs.org/Web_Application_RPM
Title: Re: Create a RPM
Post by: MScapin on May 19, 2015, 02:01:08 PM
Nice, thanks !
Could you tell me where is the specs directory ? thanks !
Title: Re: Create a RPM
Post by: Daniel B. on May 19, 2015, 02:28:50 PM
You can have a look at this page: http://wiki.contribs.org/SME_Server:Documentation:Developers_Manual#III._How_to_create_an_SME_Server_package_-_step_by_step
It's a complete guide to start writting addons for SME Server
Title: Re: Create a RPM
Post by: CharlieBrady on June 08, 2015, 07:57:42 PM
I'd like to know if someone could help me creating a RPM to put Syncthing install in ! :)

You should start by using the rpm which already exists for syncthing for CentOS6. I provided a pointer to that in another thread. Then you can build a separate smeserver-syncthing rpm which just contains the simple 'glue' for running syncthing in SME server.
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 08:37:02 AM
Hey !
so I created 2 spec files to build my rpm, one with syncthing's files and one with syncthing configuration :

Syncthing's files :

Code: [Select]
Name: syncthing
Version: 0.11.8
Release:%{?dist}
Summary: Syncthing
License: GPL
URL: http://syncthing.net/
Source0: /root/rpmbuild/SOURCES/syncthing-linux-386-v0.11.8.tar.gz
BuildRoot: %{_tmppath}/%{name}-test
BuildRequires: golang

%description
Syncthing replaces Dropbox and BitTorrent Sync with something open, trustworthy and decentralized. Your data is your data alone and you deserve to choose where it is stored, if it is shared with some third party and how it's transmitted over the Internet.

%prep

%setup -c -n syncthing-%{version}

%build
rm -rf /home/syncthing
userdel syncthing
useradd syncthing
mkdir /home/syncthing/log
mkdir /home/syncthing/bin


%install
rm -rf %{buildroot}

mkdir -p %{buildroot}%{_bindir}
install -p -m 0755 %{name}-linux-386-v%{version}/syncthing %{buildroot}%{_bindir}

mkdir -p %{buildroot}%{_unitdir}
install -p -m 0644 %{S:0} %{buildroot}%{_unitdir}


%clean


%files
/usr/bin/syncthing



%defattr(-,root,root)
%doc


%changelog

Syncthing's configuration :

Code: [Select]
Name: syncthing_server
Version: 0.11.8
Release:%{?dist}
Summary: Syncthing
License: GPL
URL: http://syncthing.net/
Source0: /root/rpmbuild/SOURCES/syncthing_server.tar.gz    #Contains config.xml + syncthing's script
BuildRoot: %{_tmppath}/%{name}-test
BuildRequires: syncthing

%description
Syncthing replaces Dropbox and BitTorrent Sync with something open, trustworthy and decentralized. Your data is your data alone and you deserve to choose where it is stored, if it is shared with some third party and how it's transmitted over the Internet.

%prep

%setup -c -n %{name}

%build

%install
cd /root/rpmbuild/BUILD/syncthing_server/syncthing_server
cp syncthing /etc/rc.d/init.d/
cp config.xml /home/syncthing/.config/syncthing/
%post
chown syncthing:syncthing -Rf /home/syncthing
chmod u+x /etc/rc.d/init.d/syncthing
chkconfig syncthing --override
ln -f -s /etc/rc.d/init.d/e-smith-service /etc/rc7.d/S99syncthing
config set syncthing service status enabled
config setprop syncthing access public
config setprop syncthing TCPPort 8080
config setprop syncthing TCPPorts 8080,22000
config setprop syncthing UDPPort 21025
signal-event remoteaccess-update



%files




So, are there some mistakes or some things missing in theses files ?

And is there something missing to create my rpm ?

Thanks !
Title: Re: Create a RPM
Post by: Daniel B. on June 16, 2015, 09:03:02 AM
Yes, there're still some issues, first for the syncthing RPM itself


Now, for your second RPM


Also, you should add some carriage return in the %description, which is for now a very long line.

Cheers,
Daniel
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 09:22:46 AM
Ok, thanks a lot for the fast answer ! I'll try and let you know !
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 02:08:04 PM
So we modified the spec file and now it goes well. rpm -ivh works , files are where they have to be.

Here's the spec file we used

Code: [Select]
Summary: Syncthing.
Name: syncthing
Version: 0.11.8
Release: 1%{?dist}
License: GPL
Group: Applications/Internet

#create source, go to SOURCES dir
#git clone https://github.com/syncthing/syncthing
#mv syncthing-linux-386-v0.11.8.tar.gz
#tar czvf syncthing-linux-386-v0.11.8.tar.gz syncthing-0.11.8

Source0: %{_sourcedir}/syncthing-linux-386-v0.11.8.tar.gz
Source1: %{_sourcedir}/syncthing-init

BuildRoot: /var/tmp/%{name}-buildroot

%description
Syncthing replaces proprietary sync and cloud services with something open, trustworthy
and decentralized. Your data is your data alone and you deserve to choose where it is
stored, if it is shared with some third party and how it's transmitted over the Internet.

%prep

%setup -c -n syncthing



%build
export GOPATH=/tmp/go
git clone https://github.com/syncthing/syncthing
cd ~/rpmbuild/BUILD/syncthing/syncthing
go run build.go

%install

rm -rf $RPM_BUILD_ROOT

install --directory $RPM_BUILD_ROOT/usr/sbin/
install -m 755 %{_sourcedir}/syncthing $RPM_BUILD_ROOT/usr/sbin/syncthing
install --directory $RPM_BUILD_ROOT/etc/init.d/
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT/etc/init.d/syncthing
install --directory $RPM_BUILD_ROOT/etc/linux-runit/
install -m 755 %{_sourcedir}/syncthing-linux-386-v0.11.8/syncthing $RPM_BUILD_ROOT/etc
install -m 755 %{_sourcedir}/syncthing-linux-386-v0.11.8/syncthing.md5 $RPM_BUILD_ROOT/etc
install -m 755 %{_sourcedir}/syncthing-linux-386-v0.11.8/etc/linux-runit/run $RPM_BUILD_ROOT/etc/linux-runit

#%clean
#rm -rf $RPM_BUILD_ROOT

%files
/usr/sbin/syncthing
/etc/init.d/syncthing
/etc/linux-runit/run
/etc/syncthing
/etc/syncthing.md5


%defattr(-,root,root)
%doc


%changelog

Is it ok for you guys ?



Title: Re: Create a RPM
Post by: Daniel B. on June 16, 2015, 02:17:27 PM
Better, but not yet ready, a few more issues:


++
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 03:29:04 PM
Ok, i'll make this.

So we installed the rpm , everything went well, but the service doesn't start :

Code: [Select]
[root@stageafpa init.d]# service syncthing restart
/etc/rc.d/init.d/syncthing: line 30: kill: (2459) - Aucun processus de ce type
Service not running
/etc/rc.d/init.d/syncthing: line 19: kill: (2459) - Aucun processus de ce type
Starting service▒
Service started


It says that the service is started, but it is not...
Do you know why ?
Title: Re: Create a RPM
Post by: Daniel B. on June 16, 2015, 03:31:02 PM
Do you know why ?

Not without seeing the init script, but I guess the service is being stopped while it's not running. As for why itg's not running, I have no idea, you should check syncthing logs and /or /var/log/messages
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 03:41:51 PM
The one in etc/rc.d/init.d ?

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
Title: Re: Create a RPM
Post by: MScapin on June 16, 2015, 03:45:17 PM
Ok, my bad, just watch the log file :

Code: [Select]
15:42:55 FATAL: mkdir /home/syncthing/.config: permission denied

but I don't even know how to have this .config folder , which should contains config.xml...
Title: Re: Create a RPM
Post by: Stefano on June 16, 2015, 04:25:53 PM
you must adapt paths to SME's standards

please read carefully the developers' manual (link above)
Title: Re: Create a RPM
Post by: CharlieBrady on June 16, 2015, 04:35:18 PM
The one in etc/rc.d/init.d ?

In a kill command, you are using the letter 0, when you should use the number zero.

Why aren't you using the already existing syncthing rpm?
Title: Re: Create a RPM
Post by: MScapin on June 17, 2015, 08:50:25 AM
Because we have to do it by ourselves :D (internship)
Our syncthing.spec works fine, we now have to make the config.xml install in /etc/syncthing and tell the script to search it here, I'll keep you informed !
Title: Re: Create a RPM
Post by: MScapin on June 18, 2015, 01:34:59 PM
As the RPM is created, I made a new post to speak about the templates.

Link :
http://forums.contribs.org/index.php?topic=51760.new#new

Thanks for the help here !

Best regards,

MScapin.