From adc8f9a119711b26615805f8ea8f7b2d6fe52b61 Mon Sep 17 00:00:00 2001 From: Niek Vlessert Date: Tue, 20 Oct 2015 23:21:50 +0200 Subject: [PATCH 1/3] FS-8369 Debian8/CentOS7 systemd installer additions 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 | 8 +++++ build/freeswitch-tmpfiles.conf | 1 - build/freeswitch.service | 17 ---------- configure.ac | 28 +++++++++++++++ init/freeswitch.default | 2 ++ init/freeswitch.service.in | 31 +++++++++++++++++ init/freeswitch.tmpfile | 1 + init/install_systemd.sh.in | 62 ++++++++++++++++++++++++++++++++++ 8 files changed, 132 insertions(+), 18 deletions(-) delete mode 100644 build/freeswitch-tmpfiles.conf delete mode 100644 build/freeswitch.service create mode 100644 init/freeswitch.default create mode 100644 init/freeswitch.service.in create mode 100644 init/freeswitch.tmpfile create mode 100644 init/install_systemd.sh.in diff --git a/build/Makefile.am b/build/Makefile.am index 61ac412d42..38202826da 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -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 index 881873fb29..0000000000 --- a/build/freeswitch-tmpfiles.conf +++ /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 index ae6921b4df..0000000000 --- a/build/freeswitch.service +++ /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 diff --git a/configure.ac b/configure.ac index 10d13898b0..df050a0001 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000000..41cd0758c6 --- /dev/null +++ b/init/freeswitch.default @@ -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 index 0000000000..930c8c2b93 --- /dev/null +++ b/init/freeswitch.service.in @@ -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 index 0000000000..baea7b8113 --- /dev/null +++ b/init/freeswitch.tmpfile @@ -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 index 0000000000..60253a141a --- /dev/null +++ b/init/install_systemd.sh.in @@ -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 From 757fa94239e67aed08ec8ada776415e08a18987a Mon Sep 17 00:00:00 2001 From: Niek Vlessert Date: Tue, 20 Oct 2015 23:21:50 +0200 Subject: [PATCH 2/3] FS-8369 Debian8/CentOS7 systemd installer additions 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 build/startup 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 all bindir directory prefixes ./configure can have * Detects if Debian8/CentOS7 use systemd * Can be used with a user with sudo permissions --- build/Makefile.am | 6 +++--- {init => build/startup}/freeswitch.default | 0 {init => build/startup}/freeswitch.service.in | 0 {init => build/startup}/freeswitch.tmpfile | 0 {init => build/startup}/install_systemd.sh.in | 8 ++++---- configure.ac | 7 ++++--- 6 files changed, 11 insertions(+), 10 deletions(-) rename {init => build/startup}/freeswitch.default (100%) rename {init => build/startup}/freeswitch.service.in (100%) rename {init => build/startup}/freeswitch.tmpfile (100%) rename {init => build/startup}/install_systemd.sh.in (91%) diff --git a/build/Makefile.am b/build/Makefile.am index 38202826da..dbda77330e 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -57,10 +57,10 @@ install: @echo " + $(MK) samples +" if KNOWN_INIT @echo " + +" - @echo " + Install init scripts: +" - @echo " + --------------------- +" + @echo " + Install startup scripts: +" + @echo " + ------------------------ +" @echo " + +" - @echo " + init/install_systemd.sh +" + @echo " + build/startup/install_systemd.sh +" endif @echo " + +" @echo " + +" diff --git a/init/freeswitch.default b/build/startup/freeswitch.default similarity index 100% rename from init/freeswitch.default rename to build/startup/freeswitch.default diff --git a/init/freeswitch.service.in b/build/startup/freeswitch.service.in similarity index 100% rename from init/freeswitch.service.in rename to build/startup/freeswitch.service.in diff --git a/init/freeswitch.tmpfile b/build/startup/freeswitch.tmpfile similarity index 100% rename from init/freeswitch.tmpfile rename to build/startup/freeswitch.tmpfile diff --git a/init/install_systemd.sh.in b/build/startup/install_systemd.sh.in similarity index 91% rename from init/install_systemd.sh.in rename to build/startup/install_systemd.sh.in index 60253a141a..6fe5374a5c 100644 --- a/init/install_systemd.sh.in +++ b/build/startup/install_systemd.sh.in @@ -25,11 +25,11 @@ 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@" + echo "- Set permissions on @prefix@ and files in @bindir_expanded@" fi echo "- Install systemd unit file" echo "- Install /etc/@environmentfilelocation@/freeswitch" -echo +echo read -p "Do you want to continue? (y/n) " -n 1 -r if [[ $REPLY =~ ^[yY]$ ]] then @@ -45,7 +45,7 @@ then then $SUDO chown -R freeswitch:freeswitch @prefix@ $SUDO chmod -R ug=rwX,o= @prefix@ - $SUDO chmod -R u=rwx,g=rx @bindir@/* + $SUDO chmod -R u=rwx,g=rx @bindir_expanded@/* fi $SUDO cp init/freeswitch.service /etc/systemd/system/ $SUDO cp init/freeswitch.tmpfile /etc/tmpfiles.d/freeswitch.conf @@ -58,5 +58,5 @@ then 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" + echo "Then start fs_cli by running @bindir_expanded@/fs_cli" fi diff --git a/configure.ac b/configure.ac index df050a0001..a1d8010a39 100644 --- a/configure.ac +++ b/configure.ac @@ -83,7 +83,7 @@ default_certsdir="$prefix/certs" default_fontsdir="$prefix/fonts" default_imagesdir="$prefix/images" -bindir="$exec_prefix/bin" +eval bindir_expanded="${bindir}" if test "${enable_fhs}" = "yes"; then eval full_datadir="${datadir}/freeswitch" @@ -789,8 +789,9 @@ case "$host" in 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]) + AC_SUBST(bindir_expanded) + AC_CONFIG_FILES([build/startup/install_systemd.sh], [chmod +x build/startup/install_systemd.sh]) + AC_CONFIG_FILES([build/startup/freeswitch.service]) fi ;; *) From 389d24da145531e3abb7dc943f6c2609286cf685 Mon Sep 17 00:00:00 2001 From: Niek Vlessert Date: Tue, 10 Nov 2015 19:43:46 +0100 Subject: [PATCH 3/3] FS-8369 Fixes - Don't check OS, current patch should be compatible with Debian and RHEL derivatives and ArchLinux - Make useradd the tool to add the usera nd group to work on all --- build/Makefile.am | 6 +++--- build/startup/freeswitch.service.in | 7 +++--- build/startup/install_systemd.sh.in | 25 ++++++++++------------ configure.ac | 33 ++++++----------------------- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/build/Makefile.am b/build/Makefile.am index dbda77330e..936ab56843 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -55,10 +55,10 @@ install: @echo " + Install/Re-install default config: +" @echo " + ---------------------------------- +" @echo " + $(MK) samples +" -if KNOWN_INIT +if SYSTEMD_INIT @echo " + +" - @echo " + Install startup scripts: +" - @echo " + ------------------------ +" + @echo " + Install systemd startup scripts: +" + @echo " + -------------------------------- +" @echo " + +" @echo " + build/startup/install_systemd.sh +" endif diff --git a/build/startup/freeswitch.service.in b/build/startup/freeswitch.service.in index 930c8c2b93..f580ba2480 100644 --- a/build/startup/freeswitch.service.in +++ b/build/startup/freeswitch.service.in @@ -5,11 +5,12 @@ After=syslog.target network.target local-fs.target [Service] ; service Type=forking -PIDFile=@rundir@/freeswitch.pid +PIDFile=@runtimedir@/freeswitch.pid PermissionsStartOnly=true Environment="DAEMON_OPTS=-nonat" -EnvironmentFile=-/etc/@environmentfilelocation@/freeswitch -ExecStart=@bindir@/freeswitch -u freeswitch -g freeswitch -ncwait -rp ${DAEMON_OPTS} +EnvironmentFile=-/etc/sysconfig/freeswitch +EnvironmentFile=-/etc/default/freeswitch +ExecStart=@bindir_expanded@/freeswitch -u freeswitch -g freeswitch -ncwait -rp ${DAEMON_OPTS} TimeoutSec=20s Restart=on-failure ; exec diff --git a/build/startup/install_systemd.sh.in b/build/startup/install_systemd.sh.in index 6fe5374a5c..3f77c4f8b3 100644 --- a/build/startup/install_systemd.sh.in +++ b/build/startup/install_systemd.sh.in @@ -1,9 +1,8 @@ #!/bin/bash -# @DISTRO@ installer # Niek Vlessert USER=`whoami` -DISTRO=@DISTRO@ +DISTRO=$(source /etc/os-release && echo $PRETTY_NAME) if [ $USER != "root" ] ; then SUDO=`which sudo | awk -F"/" '{print $NF}'` if [ -z $SUDO ] ; then @@ -20,36 +19,34 @@ if [ $USER != "root" ] ; then fi echo -echo "This will do several things on your @DISTRO@ installation:" +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_expanded@" fi -echo "- Install systemd unit file" -echo "- Install /etc/@environmentfilelocation@/freeswitch" +echo "- Install systemd unit file and other required files" 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 + $SUDO useradd -d @confdir@ -r -U -s /bin/false -c "FreeSWITCH open source softswitch" freeswitch 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_expanded@/* 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 cp build/startup/freeswitch.service /etc/systemd/system/ + $SUDO cp build/startup/freeswitch.tmpfile /etc/tmpfiles.d/freeswitch.conf + if [ -d /etc/sysconfig ]; then + $SUDO cp build/startup/freeswitch.default /etc/sysconfig/freeswitch + else + $SUDO cp build/startup/freeswitch.default /etc/default/freeswitch + fi $SUDO systemd-tmpfiles --clean --create $SUDO systemctl daemon-reload echo diff --git a/configure.ac b/configure.ac index a1d8010a39..4f3e0d24e6 100644 --- a/configure.ac +++ b/configure.ac @@ -773,33 +773,14 @@ 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_SUBST(bindir_expanded) - AC_CONFIG_FILES([build/startup/install_systemd.sh], [chmod +x build/startup/install_systemd.sh]) - AC_CONFIG_FILES([build/startup/freeswitch.service]) - fi - ;; - *) - knowninit=false - ;; - esac + systemdinit=false + if test -d /run/systemd/system; then + systemdinit=true + AC_SUBST(bindir_expanded) + AC_CONFIG_FILES([build/startup/install_systemd.sh], [chmod +x build/startup/install_systemd.sh]) + AC_CONFIG_FILES([build/startup/freeswitch.service]) fi - AM_CONDITIONAL([KNOWN_INIT], [test x$knowninit = xtrue]) + AM_CONDITIONAL([SYSTEMD_INIT], [test x$systemdinit = xtrue]) ;; esac