How to auto restart a crashed app?

594

Open your terminal and type as

gedit autostart.sh

then paste this code as it as

#!/bin/bash

while true
do
if [ ! `pgrep docky` ] ; then
/usr/bin/autorestart1.sh
fi
sleep 30
done

save it & close.

Then again in the terminal type as

sudo gedit /usr/bin/autostart1.sh

and paste

cd /usr/bin/
docky

save & close.

thats it now onwards. your application will be autostart after the crash,:)

Credit goes to Ubuntuforums

Share:
594

Related videos on Youtube

ottercoder
Author by

ottercoder

Updated on September 18, 2022

Comments

  • ottercoder
    ottercoder over 1 year

    I'm trying to implement Angular Interceptor for Exceptions. For one at least. I have a token and when it old enogh backend throws TokenAlmostExpired exception. This exception contains errorCode = 101. In the interceptor I'm checking that code is 101 and then I need to send POST request to backend's /refresh endpoint so I could refresh token.

    .factory('errorInjector',['$injector', function ($q, $injector) {
    
        var vm = this;
    
        var errorInjector = {
            'response': function (response) {
                console.log(response);
                return response;
            },
            'responseError': function (rejection) {
                if (JSON.stringify(rejection.data.errorCode) === JSON.stringify(101)) {
                    vm.getRefreshToken();
                }
                return $q.reject(rejection);
            }
        };
        return errorInjector;
    }]);
    

    and

    .config(['$httpProvider', function ($httpProvider) {
            $httpProvider.interceptors.push('errorInjector');
        }]);
    

    $http

    But there's a problem at interceptor level, that I can't just give it dependency on $http, because there's Circular dependency found: $http <- errorInjector <- $http <- $templateFactory <- $view <- $state

    $scope

    And I can't put getRefreshToken() function to $scope, because $scope dependency also gives 'Circular dependency'.

    $Injector

    var http = $injector.get('$http');
    

    doesn't work as well, and gives me erorr.

    So how can I catch exception in interceptor and then do a $http request from there?

    • Callum Linington
      Callum Linington almost 8 years
      You may want to consider firing off an event, and picking it up in a service and doing the execution from there
    • Callum Linington
      Callum Linington almost 8 years
      Don't use rootscope, create your own event aggregator...
    • el vis
      el vis almost 8 years
      Can you show full errorInjector code? It seems that it is not full implementation.
    • Callum Linington
      Callum Linington almost 8 years
      We don't need full errorInjector code, there is enough there
    • el vis
      el vis almost 8 years
      I do not think so. It has $injector injected that should be used to avoid circural dependency .
    • Callum Linington
      Callum Linington almost 8 years
      Using $injector is a code smell to me
    • Callum Linington
      Callum Linington almost 8 years
      Here is an event aggregator pattern implementation if you want a full on example with your code just ask
    • ottercoder
      ottercoder almost 8 years
      @CallumLinington I've never done anything with event, so I'd really like to get some help on that, thanks. As long as I understand it supposed to be easy .broadcast("something), .subscribe('something), right?
    • Callum Linington
      Callum Linington almost 8 years
      Yeah, if you look at my plnker it should be fairly obvious to what is going on
    • ottercoder
      ottercoder almost 8 years
      @CallumLinington, not really there's a lot of letters that I don't get. What is "t" and "ev", for instance?
    • el vis
      el vis almost 8 years
      @ottercoder if you do not understand @CallumLinington code it seems that you do not understant DI in angular, thats why you have '$injector', function ($q, $injector) which should be '$q', '$injector', function ($q, $injector) and thats probably your problem here
    • Callum Linington
      Callum Linington almost 8 years
      Yeah, would agree with @pawlakppp on this
    • ottercoder
      ottercoder almost 8 years
      If I'd understand Angular completely, I would'nt need a help at all. But I've found a solution. I'm putting function from service to $rootScope and calling it as a promise. $q.get('$rootScope').vmRT.getRefreshToken();
  • Blaine
    Blaine about 8 years
    how can I implement this to function the same way if a user quits the application? And is "autostart1.sh" supposed to be named "autorestart1.sh" as per previous file?
  • ottercoder
    ottercoder almost 8 years
    Circular dependency found: $http <- errorLauncher <- httpInterseptor <- $http <- $templateFactory <- $view <- $state :/
  • Alexandr Fedoseev
    Alexandr Fedoseev almost 8 years
    try the $emit from error handler then ) hope it will help