Commit 5a3a3a84 authored by Franco Fichtner's avatar Franco Fichtner

firmware: add running API action and reattach if possible; closes #646

parent 2e10248c
...@@ -316,6 +316,19 @@ class FirmwareController extends ApiControllerBase ...@@ -316,6 +316,19 @@ class FirmwareController extends ApiControllerBase
return $response; return $response;
} }
/**
* retrieve exectution status
*/
public function runningAction()
{
$backend = new Backend();
$result = array(
'status' => trim($backend->configdRun('firmware running'))
);
return $result;
}
/** /**
* retrieve upgrade status (and log file of current process) * retrieve upgrade status (and log file of current process)
*/ */
......
...@@ -85,7 +85,8 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -85,7 +85,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
function upgrade(){ function upgrade(){
$('#progresstab > a').tab('show'); $('#progresstab > a').tab('show');
$('#updatestatus').html("{{ lang._('Upgrading... (do not leave this page while upgrade is in progress)') }}"); $('#updatestatus').html("{{ lang._('Upgrading...') }}");
$("#upgrade").attr("style","");
$("#upgrade_progress").addClass("fa fa-spinner fa-pulse"); $("#upgrade_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall('/api/core/firmware/upgrade',{upgrade:$.upgrade_action},function() { ajaxCall('/api/core/firmware/upgrade',{upgrade:$.upgrade_action},function() {
...@@ -102,7 +103,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -102,7 +103,7 @@ POSSIBILITY OF SUCH DAMAGE.
function action(pkg_act, pkg_name) function action(pkg_act, pkg_name)
{ {
$('#progresstab > a').tab('show'); $('#progresstab > a').tab('show');
$('#updatestatus').html("{{ lang._('Executing... (do not leave this page while execute is in progress)') }}"); $('#updatestatus').html("{{ lang._('Executing...') }}");
ajaxCall('/api/core/firmware/'+pkg_act+'/'+pkg_name,{},function() { ajaxCall('/api/core/firmware/'+pkg_act+'/'+pkg_name,{},function() {
$('#updatelist').empty(); $('#updatelist').empty();
...@@ -136,7 +137,6 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -136,7 +137,6 @@ POSSIBILITY OF SUCH DAMAGE.
}] }]
}); });
} else { } else {
upgrade(); upgrade();
} }
...@@ -178,7 +178,7 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -178,7 +178,7 @@ POSSIBILITY OF SUCH DAMAGE.
"{{ lang._('The upgrade has finished and your device is being rebooted at the moment, please wait...') }}" + "{{ lang._('The upgrade has finished and your device is being rebooted at the moment, please wait...') }}" +
' <i class="fa fa-cog fa-spin"></i>' ' <i class="fa fa-cog fa-spin"></i>'
); );
setTimeout(rebootWait, 30000); setTimeout(rebootWait, 45000);
}, },
}); });
} else { } else {
...@@ -292,14 +292,20 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -292,14 +292,20 @@ POSSIBILITY OF SUCH DAMAGE.
if ($('#message').html() != '') { if ($('#message').html() != '') {
$('#message').attr('style', ''); $('#message').attr('style', '');
} }
// repopulate package information // repopulate package information
packagesInfo(); packagesInfo();
ajaxGet('/api/core/firmware/running',{},function(data, status) {
// if action is already running reattach now...
if (data['status'] == 'busy') {
upgrade();
// dashboard link: run check automatically // dashboard link: run check automatically
if (window.location.hash == '#checkupdate') { } else if (window.location.hash == '#checkupdate') {
updateStatus(); updateStatus();
} }
}); });
});
</script> </script>
<div class="container-fluid"> <div class="container-fluid">
......
#!/bin/sh
# Copyright (C) 2016 Franco Fichtner <franco@opnsense.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
LOCKFILE="/tmp/pkg_upgrade.progress"
FLOCK="/usr/local/bin/flock -n"
(
if ${FLOCK} 9; then
echo "ready"
else
echo "busy"
fi
) 9< ${LOCKFILE}
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
command:/usr/local/opnsense/scripts/firmware/check.sh command:/usr/local/opnsense/scripts/firmware/check.sh
parameters: parameters:
type:script_output type:script_output
message:retrieve package status message:retrieve firmware update status
[running]
command:/usr/local/opnsense/scripts/firmware/running.sh
parameters:
type:script_output
message:retrieve firmware execution status
[upgrade] [upgrade]
command: /usr/sbin/daemon -f /usr/local/opnsense/scripts/firmware/launcher.sh upgrade command: /usr/sbin/daemon -f /usr/local/opnsense/scripts/firmware/launcher.sh upgrade
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment