diff --git a/html/svc/bu_cmdr.service b/html/svc/bu_cmdr.service
new file mode 100644
index 0000000..ce063af
--- /dev/null
+++ b/html/svc/bu_cmdr.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=PHP Middleware For Websites
+After=apache2.service
+Documentation=http://pearcey.net:8080/johnpearcey/backup-commander
+
+[Service]
+Type=simple
+WorkingDirectory=/var/www/backup-commander/html/svc
+ExecStart=php /var/www/backup-commander/html/svc/main.php
+ExecStop=php /var/www/backup-commander/html/svc/main.php stop
+ExecReload=php /var/www/backup-commander/html/svc/main.php reload
+
+[Install]
+WantedBy=multi-user.target
diff --git a/html/svc/main-svc.php b/html/svc/main-svc.php
new file mode 100644
index 0000000..7c48561
--- /dev/null
+++ b/html/svc/main-svc.php
@@ -0,0 +1,11 @@
+
diff --git a/html/svc/main.php b/html/svc/main.php
index c28654c..1065fe0 100644
--- a/html/svc/main.php
+++ b/html/svc/main.php
@@ -1,5 +1,32 @@
/dev/null 2>>/root/logs/sys-update.log
+
+//$argv[0] is always the name that was used to run the script.
+if(count($argv)>1){
+
+ include __DIR__."/main-svc.php";
+
+ if($argv[1]==='stop'){
+ $rtn = run_main_command( 'f:cli-stop' );
+ print_r( $rtn );
+ exit(0);
+ }
+
+ if($argv[1]==='reload'){
+ $rtn = run_main_command( 'f:cli-reload' );
+ print_r( $rtn );
+ exit(0);
+ }
+
+ $rtn = run_main_command( $argv[1] );
+ print_r( $rtn );
+ exit(0);
+
+}
+
+$g_shutdown = false;
+
/*
* This is the backup process CLI application.
*
@@ -47,6 +74,11 @@
while(true){
+ if($g_shutdown){
+ print("CLI request to shutdown: googbye!\n");
+ exit(0);
+ }
+
$bDidWork = false;
$bDidWork |= check_rpc_clients();
@@ -291,7 +323,8 @@
// where it is a simple function call, i.e. 'f:' (provided it is a trusted source and/or has been previously checked)
global $g_data_dir;
-
+ global $g_shutdown;
+
if( 'f:getbu_list_state' !== $obj[0] ){
print_r( $obj );
}
@@ -362,10 +395,13 @@
clear_cached_data();
return array($err);
- /*case 'f:set_sched_date':
- $err = set_sched_date_db( $obj[1], $obj[2] );
+ case 'f:cli-reload':
clear_cached_data();
- return array($err);*/
+ return array('ok:reload');
+
+ case 'f:cli-stop':
+ $g_shutdown = true;
+ return array('ok:shutdown');
case 'f:delete_bu_item':
//[$err] = rpc( 'f:delete_bu_item', $buid );
diff --git a/notes.txt b/notes.txt
index acf63a7..5ee3f2b 100644
--- a/notes.txt
+++ b/notes.txt
@@ -1,3 +1,24 @@
-Testing Rqd
------------
+Service
+-------
+ After placing the service at
+ /usr/lib/systemd/system/bu_cmdr.service
+ refresh the daemon:
+ systemctl daemon-reload
+
+ Start the service
+ systemctl start bu_cmdr.service
+
+ Stop the service
+ systemctl stop bu_cmdr.service
+
+ Print the logs (f follow)
+ journalctl -fu bu_cmdr.service
+
+ To start the service at boot time, place the service file (or symlink) in:
+ cd /etc/systemd/system/
+ ln -s /usr/lib/systemd/system/bu_cmdr.service
+
+ then enable it
+ systemctl enable bu_cmdr.service
+