diff --git a/lamassu-admin-elm/src/MaintenanceMachines/Rest.elm b/lamassu-admin-elm/src/MaintenanceMachines/Rest.elm index d009dae2..8b591ab1 100644 --- a/lamassu-admin-elm/src/MaintenanceMachines/Rest.elm +++ b/lamassu-admin-elm/src/MaintenanceMachines/Rest.elm @@ -71,3 +71,9 @@ encodeAction action = [ ( "action", E.string "reboot" ) , ( "deviceId", E.string machine.deviceId ) ] + + RestartServices machine -> + E.object + [ ( "action", E.string "restartServices" ) + , ( "deviceId", E.string machine.deviceId ) + ] diff --git a/lamassu-admin-elm/src/MaintenanceMachines/Types.elm b/lamassu-admin-elm/src/MaintenanceMachines/Types.elm index 850ee243..b603b080 100644 --- a/lamassu-admin-elm/src/MaintenanceMachines/Types.elm +++ b/lamassu-admin-elm/src/MaintenanceMachines/Types.elm @@ -33,6 +33,7 @@ type MachineAction = ResetCashOutBills Machine | UnpairMachine Machine | RebootMachine Machine + | RestartServices Machine type Msg diff --git a/lamassu-admin-elm/src/MaintenanceMachines/View.elm b/lamassu-admin-elm/src/MaintenanceMachines/View.elm index 5403aa2f..58df009b 100644 --- a/lamassu-admin-elm/src/MaintenanceMachines/View.elm +++ b/lamassu-admin-elm/src/MaintenanceMachines/View.elm @@ -36,7 +36,9 @@ rowView machine = [ td [] [ button [ class [ C.TableButton ], onClick (Submit (UnpairMachine machine)) ] [ text "Unpair" ] ] , td [] - [ button [ class [ C.TableButton ], onClick (Submit (RebootMachine machine)) ] [ text "Reboot" ] ] + [ button [ class [ C.TableButton ], onClick (Submit (RebootMachine machine)) ] [ text "Reboot OS" ] ] + , td [] + [ button [ class [ C.TableButton ], onClick (Submit (RestartServices machine)) ] [ text "Restart Services" ] ] , resetBills ] diff --git a/lib/machine-loader.js b/lib/machine-loader.js index fab5c890..feee274f 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -71,11 +71,16 @@ function reboot (rec) { return axios.post(`http://localhost:3030/reboot?device_id=${rec.deviceId}`) } +function restartServices (rec) { + return axios.post(`http://localhost:3030/restartServices?device_id=${rec.deviceId}`) +} + function setMachine (rec) { switch (rec.action) { case 'resetCashOutBills': return resetCashOutBills(rec) case 'unpair': return unpair(rec) case 'reboot': return reboot(rec) + case 'restartServices': return restartServices(rec) default: throw new Error('No such action: ' + rec.action) } } diff --git a/lib/routes.js b/lib/routes.js index a9ec1b06..8fc0b188 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -29,6 +29,7 @@ const REQUEST_TTL = 3 * 60 * 1000 const pids = {} const reboots = {} +const restartServicesMap = {} const devMode = argv.dev || options.http @@ -53,6 +54,7 @@ function poll (req, res, next) { const cassettes = results.cassettes const reboot = pid && reboots[deviceId] && reboots[deviceId] === pid + const restartServices = pid && restartServicesMap[deviceId] && restartServicesMap[deviceId] === pid const langs = config.machineLanguages const locale = { @@ -90,6 +92,7 @@ function poll (req, res, next) { twoWayMode: config.cashOutEnabled, zeroConfLimit: config.zeroConfLimit, reboot, + restartServices, hasLightning, operatorInfo: { active: config.operatorInfoActive, @@ -399,6 +402,18 @@ localApp.post('/reboot', (req, res) => { res.sendStatus(200) }) +localApp.post('/restartServices', (req, res) => { + const deviceId = req.query.device_id + const pid = pids[deviceId] && pids[deviceId].pid + + if (!deviceId || !pid) { + return res.sendStatus(400) + } + + restartServicesMap[deviceId] = pid + res.sendStatus(200) +}) + localApp.post('/dbChange', (req, res, next) => { return settingsLoader.loadLatest() .then(poller.reload) diff --git a/public/elm.js b/public/elm.js index fc536c7a..b72e70ec 100644 --- a/public/elm.js +++ b/public/elm.js @@ -33858,6 +33858,9 @@ var _user$project$MaintenanceMachines_Types$Machine = F7( function (a, b, c, d, e, f, g) { return {deviceId: a, name: b, cashbox: c, cassette1: d, cassette2: e, paired: f, cashOut: g}; }); +var _user$project$MaintenanceMachines_Types$RestartServices = function (a) { + return {ctor: 'RestartServices', _0: a}; +}; var _user$project$MaintenanceMachines_Types$RebootMachine = function (a) { return {ctor: 'RebootMachine', _0: a}; }; @@ -38033,7 +38036,7 @@ var _user$project$MaintenanceMachines_Rest$encodeAction = function (action) { _1: {ctor: '[]'} } }); - default: + case 'RebootMachine': return _elm_lang$core$Json_Encode$object( { ctor: '::', @@ -38052,6 +38055,25 @@ var _user$project$MaintenanceMachines_Rest$encodeAction = function (action) { _1: {ctor: '[]'} } }); + default: + return _elm_lang$core$Json_Encode$object( + { + ctor: '::', + _0: { + ctor: '_Tuple2', + _0: 'action', + _1: _elm_lang$core$Json_Encode$string('restartServices') + }, + _1: { + ctor: '::', + _0: { + ctor: '_Tuple2', + _0: 'deviceId', + _1: _elm_lang$core$Json_Encode$string(_p0._0.deviceId) + }, + _1: {ctor: '[]'} + } + }); } }; var _user$project$MaintenanceMachines_Rest$machineDecoder = A8( @@ -38428,15 +38450,48 @@ var _user$project$MaintenanceMachines_View$rowView = function (machine) { }, { ctor: '::', - _0: _elm_lang$html$Html$text('Reboot'), + _0: _elm_lang$html$Html$text('Reboot OS'), _1: {ctor: '[]'} }), _1: {ctor: '[]'} }), _1: { ctor: '::', - _0: resetBills, - _1: {ctor: '[]'} + _0: A2( + _elm_lang$html$Html$td, + {ctor: '[]'}, + { + ctor: '::', + _0: A2( + _elm_lang$html$Html$button, + { + ctor: '::', + _0: _user$project$Css_Admin$class( + { + ctor: '::', + _0: _user$project$Css_Classes$TableButton, + _1: {ctor: '[]'} + }), + _1: { + ctor: '::', + _0: _elm_lang$html$Html_Events$onClick( + _user$project$MaintenanceMachines_Types$Submit( + _user$project$MaintenanceMachines_Types$RestartServices(machine))), + _1: {ctor: '[]'} + } + }, + { + ctor: '::', + _0: _elm_lang$html$Html$text('Restart Services'), + _1: {ctor: '[]'} + }), + _1: {ctor: '[]'} + }), + _1: { + ctor: '::', + _0: resetBills, + _1: {ctor: '[]'} + } } } };