From 9a9a17da92308dfbd6a0ff9a2f74449573872119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 2 Mar 2016 15:25:58 +0000 Subject: [PATCH] proper packaging and upstart scripts for ubuntu --- ax_init_standard_project.m4 | 78 ++++++++++++--------- bootstrap.sh | 112 +++++++++++++++++++++++++------ build-in-docker.sh | 2 +- debian/control.in | 2 +- debian/servicedock.postinst | 6 ++ mac-create-app-bundle.sh | 4 +- nodejs/etc/default/servicedock | 10 +++ nodejs/etc/init/servicedock.conf | 38 +++++++++++ nodejs/etc/servicedock.json | 2 +- nodejs/makefile.am | 6 +- nodejs/servicedock.js | 12 ++++ 11 files changed, 214 insertions(+), 58 deletions(-) create mode 100644 debian/servicedock.postinst create mode 100644 nodejs/etc/default/servicedock create mode 100755 nodejs/etc/init/servicedock.conf diff --git a/ax_init_standard_project.m4 b/ax_init_standard_project.m4 index 55480d8..93b6a8f 100644 --- a/ax_init_standard_project.m4 +++ b/ax_init_standard_project.m4 @@ -8,43 +8,60 @@ m4_define([mrw_esyscmd_s], [m4_normalize(m4_esyscmd([$1]))]) # define least version number from subversion's revision number: # it is taken modulo 256 due to a bug on Apple's MacOSX -m4_define(x_least, m4_ifdef([x_least_diff], mrw_esyscmd_s([ - SVN_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-svn-checkout" - for path in . .. ../..; do - if svn info $path 2>&1 > /dev/null; then - SVN_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') - if test -z "${SVN_REVISION}"; then SVN_REVISION=0; fi - break; - fi - done - echo $ECHO_N $(($SVN_REVISION)) -]), mrw_esyscmd_s([ - SVN_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-svn-checkout" - for path in . .. ../..; do - if svn info $path 2>&1 > /dev/null; then - SVN_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') - if test -z "${SVN_REVISION}"; then SVN_REVISION=0; fi - break; - fi - done - # Mac does not support LEAST > 255 - echo $ECHO_N $(($SVN_REVISION%256)) -]))) +m4_define(x_least, m4_ifdef([x_least_fix], [x_least_fix], + m4_ifdef([x_least_diff], + mrw_esyscmd_s([ + VCS_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-checkout" + for path in . .. ../..; do + if test -d .svn; then + VCS_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi + break; + elif test -d .git; then + VCS_REVISION=$(git rev-list --all --count) + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi + break; + fi + done + echo $ECHO_N $(($VCS_REVISION)) + ]), mrw_esyscmd_s([ + VCS_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-checkout" + for path in . .. ../..; do + if test -d .svn; then + VCS_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi + break; + elif test -d .git; then + VCS_REVISION=$(git rev-list --all --count) + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi + break; + fi + done + # Mac does not support LEAST > 255 + echo $ECHO_N $(($VCS_REVISION%256)) + ]) + ) +)) + # define version number from subversion's revision number: # it is taken modulo 256 due to a bug on Apple's MacOSX # add to x_minor if revision number is > 256 -m4_define(x_minor_diff, mrw_esyscmd_s([ - SVN_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-svn-checkout" +m4_define(x_minor_diff, m4_ifdef([x_least_fix], 0, mrw_esyscmd_s([ + VCS_REVISION="ERROR-UNDEFINED-REVISION-to-be-built-in-subdirectory-of-checkout" for path in . .. ../..; do - if svn info $path 2>&1 > /dev/null; then - SVN_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') - if test -z "${SVN_REVISION}"; then SVN_REVISION=0; fi + if test -d .svn; then + VCS_REVISION=$(LANG= svn info $path | sed -n 's/Last Changed Rev: //p') + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi + break; + elif test -d .git; then + VCS_REVISION=$(git rev-list --all --count) + if test -z "${VCS_REVISION}"; then VCS_REVISION=0; fi break; fi; done # Mac does not support LEAST > 255 - echo $ECHO_N $(($SVN_REVISION/256)) -])) + echo $ECHO_N $(($VCS_REVISION/256)) +]))) # setup version number m4_define(x_version, [x_major.m4_ifdef([x_least_diff], x_minor, m4_eval(x_minor+x_minor_diff)).m4_eval(m4_ifdef([x_least_diff], [x_least-x_least_diff], [x_least]))]) @@ -384,7 +401,7 @@ EXTRA_DIST += debian clean-debian-targets: -rm -rf \${PACKAGE_NAME}_\${PACKAGE_VERSION}~\${DISTRO}.\${BUILD_NUMBER}.{dsc,tar.gz} \${PACKAGE_NAME}_\${PACKAGE_VERSION}~\${DISTRO}.\${BUILD_NUMBER}*.changes \$\$(sed -n 's,Package: \(.*\),\1_${PACKAGE_VERSION}~${DISTRO}.${BUILD_NUMBER}*.deb,p;' debian/control) deb: distdir - cd \${PACKAGE_NAME}-\${PACKAGE_VERSION} && ( export CFLAGS="\${CFLAGS}"; export CPPFLAGS="\${CPPFLAGS}"; export CXXFLAGS="\${CXXFLAGS}"; export LDFLAGS="\${LDFLAGS}"; export DEB_CFLAGS_APPEND="\${CFLAGS}"; export DEB_CPPFLAGS_APPEND="\${CPPFLAGS}"; export DEB_CXXFLAGS_APPEND="\${CXXFLAGS}"; export DEB_LDFLAGS_APPEND="\${LDFLAGS}"; dpkg-buildpackage ) + cd \${PACKAGE_NAME}-\${PACKAGE_VERSION} && ( export CFLAGS="\${CFLAGS}"; export CPPFLAGS="\${CPPFLAGS}"; export CXXFLAGS="\${CXXFLAGS}"; export LDFLAGS="\${LDFLAGS}"; export DEB_CFLAGS_APPEND="\${CFLAGS}"; export DEB_CPPFLAGS_APPEND="\${CPPFLAGS}"; export DEB_CXXFLAGS_APPEND="\${CXXFLAGS}"; export DEB_LDFLAGS_APPEND="\${LDFLAGS}"; dpkg-buildpackage ) distclean-debian-targets: -rm debian/changelog debian/control #### End: $0 @@ -618,6 +635,7 @@ AC_DEFUN([AX_PKG_CHECK], [ # make sure, a specific header exists # - parameter: # $1 = header name +# $2 = pathes to search for AC_DEFUN([AX_REQUIRE_HEADER], [ AC_CHECK_HEADER($1, [], [ if test -n "$2"; then diff --git a/bootstrap.sh b/bootstrap.sh index 39e31b7..ffee6de 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -61,7 +61,7 @@ DESCRIPTION configure.ac. Automatically copies or creates all required template files. - From your new and empty project's subversion path, call $0 to + From your new and empty project's subversion or git path, call $0 to initialize your build environment. Before you call ${MY_NAME} the very first time, edit ${0#/*}/AUTHORS @@ -80,16 +80,27 @@ DESCRIPTION https://dev.marc.waeckerlin.org/, and the path from where you call ${MY_NAME} (which is actually ${PROJECT_PATH}) should be the path to your newly created project. Please note that your project must be a - checked out subversion repository, since this build environment - relies on subversion. + checked out subversion or git repository, since this build + environment relies on subversion or git. Example for an initial run, where your new projet is stored in - subversion on svn:/path/to/your/new-project: + subversion on https:/path/to/your/new-project: cd ~/svn svn co https://dev.marc.waeckerlin.org/svn/bootstrap-build-environment/trunk \\ bootstrap-build-environment - svn co svn:/path/to/your/new-project/trunk new-project + svn co https:/path/to/your/new-project/trunk new-project + cd new-project + ../bootstrap-build-environment/bootstrap.sh + + Example for an initial run, where your new projet is stored in + git on https:/path/to/your/new-project: + + cd ~/svn + svn co https://dev.marc.waeckerlin.org/svn/bootstrap-build-environment/trunk \\ + bootstrap-build-environment + cd ~/git + git clone https:/path/to/your/new-project cd new-project ../bootstrap-build-environment/bootstrap.sh @@ -201,13 +212,14 @@ FILES ${DEFAULT_PROJECT_NAME}::description(). * ChangeLog: Your changelog is automatically maintained from subversion history, using svn2cl. You don't need to - care about. + care about. It uses git2cl on git repositories. * configure.ac: This file becomes very short and simple. You provide the project name, the major and minor version. The least version number is automatically taken from subversion's revision, so every checkin automatically increments the least version - number. The following macros are supported: + number. In git, git rev-list --all --count is used. + The following macros are supported in configure.ac: * Enable C++: AX_USE_CXX * Enable LibTool library creation: AX_USE_LIBTOOL * Enable Scripts: AX_USE_SCRIPTS @@ -247,6 +259,20 @@ EOF shift; done +echo -en "\e[1m-> checking:\e[0m for version control system ..." +VCS="" +VCSDEPENDS="" +if test -d .svn; then + VCS="svn" + VCSDEPENDS="subversion," + echo -e " \e[32msuccess\e[0m detected ${VCS}" +elif test -d .git; then + VCS="git" + VCSDEPENDS="git," + echo -e " \e[32msuccess\e[0m detected ${VCS}" +else + echo -e " \e[33mignored\e[0m" +fi HEADER='## @id '"\$Id\$"' ## @@ -270,6 +296,7 @@ CHEADER='/** @id '"\$Id\$"' // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 + ' notice() { @@ -318,7 +345,9 @@ contains() { checkdir() { if ! test -d "$1"; then # create path run mkdir -p "$1" - run svn add "$1" + if test -n "${VCS}"; then + run ${VCS} add "$1" + fi fi } @@ -365,8 +394,12 @@ to() { fi chmod $mode $1 if test $exists -eq 0; then - run svn add "$1" - run svn propset svn:keywords "Id" "$1" + if test -n "${VCS}"; then + run ${VCS} add "$1" + if test "${VCS}" = "svn"; then + run svn propset svn:keywords "Id" "$1" + fi + fi fi return 0 } @@ -386,8 +419,12 @@ copy() { fi run cp "${source}" "$1" if test $exists -eq 0; then - run svn add "$1" - run svn propset svn:keywords "Id" "$1" + if test -n "${VCS}"; then + run ${VCS} add "$1" + if test "${VCS}" = "svn"; then + run svn propset svn:keywords "Id" "$1" + fi + fi fi } @@ -413,10 +450,29 @@ doxyadd() { fi } +vcs2cl() { + exists=0 + if test -f "Changelog"; then + exists=1 + fi + if test "${VCS}" = "git"; then + ${VCS}2cl > ChangeLog + elif test -n "${VCS}"; then + ${VCS}2cl + fi + if test $exists -eq 0; then + if test -n "${VCS}"; then + run ${VCS} add ChangeLog + fi + fi +} + # Check if we are in subversion root, if so, create trunk, branches, tags: -if test "$(LANG= svn info | sed -n 's,Relative URL: *,,p')" = "^/"; then - svn mkdir trunk branches tags - cd trunk +if test "${VCS}" = "svn"; then + if test "$(LANG= svn info | sed -n 's,Relative URL: *,,p')" = "^/"; then + svn mkdir trunk branches tags + cd trunk + fi fi # Initialize the environment: @@ -723,7 +779,9 @@ ${HEADER}dist_bin_SCRIPTS = MAINTAINERCLEANFILES = makefile.in EOF echo "${HEADER}MAINTAINERCLEANFILES = makefile.in" | to --condition AX_USE_DOXYGEN doc/makefile.am -to --condition AX_BUILD_TEST test/runtests.sh < ${0%/*}/test/runtests.sh +if testtag AX_BUILD_TEST; then + to test/runtests.sh < ${0%/*}/test/runtests.sh +fi to --condition 'AX_BUILD_TEST|AX_USE_CPPUNIT' test/makefile.am </dev/null; then + adduser servicedock --quiet --system --ingroup docker --no-create-home --home /usr/share/servicedock +fi diff --git a/mac-create-app-bundle.sh b/mac-create-app-bundle.sh index 6ced200..d1f41a6 100755 --- a/mac-create-app-bundle.sh +++ b/mac-create-app-bundle.sh @@ -75,7 +75,7 @@ cd ${oldpath} # Step 4: if necessary, install qt_menu.nib if test -n "${QTDIR}"; then - MENU_NIB=$(find ${QTDIR} -name .svn -prune -o -name qt_menu.nib -print \ + MENU_NIB=$(find ${QTDIR} -name .svn -o -name .git -prune -o -name qt_menu.nib -print \ | head -1) if test -e "${MENU_NIB}"; then rsync -r "${MENU_NIB}" ${1}/Contents/Resources/ @@ -100,4 +100,4 @@ else EOF -fi \ No newline at end of file +fi diff --git a/nodejs/etc/default/servicedock b/nodejs/etc/default/servicedock new file mode 100644 index 0000000..1e30417 --- /dev/null +++ b/nodejs/etc/default/servicedock @@ -0,0 +1,10 @@ +# set values for servicedock process + +#EXEC_SERVICEDOCK="/usr/bin/nodejs /usr/share/servicedock/nodejs/servicedock" + +# by default logs to /var/log/servicedock.log +SERVICEDOCK_LOG="/dev/null" + +#SERVICEDOCK_USER="servicedock" + +#SERVICEDOCK_PORT="8888" diff --git a/nodejs/etc/init/servicedock.conf b/nodejs/etc/init/servicedock.conf new file mode 100755 index 0000000..bfc1156 --- /dev/null +++ b/nodejs/etc/init/servicedock.conf @@ -0,0 +1,38 @@ +#!upstart +description "ServiceDock" +author "Marc Wäckerlin" + +start on (local-filesystems and net-device-up) +stop on runlevel [!2345] + +respawn + +script + echo $$ > /var/run/servicedock.pid + # there are some useful defaults + # do not edit this file, overwrite values in /etc/default/servicedock + EXEC_SERVICEDOCK="/usr/bin/nodejs /usr/share/servicedock/nodejs/servicedock" + SERVICEDOCK_LOG="/var/log/servicedock.log" + SERVICEDOCK_USER="servicedock" + SERVICEDOCK_PORT="" + [ -r /etc/default/servicedock ] && . /etc/default/servicedock + if test -n "${SERVICEDOCK_USER}"; then + exec sudo -u "${SERVICEDOCK_USER}" ${EXEC_SERVICEDOCK} ${SERVICEDOCK_PORT} >> ${SERVICEDOCK_LOG} 2>&1 + else + exec ${NODEJS_BIN} >> ${SERVICEDOCK_LOG} 2>&1 + fi +end script + +pre-start script + SERVICEDOCK_LOG="/var/log/servicedock.log" + [ -r /etc/default/servicedock ] && . /etc/default/servicedock + # Date format same as (new Date()).toISOString() for consistency + echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> ${SERVICEDOCK_LOG} +end script + +pre-stop script + SERVICEDOCK_LOG="/var/log/servicedock.log" + [ -r /etc/default/servicedock ] && . /etc/default/servicedock + rm /var/run/servicedock.pid + echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> ${SERVICEDOCK_LOG} +end script diff --git a/nodejs/etc/servicedock.json b/nodejs/etc/servicedock.json index 5427224..078d6c0 100644 --- a/nodejs/etc/servicedock.json +++ b/nodejs/etc/servicedock.json @@ -1,3 +1,3 @@ { - "port": 8889 + "port": 8888 } diff --git a/nodejs/makefile.am b/nodejs/makefile.am index 062536e..c121139 100644 --- a/nodejs/makefile.am +++ b/nodejs/makefile.am @@ -8,7 +8,11 @@ EXTRA_DIST = servicedock.js package.json.in public routes sockets docker views nodejsdir = ${pkgdatadir}/nodejs -sysconf_DATA = etc/@PACKAGE_NAME@.json +sysconfdefaultdir = ${sysconfdir}/default +sysconfinitdir = ${sysconfdir}/init +dist_sysconf_DATA = etc/@PACKAGE_NAME@.json +dist_sysconfdefault_DATA = etc/default/servicedock +dist_sysconfinit_DATA = etc/init/servicedock.conf all: node_modules diff --git a/nodejs/servicedock.js b/nodejs/servicedock.js index 50881bf..c7953d8 100644 --- a/nodejs/servicedock.js +++ b/nodejs/servicedock.js @@ -14,6 +14,18 @@ var config = require(package.path.config); var docker = require(__dirname+'/docker')(app); // Configuration +process.argv.forEach(function(val, index) { + if (index<2) {return} + if (index!=2 || typeof val != 'number') { + console.log("**** ERROR: Unexpected Argument - allowed is only a port number"); + process.exit(1); + } + config.port = val; +}); +if (typeof config.port != 'number') { + console.log("**** WARNING: no valid port given, defaults to 8888"); + config.port = 8888; +} app.configure(function(){ app.set('views', __dirname + '/views');