Michele Bini avatar Michele Bini committed ceecd98

Add init.d script.

Comments (0)

Files changed (5)

 * Add init.d service for timekoin
 * Add an installation-time query to the user on whether to add the timekoin Alias.
-* Remove non-commercial material (icon) (DONE)
 * Add manpage generate-timekoin-keys.
 * Peers appear twice on the peer list sometimes
+timekoin (1.9-deb41) unstable; urgency=low
+
+  * Add init.d script.
+
+ -- Michele Bini <michele.bini@gmail.com>  Fri, 21 Sep 2012 14:11:32 +0200
+
 timekoin (1.9-deb40) unstable; urgency=low
 
   * Fix watchdog start.
 
 Package: timekoin
 Architecture: all
-Depends: dbconfig-common, php5, php5-cli, apache2|httpd, php5-mysql, mysql-client, mysql-server
+Depends: dbconfig-common, php5, php5-cli, apache2|httpd, php5-mysql, mysql-client, mysql-server, uuid
 Description: peer-to-peer cryptocurrency
  Open-source peer-to-peer based crypto-currency system.

debian/init.d/timekoin

+#! /bin/sh
+
+### BEGIN INIT INFO
+# Provides:          timekoin
+# Required-Start:    $local_fs $remote_fs $named $network $time mysql
+# Required-Stop:     $local_fs $remote_fs $named $network $time mysql
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: timekoin cryptocurrency
+# Description:       timekoin is a peer-to-peer cryptocurrency system
+### END INIT INFO
+
+set -e
+
+test -x /usr/share/timekoin/ || exit 0
+
+. /lib/lsb/init-functions
+
+LANG=C
+export LANG
+
+PIDFILE="/var/run/timekoin.pid"
+
+NAME="timekoin"
+
+stop_timekoin() {
+    log_daemon_msg "Stopping TimeKoin"
+    start-stop-daemon --stop --pidfile "$PIDFILE" --quiet --oknodo
+    status=$?
+    if [ x"$status" = x"0" ]; then
+	cd /usr/share/timekoin/public/
+	echo "<?PHP
+include 'configuration.php';
+include 'function.php';
+
+if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD)  == FALSE) { exit; }
+if (mysql_select_db(MYSQL_DATABASE) 			   == FALSE) { exit; }
+
+mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '0' WHERE \`main_loop_status\`.\`field_name\` = 'main_heartbeat_active' LIMIT 1\");
+
+// Clear transaction queue to avoid unnecessary peer confusion
+mysql_query(\"TRUNCATE TABLE \`transaction_queue\`\");
+?>" |su www-data -c php
+    fi
+
+    rm -f $PIDFILE
+    log_end_msg $?
+}
+
+start_timekoin() {
+    log_daemon_msg "Starting TimeKoin"
+
+    cd /usr/share/timekoin/public/
+    echo "<?PHP
+include 'configuration.php';
+include 'function.php';
+
+if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD)  == FALSE) { exit; }
+if (mysql_select_db(MYSQL_DATABASE) 			   == FALSE) { exit; }
+
+// Database Initialization
+initialization_database();
+
+mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '\" . time() . \"' WHERE \`main_loop_status\`.\`field_name\` = 'main_last_heartbeat' LIMIT 1\");
+
+// Set loop at active now
+mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '1' WHERE \`main_loop_status\`.\`field_name\` = 'main_heartbeat_active' LIMIT 1\"); ?>" |su www-data -c php
+
+    # Enable the main process
+    f=/var/lib/timekoin/status.php.$(uuid)
+    sed "s/defined* *[(][^)A-Za-z]TIMEKOIN_DISABLED[^)]*[)];/define(\"TIMEKOIN_DISABLED\", \"0\");/" </var/lib/timekoin/status.php >"$f"
+    mv "$f" /var/lib/timekoin/status.php
+
+    start-stop-daemon --chdir /usr/share/timekoin/public --start --chuid www-data --make-pidfile --pidfile "$PIDFILE" --nicelevel 2 --oknodo --background --startas /usr/bin/php -- main.php
+    status=$?
+
+    log_end_msg $?
+}
+
+case "$1" in
+    start)  start_timekoin  ;;
+    stop)   stop_timekoin   ;;
+    restart|force-reload)
+	stop_timekoin
+	start_timekoin
+	;;
+    status)
+	start-stop-daemon --status --pidfile "$PIDFILE" --quiet
+	;;
+  *)
+    echo "Usage: $0 {start|stop|restart|force-reload|status}"
+    exit 1
+    ;;
+esac
+
+exit 0
-debian/apache.conf etc/timekoin
+debian/init.d/timekoin etc/init.d/
+debian/apache.conf etc/timekoin/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.