Koozali.org: home of the SME Server

Create a RPM

Offline MScapin

  • *
  • 14
  • +0/-0
Create a RPM
« 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 !

Offline TerryF

  • grumpy old man
  • *
  • 1,821
  • +6/-0
Re: Create a RPM
« Reply #1 on: May 19, 2015, 11:49:10 AM »
--
qui scribit bis legit

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #2 on: May 19, 2015, 02:01:08 PM »
Nice, thanks !
Could you tell me where is the specs directory ? thanks !

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Create a RPM
« Reply #3 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
C'est la fin du monde !!! :lol:

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Create a RPM
« Reply #4 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.

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #5 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 !
« Last Edit: June 16, 2015, 08:42:02 AM by MScapin »

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Create a RPM
« Reply #6 on: June 16, 2015, 09:03:02 AM »
Yes, there're still some issues, first for the syncthing RPM itself

  • Why don't you start with the spec file Charlie has pointed out ?
  • You're using the pre-compiled binaries to "build" the RPM, it should be done from the sources
  • You're running commands in the %build section, like deleting and creating the syncthing user. First, why would you delete it before ? second, this must not be in the %build section, as it'll be executed on the build box, and not on the server which installs the final RPM
  • You're creating /home/syncthing/bin and /home/syncthing/log but those directories are then not included in the final RPM (see the %file section)
  • The commands with %{_unitddir} shouldn't be there. I guess you copied/pasted them from an Fedora/EL67 spec file, and they are related to systemd config, which isn't used on SME
  • The changelog section is empty, there should be at least one entry with "Initial package" or something similar
  • The init script and the default config file which are included in your second RPM should be in the first one, as they are part of syncthing itself and are not SME specific

Now, for your second RPM

  • You used the name syncthing_smeserver, while the convention is to use smeserver-syncthing
  • You used the same version number as syncthing itself. This is fine, but not strictly required. Usually a smeserver-XXXX package doesn't need changes at each update of the main project, so, version numbers will usually get out of sync anyway (unless you just rebuild the smeserver-XXXX RPM just to bump the version/release number)
  • You're using an absolute path to the source tgs, this is wrong, just stpecifies the tarball name without any path
  • You've added syncthing in the BuildRequires, I don't think syncthing is required to build smeserver-syncthing. It be Required instead of BuildRequired
  • It's obvious that you're still working under the root account of your build box. This is really a bad practice as you could totally break it, you should create an un privileged user account for this
  • You're using absolute paths in the %install section (especially /root/rpmbuild) which is wrong. A spec file must be buildable on any box, and under any user account
  • As already said before, the init script and the default config file should be included in the main syncthing RPM
  • You're chowning files in the %install section. Once again, this will be executed on the box building the RPM, not the one installing it. This will probably fail as I see no reason for the syncthing account to exist on the build box. Anyway, you should need to use chown in any step, it'd be cleaner to either use the correct -m argument to the install command, or specify the correct permissions in the %files section
  • You shouldn't use chkconfig (which in your case, once again, is executed on the box building the RPM). And the symlink creation would be better defined in e createlinks script, see http://wiki.contribs.org/Createlinks_example_script
  • For the DB properties, you should use the config command, but instead, you should provide fragments in /etc/e-smith/db. See the developer manual, especially http://wiki.contribs.org/SME_Server:Documentation:Developers_Manual#Database_initialization
  • You should never run any signal-event automatically (and once agin, this one would be executed on the build box anyway)
  • Your %files section is empty, which means your RPM will be.....empty. You should list files which should be included in the final RPM in this %files section

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

Cheers,
Daniel
C'est la fin du monde !!! :lol:

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #7 on: June 16, 2015, 09:22:46 AM »
Ok, thanks a lot for the fast answer ! I'll try and let you know !

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #8 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 ?




Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Create a RPM
« Reply #9 on: June 16, 2015, 02:17:27 PM »
Better, but not yet ready, a few more issues:

  • You're using the pre-compiled binaries tarball, then git clone the repository in the %build section. Neither is correct, you should get a source tarball, and only use this (you cannot use a git clone in the %build section, everything should be self contained in the SRPM)
  • export GOPATH=/tmp/go is probably not correct, as you cannot guarantee it'll have enough space on the build box, it should probably be set to %{builddir} or something standard
  • /etc/syncthing.md5 shouldn't be included in the final RPM, and neither the runit script (although you could put the runit script in %doc so it gets included in /usr/share/doc/ as a sample file)
  • Your changelog is still empty and should contains at least one entry (the initial packaging)

++
C'est la fin du monde !!! :lol:

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #10 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 ?
« Last Edit: June 16, 2015, 03:30:59 PM by MScapin »

Offline Daniel B.

  • *
  • 1,699
  • +0/-0
    • Firewall Services, la sécurité des réseaux
Re: Create a RPM
« Reply #11 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
C'est la fin du monde !!! :lol:

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #12 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

Offline MScapin

  • *
  • 14
  • +0/-0
Re: Create a RPM
« Reply #13 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...

Offline Stefano

  • *
  • 10,836
  • +2/-0
Re: Create a RPM
« Reply #14 on: June 16, 2015, 04:25:53 PM »
you must adapt paths to SME's standards

please read carefully the developers' manual (link above)