]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8369 Debian8/CentOS7 systemd installer additions
authorNiek Vlessert <niekvlessert@gmail.com>
Tue, 20 Oct 2015 21:21:50 +0000 (23:21 +0200)
committerNiek Vlessert <niekvlessert@gmail.com>
Tue, 20 Oct 2015 21:21:50 +0000 (23:21 +0200)
After builing Freeswitch this makes actually run it easy by offering
an installer script.

* Changes to configure.ac to detect Debian8/CentOS 7 and create installer script
* Changes to build/Makefile.am to display the option
* Added init directory with templates and other files
* Deleted outdated build/freeswitch.service and tmpfiles.conf
* Unit file based on the latest systemd service file FS-8194
* Won't interfere with other platforms (afaik)
* Supports ./configure --prefix=
* Detects if Debian8/CentOS7 use systemd
* Can be used with a user with sudo permissions

build/Makefile.am
build/freeswitch-tmpfiles.conf [deleted file]
build/freeswitch.service [deleted file]
configure.ac
init/freeswitch.default [new file with mode: 0644]
init/freeswitch.service.in [new file with mode: 0644]
init/freeswitch.tmpfile [new file with mode: 0644]
init/install_systemd.sh.in [new file with mode: 0644]

index 61ac412d4223601efcd07d5f7f3dc7fa4434a8fc..38202826da4fca583cc075a85456d35cacc6c411 100644 (file)
@@ -1,5 +1,6 @@
 MK=`echo $(MAKE) | $(AWK) '{printf "%5s\n", $$0}' `
 
+
 all:
        @echo " +---------- FreeSWITCH Build Complete ----------+"
        @echo " + FreeSWITCH has been successfully built.       +"
@@ -54,6 +55,13 @@ install:
        @echo " +       Install/Re-install default config:        +"
        @echo " +       ----------------------------------        +"
        @echo " +               $(MK) samples                     +"
+if KNOWN_INIT
+       @echo " +                                                 +"
+       @echo " +       Install init scripts:                     +"
+       @echo " +       ---------------------                     +"
+       @echo " +                                                 +"
+       @echo " +       init/install_systemd.sh                   +"
+endif
        @echo " +                                                 +"
        @echo " +                                                 +"
        @echo " +       Additional resources:                     +"
diff --git a/build/freeswitch-tmpfiles.conf b/build/freeswitch-tmpfiles.conf
deleted file mode 100644 (file)
index 881873f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-d /run/freeswitch 0750 freeswitch daemon -
diff --git a/build/freeswitch.service b/build/freeswitch.service
deleted file mode 100644 (file)
index ae6921b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=FreeSWITCH
-After=syslog.target network.target
-After=postgresql.service postgresql-9.3.service postgresql-9.4.service mysqld.service httpd.service
-
-[Service]
-User=freeswitch
-EnvironmentFile=-/etc/sysconfig/freeswitch
-# RuntimeDirectory is not yet supported in CentOS 7. A workaround is to use /etc/tmpfiles.d/freeswitch.conf
-#RuntimeDirectory=/run/freeswitch
-#RuntimeDirectoryMode=0750
-WorkingDirectory=/run/freeswitch
-ExecStart=/usr/bin/freeswitch -nc -nf $FREESWITCH_PARAMS
-ExecReload=/usr/bin/kill -HUP $MAINPID
-
-[Install]
-WantedBy=multi-user.target
index 10d13898b002bf883ee90341023e4e327274324f..df050a0001cc77772c910f425dd940d628dc6426 100644 (file)
@@ -83,6 +83,8 @@ default_certsdir="$prefix/certs"
 default_fontsdir="$prefix/fonts"
 default_imagesdir="$prefix/images"
 
+bindir="$exec_prefix/bin"
+
 if test "${enable_fhs}" = "yes"; then
     eval full_datadir="${datadir}/freeswitch"
     eval datadir=$full_datadir
@@ -771,6 +773,32 @@ case "$host" in
     ;;
     *linux*)
        APR_ADDTO([PLATFORM_CORE_LIBS], [-ldl -lcrypt -lrt])
+       if test -f /etc/os-release; then
+               DISTRO="$(source /etc/os-release && echo $ID$VERSION_ID)"
+               case "$DISTRO" in
+                       *debian8*)
+                               environmentfilelocation="default"
+                               ;;&
+                       *centos7*)
+                               environmentfilelocation="sysconfig"
+                               ;;&
+                       *debian8*|*centos7*)
+                               knowninit=false
+                               if test -d /run/systemd/system; then
+                                       knowninit=true
+                                       AC_SUBST(DISTRO)
+                                       AC_SUBST(rundir)
+                                       AC_SUBST(environmentfilelocation)
+                                       AC_CONFIG_FILES([init/install_systemd.sh], [chmod +x init/install_systemd.sh])
+                                       AC_CONFIG_FILES([init/freeswitch.service])
+                               fi
+                               ;;
+                       *)
+                               knowninit=false
+                               ;;
+               esac
+       fi
+       AM_CONDITIONAL([KNOWN_INIT], [test x$knowninit = xtrue])
     ;;
 esac
 
diff --git a/init/freeswitch.default b/init/freeswitch.default
new file mode 100644 (file)
index 0000000..41cd075
--- /dev/null
@@ -0,0 +1,2 @@
+# /etc/default/freeswitch
+DAEMON_OPTS="-nonat"
diff --git a/init/freeswitch.service.in b/init/freeswitch.service.in
new file mode 100644 (file)
index 0000000..930c8c2
--- /dev/null
@@ -0,0 +1,31 @@
+[Unit]
+Description=freeswitch
+After=syslog.target network.target local-fs.target
+
+[Service]
+; service
+Type=forking
+PIDFile=@rundir@/freeswitch.pid
+PermissionsStartOnly=true
+Environment="DAEMON_OPTS=-nonat"
+EnvironmentFile=-/etc/@environmentfilelocation@/freeswitch
+ExecStart=@bindir@/freeswitch -u freeswitch -g freeswitch -ncwait -rp ${DAEMON_OPTS}
+TimeoutSec=20s
+Restart=on-failure
+; exec
+User=root
+Group=daemon
+LimitCORE=infinity
+LimitNOFILE=100000
+LimitNPROC=60000
+;LimitSTACK=240
+LimitRTPRIO=infinity
+LimitRTTIME=7000000
+IOSchedulingClass=realtime
+IOSchedulingPriority=2
+CPUSchedulingPolicy=rr
+CPUSchedulingPriority=89
+UMask=0007
+
+[Install]
+WantedBy=multi-user.target
diff --git a/init/freeswitch.tmpfile b/init/freeswitch.tmpfile
new file mode 100644 (file)
index 0000000..baea7b8
--- /dev/null
@@ -0,0 +1 @@
+d /var/run/freeswitch 0755 freeswitch freeswitch - -
diff --git a/init/install_systemd.sh.in b/init/install_systemd.sh.in
new file mode 100644 (file)
index 0000000..60253a1
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+# @DISTRO@ installer
+# Niek Vlessert
+
+USER=`whoami`
+DISTRO=@DISTRO@
+if [ $USER != "root" ] ; then
+       SUDO=`which sudo | awk -F"/" '{print $NF}'`
+       if [ -z $SUDO ] ; then
+               echo "No root and no sudo... please run this as root or install sudo and make sure your user has permissions to use it."
+               exit
+       else
+               read -p "The currently active user is not root but sudo is available... do you want to install using sudo? (y/n) " -n 1 -r
+               if ! [[ $REPLY =~ ^[yY]$ ]]
+               then
+                       echo
+                       exit
+               fi
+       fi
+fi
+
+echo
+echo "This will do several things on your @DISTRO@ installation:"
+echo "- Create user freeswitch and add it to group freeswitch"
+FSPATH=@prefix@
+if [[ $FSPATH == *"freeswitch"* ]]
+then
+       echo "- Set permissions on @prefix@ and files in @bindir@"
+fi
+echo "- Install systemd unit file"
+echo "- Install /etc/@environmentfilelocation@/freeswitch"
+echo 
+read -p "Do you want to continue? (y/n) " -n 1 -r
+if [[ $REPLY =~ ^[yY]$ ]]
+then
+       echo
+       echo "Installing..."
+       $SUDO groupadd freeswitch
+       if DISTRO="debian8"; then
+               $SUDO adduser --disabled-password  --quiet --system --home @confdir@ --gecos "FreeSWITCH open source softswitch" --ingroup freeswitch freeswitch
+       elif DISTRO="centos7"; then
+               $SUDO adduser --system --home @confdir@ -c "FreeSWITCH open source softswitch" -g freeswitch freeswitch
+       fi
+       if [[ $FSPATH == *"freeswitch"* ]]
+       then
+               $SUDO chown -R freeswitch:freeswitch @prefix@
+               $SUDO chmod -R ug=rwX,o= @prefix@
+               $SUDO chmod -R u=rwx,g=rx @bindir@/*
+       fi
+       $SUDO cp init/freeswitch.service /etc/systemd/system/
+       $SUDO cp init/freeswitch.tmpfile /etc/tmpfiles.d/freeswitch.conf
+       $SUDO cp init/freeswitch.default /etc/@environmentfilelocation@/freeswitch
+       $SUDO systemd-tmpfiles --clean --create
+       $SUDO systemctl daemon-reload
+       echo
+       if [ -f @confdir@/vars.xml ] ; then
+               echo "You may now start Freeswitch using 'systemctl start freeswitch'"
+       else
+               echo "Make sure your config files are in place in @confdir@, if they are you can start Freeswitch using 'systemctl start freeswitch'"
+       fi
+       echo "Then start fs_cli by running @bindir@/fs_cli"
+fi