From 53cd0667836d6bbe73db85d4dca4ee66a7a5a351 Mon Sep 17 00:00:00 2001 From: Sean Mathews Date: Tue, 28 Nov 2017 12:23:33 -0800 Subject: [PATCH 1/3] Improved to create PID folder and set permissions to run daemon as at startup. Most systems clear out /var/run at boot so it must be initialized at boot every time. --- init/ser2sock | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/init/ser2sock b/init/ser2sock index 9d783f1..b1f170b 100755 --- a/init/ser2sock +++ b/init/ser2sock @@ -31,12 +31,15 @@ PROGRAM_NAME="ser2sock" # Use the name of this script as the SCRIPT_NAME SCRIPT_NAME=${0##*/} +# Uncoment next line to set user to run daemon as. Best to be a real user like "pi:pi". +#RUN_AS="root:root" + CONF_FILE="/etc/ser2sock/${SCRIPT_NAME}.conf" EXECUTABLE="/usr/local/bin/${PROGRAM_NAME}" -PID_FILE="/var/run/${SCRIPT_NAME}.pid" +PID_FILE="/var/run/${PROGRAM_NAME}/${SCRIPT_NAME}.pid" -#EXTRA_START_ARGS="--chuid pi:pi" EXTRA_START_ARGS="" + DAEMON_ARGS="-d -f ${CONF_FILE} -P ${PID_FILE}" RETVAL=0 @@ -45,6 +48,26 @@ GREEN=$(tput setaf 2) RED=$(tput setaf 1) NORMAL=$(tput sgr0) +# PID folder sanity check. /var/run may be a tmp file system so we need to check. +if [ ! -d /var/run/${PROGRAM_NAME} ]; then + mkdir /var/run/${PROGRAM_NAME} 2>/dev/null + if [ $? -ne 0 ]; then + echo $"${BOLD}${RED}Failed to create PID folder '/var/run/${PROGRAM_NAME}/'" + exit 1 + fi +fi + +# Are we running as a specific user? If so then we need the correct permissions. +if [ -n "${RUN_AS}" ]; then + EXTRA_START_ARGS+=" --chuid ${RUN_AS}" + # Set permissions to pid folder for the user + chown ${RUN_AS} /var/run/${PROGRAM_NAME} 2>/dev/null + if [ $? -ne 0 ]; then + echo $"${BOLD}${RED}Failed to set PID folder '/var/run/${PROGRAM_NAME}/' owner to '${RUN_AS}'" + exit 1 + fi +fi + start() { echo echo $"Starting instantiation ${BOLD}${SCRIPT_NAME}${NORMAL} of ${BOLD}${PROGRAM_NAME}${NORMAL}..." From dbedc7cb5468bdb4366266efc8f508655b3118db Mon Sep 17 00:00:00 2001 From: Sean Mathews Date: Tue, 28 Nov 2017 12:26:32 -0800 Subject: [PATCH 2/3] remove a few blank lines I did not like --- init/ser2sock | 2 -- 1 file changed, 2 deletions(-) diff --git a/init/ser2sock b/init/ser2sock index b1f170b..40f4867 100755 --- a/init/ser2sock +++ b/init/ser2sock @@ -37,9 +37,7 @@ SCRIPT_NAME=${0##*/} CONF_FILE="/etc/ser2sock/${SCRIPT_NAME}.conf" EXECUTABLE="/usr/local/bin/${PROGRAM_NAME}" PID_FILE="/var/run/${PROGRAM_NAME}/${SCRIPT_NAME}.pid" - EXTRA_START_ARGS="" - DAEMON_ARGS="-d -f ${CONF_FILE} -P ${PID_FILE}" RETVAL=0 From 28de6adfe078ff2c500e114f559b7a8a49bb44bb Mon Sep 17 00:00:00 2001 From: Sean Mathews Date: Tue, 28 Nov 2017 12:38:27 -0800 Subject: [PATCH 3/3] bump revision and log changes. --- ChangeLog | 4 ++++ configure | 20 ++++++++++---------- configure.ac | 2 +- ser2sock.c | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c33b56..3ab1b5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +v1.5.5 - 11/28/17 + Improved init.d script to create PID folder and set permissions as needed as well + as well as improve configuration for daemon owner and group. + v1.5.4 - 07/05/17 Fixed a termination issue while debug logging. Updated configure scripts to use SSL_CTX_new instead of SSL_library_init to support OpenSSL 1.1 diff --git a/configure b/configure index b5a0b40..cb45dd4 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for ser2sock 1.4.4. +# Generated by GNU Autoconf 2.69 for ser2sock 1.5.5. # # Report bugs to . # @@ -580,8 +580,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='ser2sock' PACKAGE_TARNAME='ser2sock' -PACKAGE_VERSION='1.4.4' -PACKAGE_STRING='ser2sock 1.4.4' +PACKAGE_VERSION='1.5.5' +PACKAGE_STRING='ser2sock 1.5.5' PACKAGE_BUGREPORT='general@support.nutech.com' PACKAGE_URL='' @@ -1264,7 +1264,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures ser2sock 1.4.4 to adapt to many kinds of systems. +\`configure' configures ser2sock 1.5.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1330,7 +1330,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of ser2sock 1.4.4:";; + short | recursive ) echo "Configuration of ser2sock 1.5.5:";; esac cat <<\_ACEOF @@ -1425,7 +1425,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -ser2sock configure 1.4.4 +ser2sock configure 1.5.5 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1848,7 +1848,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by ser2sock $as_me 1.4.4, which was +It was created by ser2sock $as_me 1.5.5, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2664,7 +2664,7 @@ fi # Define the identity of the package. PACKAGE='ser2sock' - VERSION='1.4.4' + VERSION='1.5.5' cat >>confdefs.h <<_ACEOF @@ -5106,7 +5106,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by ser2sock $as_me 1.4.4, which was +This file was extended by ser2sock $as_me 1.5.5, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5172,7 +5172,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -ser2sock config.status 1.4.4 +ser2sock config.status 1.5.5 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index b50d224..b2a76df 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT(ser2sock, 1.5.4, general@support.nutech.com) +AC_INIT(ser2sock, 1.5.5, general@support.nutech.com) AC_CONFIG_SRCDIR([ser2sock.c]) AM_INIT_AUTOMAKE AC_CONFIG_HEADERS([config.h]) diff --git a/ser2sock.c b/ser2sock.c index e0f920d..fbbb886 100644 --- a/ser2sock.c +++ b/ser2sock.c @@ -62,7 +62,7 @@ #include #endif -#define SER2SOCK_VERSION "V1.5.2" +#define SER2SOCK_VERSION "V1.5.5" #define TRUE 1 #define FALSE 0