Jump to content

Serendesk

Members
  • Posts

    22
  • Joined

  • Last visited

  • Days Won

    2

Reputation Activity

  1. Like
    Serendesk reacted to Paul in Forum Upgrade   
    Thanks, much appreciated! Now we just need to get v4 beta out to ya, and that'll round things out nicely.  
  2. Like
    Serendesk got a reaction from Michael in Forum Upgrade   
    Great work. Navigation and notifications are much better.
  3. Like
    Serendesk reacted to Paul in Release 3.6.2 (Security Advisory)   
    Version 3.6.2 is now available. More information on this advisory and direct download links can be found at http://www.blesta.com/2016/08/02/security-advisory/
     
  4. Like
    Serendesk got a reaction from jobplease in Validating A Service Field As Unique   
    Hi all,
     
    Just sharing an approach that can be used in a custom module to check whether a service field value is unique or already in use (e.g. to enforce unique domain names).
    public function validateService($package, array $vars=null, $edit=false) { if ($package) $module_row_id = $package->module_row; else $module_row_id = isset($vars['module_row']) ? $vars['module_row'] : null; $row = $this->getModuleRow($module_row_id); //get the service id using a known and guaranteed unique field. this is needed to perform a unique validation of service fields without having the same service that may already have the field to cause validation to fail (e.g. when activating a pending service). $service_id = $this->getServiceIDUsingUniqueServiceField('myUniqueServiceUID', $params['myUniqueServiceUID']); $rules = array( 'domain' => array( 'unique' => array( 'final' => true, 'rule' => array(array($this, "checkUniqueDomain"), $service_id), 'negate' => true, 'message' => Language::_("ModuleName.!error.domain_valid.unique", true) ) ) ); $this->Input->setRules($rules); return $this->Input->validates($params); } // check any service field value exists private function checkServiceFieldValueExists($key, $value, $service_id = null) { Loader::loadComponents($this, array("Record")); $exists = false; if (is_null($service_id)) { $service_id = -1; } $this->Record->select() ->from("service_fields") ->where("service_fields.key", "=", $key) ->where("service_fields.value", "=", $value) ->where("service_fields.service_id", "!=", $service_id); if($this->Record->numResults() > 0) { $exists = true; } $this->Record->reset(); return $exists; } // check domain is unique public function checkUniqueDomain($value, $service_id = null) { return $this->checkServiceFieldValueExists('domain', $value, $service_id); }
  5. Like
    Serendesk reacted to Tyson in Checkout & Pay 404 Error   
    I suspect that issue is a bug that can be resolved as I mentioned in post 14. A condition of duplicating the issue is that you must encounter an error such as not filling out all required fields. We're tracking this as CORE-1937.
  6. Like
    Serendesk reacted to bobs@sectorlink in Where Is The Controller File For Client_Services_Review.pdt?   
    I figured it out...
     
     /var/www/blesta/app/controllers/client_services.php in the method: review
     
    I added  $this->set("client", $this->client); and now it works.
  7. Like
    Serendesk reacted to Michael in Ability To Move A Service From One Client To Another   
    You can move services via the services table search the client ID (ID in the url) and then change the client ID on the service ID you wish to move.
  8. Like
    Serendesk reacted to Michael in Fraud Record   
    Fraud Record, for Blesta would be amazing in my opinion, it checks a database for unwanted customers, it's a bit like a neighbourhood watch team, but for webhosting.
     
    Any fraud gets submitted to the database, and you can check to ensure you don't get the same unwanted customers.
     
     Stop Fraud Clients, Report Abusive Customers. Combine your efforts to fight misbehaving clients.
     
    I used to use it on the last billing system I used and it helped much better than Maxmind, because bad clients are bad clients.
     
    http://www.fraudrecord.com/
     
     
    API: http://www.fraudrecord.com/developers.php
  9. Like
    Serendesk reacted to smicroz in Nginx And Blesta   
    Hi,
     
    Finally I can be solved adding in directadmin cp, in custom hosts
    if (!-e $request_filename){ rewrite ^(.*)$ /index.php; } #Core rewrite location @blesta { rewrite ^(.*)$/index.php/(.*) /$1 permanent; } Thanks!!
  10. Like
    Serendesk reacted to Rodrigo in Analysing Blesta Database (Useful Mysql Queries)   
    When you have a blesta setup with relatively high client volume, you may want to periodically check if everything is OK, or clean up things that should not be there (i.e: data that is not automatically removed by blesta/plugins).
     
    I've come up to this queries which I use periodically:
     
    - Show users that have at least 1 active service and more than 3 unpaid invoices: This may happen when a provision plugin is not suspending a service, or just human mistake (useful to find customers that are not paying because of not having their services suspended)
    SELECT many_invoices_customers.id 'customer_id', services.id_value 'service_id' from (SELECT i.client_id 'id',  count(*) 'c' FROM invoices i, clients c WHERE c.id = i.client_id AND i.status != 'void' and i.paid != i.total  GROUP BY i.client_id HAVING c > 3) many_invoices_customers, services WHERE services.client_id = many_invoices_customers.id AND services.status = 'active'; - Show users that have more than 3 unpaid invoices and at least 1 suspended service: let's you clean up users that don't pay anymore (and manually cancel them)
    SELECT many_invoices_customers.id 'customer_id', services.id_value 'service_id', many_invoices_customers.c 'invoices_number' from (SELECT i.client_id 'id',  count(*) 'c' FROM invoices i, clients c WHERE c.id = i.client_id AND i.status != 'void' and i.paid != i.total  GROUP BY i.client_id HAVING c > 3) many_invoices_customers, services WHERE services.client_id = many_invoices_customers.id AND services.status = 'suspended' ORDER BY many_invoices_customers.c DESC; I haven't implemented auto service cancel yet, but maybe is useful to someone here
     
    *Those queries are meant to be executed directly into your blesta MySQL DB.
  11. Like
    Serendesk reacted to Michael in Nginx And Blesta   
    I recommend you follow: http://www.blesta.com/forums/index.php?/topic/2769-blesta-nginx-the-easy-way-tutorial/
  12. Like
    Serendesk reacted to Abdy in [Plugin] Mass Mailer   
    Simple, Send a email to all your clients, Perfect for send Newsletters or Announcements.
     
    Available in Github: https://github.com/CyanDarkInc/Mass-Mailer
     
    Mini-Update: Language Filter added. you can send mass mails only to Language-Specific users.

  13. Like
    Serendesk reacted to Michael in [Theme] Free Flat Integration   
    Flat Theme Integration
    Integrated to Blesta by Licensecart
     
    Here's our first free integration for Blesta, it was integrated to on 3.5 at the moment.
    You can try it on 3.4 if you wish by editing config.json in the theme.
     
    You can get the full site theme for free from:
    https://shapebootstrap.net/item/1524965-flat-theme-free-responsive-multipurpose-site-template
     
    You can get the Blesta integration for free from:
    https://licensecart.com/customers/plugin/download_manager/client_main/index/46/
     
    Previews:

     
    Logged in Preview:

     
    Upload the flat folder to: /app/views/client/
     
    Go to: Settings > Company > Look and Feel > Templates > Flat (from dropdown menu).
  14. Like
    Serendesk reacted to PauloV in [Plugin] Blesta Live Chat Rc 1.0.7 - 4ºrc   
    (Updated 14-04-2015)
     
     
    Hello to all blestars
     
    Here it is the Third Release Candidate for Blesta Live Chat 1.0.7
     
     
    Here it is the "Biggest" update ever made for "Blesta Live Chat" Plugin with a new clean design (I will try to update screenshots next week)    Atention: To use this you have to uninstall your old "Blesta Live Chat" Plugin, and install this one. Unfortunately this cannot be "Auto Update" because I have made an huge modification and also add the Lastest, most stable "livehelperchat" from github (https://github.com/LiveHelperChat/)   This version brings a LOT of new features and Im going to trie not forget all posting it here   Added: - Live Help Widget Auto detect Language on Client Area (also wen client are not loged in it detects the language) - Live Help Widget Auto detect Name and Email wen client logins to Client Area Fixed: - Fixed quotes in name problem. (bug found by a.daniello)   Added: 10 auto languages detect on Admin/Staff Chat Box (thanks to a.daniello) Fix: Security issue on Chat Box displayin outside Admin/Staff login session (thanks to a.daniello) Added: See what user see with screenshot feature, Co-Browsing/Screen sharing (See in real time what your user sees on screen) (needs nodejs installed on server to fully support) Speech to text (now supporting your your voice conversion to text) Files upload Chat search Option to add custom form fields. It can be either user variables or hidden fields. Usefull if you are integrating with third party system and want to pass user_id for example. Cronjobs Callbacks Closed chat callback Unanswered chat callback Asynchronous status loading, not blocking site javascript. XML, JSON export module GEO detection using three different sources Option to configure start chat fields Browser title blinking then there is pending message. Option to limit pro active chat invitation messages based on pending chats. Option to configure frequency for pro active chat invitation message. You can set after how many hours for the same user invitation message should be shown again. Users blocking Top performance with enabled cache Option to send messges to anonymous site visitors, Voting module FAQ module Online users map Pro active chat invitatio Total pageviews tracking Total pageviews including previous visits tracking Visits tracking, how many times user has been on your page. Auto responder BB Code support. Links recognition. Smiles and few other hidden features First user visit tracking Option to have different pro active messages for different domains. This can be archieved using different identifiers. Protection against spammers using advanced captcha technique without requiring users to enter any captcha code. Flexible permission system, Roles,GroupsUsers Tablet and Mobile friendly And here is the complete list what Blesta Live Chat can do right now   Auto install and preconfigure an Admin/Staff Chat (Staff and Admin can chat with each outher online securelly). Vew in real time (5 seconds delay), all online users, and see what are they doing. Auto install and add Blesta Live Chat Widget on your Blesta Order Froms and Client Area. Blesta Live Chat can do: See what user see with screenshot feature, Co-Browsing/Screen sharing (See in real time what your user sees on screen) (needs nodejs installed on server to fully support) Speech to text (now supporting your your voice conversion to text) XMPP support for notifications about new chats. (IPhone, IPad, Android, Blackberry, GTalk etc...) Chrome extension Repeatable sound notifications Work hours See what user see with screenshot feature Drag & Drop widgets, minimize/maximize widgets Multiple chats same time See what users are typing before they send a message Multiple operators Send delayed canned messages as it was real user typing Chats archive Priority queue Chats statistic generation, top chats Resume chat after user closed chat All chats in single window with tabs interface, tabs are remembered before they are closed Chat transcript print Chat transcript send by mail Site widget Page embed mode for live support script or widget mode, or standard mode. Multilanguage Chats transfering Departments Files upload Chat search Automatic transfers between departments Option to generate JS for different departments Option to prefill form fields. Option to add custom form fields. It can be either user variables or hidden fields. Usefull if you are integrating with third party system and want to pass user_id for example. Cronjobs Callbacks Closed chat callback Unanswered chat callback Asynchronous status loading, not blocking site javascript. XML, JSON export module Option to send transcript to users e-mail SMTP support HTTPS support No third parties cookies dependency Previous users chats Online users tracking, including geo detection GEO detection using three different sources Option to configure start chat fields Sounds on pending chats and new messages Google chrome notifications on pending messages. Browser title blinking then there is pending message. Option to limit pro active chat invitation messages based on pending chats. Option to configure frequency for pro active chat invitation message. You can set after how many hours for the same user invitation message should be shown again. Users blocking Top performance with enabled cache Windows, Linux and Mac native applications. Advanced embed code generation with numerous options of includable code. Template override system Module override system Support for custom extensions Changeable footer and header content Option to send messges to anonymous site visitors, Canned messages Informing then operator or user is typing. Option to see what user is typing before he sends a message Canned messages for desktop client Voting module FAQ module Online users map Pro active chat invitatio Remember me functionality Total pageviews tracking Total pageviews including previous visits tracking Visits tracking, how many times user has been on your page. Time spent on site Auto responder BB Code support. Links recognition. Smiles and few other hidden features First user visit tracking Option for customers mute sounds Option for operators mute messages sounds and new pending chat's sound. Option to monitor online operators. Option to have different pro active messages for different domains. This can be archieved using different identifiers. Dekstop client supports HTTPS Protection against spammers using advanced captcha technique without requiring users to enter any captcha code. Option for operator set online or offline mode. Desktop client for, Windows, Linux, Mac (you can download here https://livehelperchat.com/article/static/5) Flexible permission system, Roles, Groups, Users Tablet and Mobile friendly older fixes:
     
    Here it is the Second Release Candidate for Blesta Live Chat 1.0.4
    (you can install/upgrade on 3.1.X or 3.2.X, you will not loose any configurations)
    Fix: Minor bug detected wen insert javascript with <?include();?> insted of <?php include();?> Added: Shadows to Count Badge like Facebook Badge. Fix: Fixed problem that only afected Firefox and Opera browsers, not displaying Blesta Stats or Blesta Live Chat on the Menu. Fix: Fixed problem that online visitores/chat sessions where still showing on Admin Menu Count Badge. Now it only shows the latest 10 minuts users based on latest activity on site. For this to work you have to be "Online" on "Live Chat" as Staff. Fix: Optimized code to fetch some dinamic paths that could cause errors wen changing Admin or Client Routes. Fix: Now on uninstall/install/upgrade it detects all Admin and Client new Themes and removes/add the code to show the Chat Box Add: Support for Blesta 3.2 new and future themes. Add: Count Menu Badge reformulated to the same as Blesta uses. Add: Now the Count Badge will only show if there is 1 or more users online browsing or chatting. We have changed the badge color to RED to alert and be more visible to staff members. Add: Added PayPal donation link to the Plugin in "Settings->Plugins->Blesta Live Chat". How to Upgrade (if you have alredy installed) (Note: only for 1.0.6 or above):   1º- Download the Blesta Live Chat Plugin here: Download Here (updated 14-04-2015) 2º- Uncompress, and upload the folder "live_chat" to blesta /plugins/ directory. (you will not lose any configurations) 3º- Go to Blesta Admin, and click on Setings->Company->Plugins and it will list the "Blesta Live Chat" plugin, and a new "UPGRADE" button Click on "UPGRADE".   This version brings a lot of bugs detected and also brings the XMPP options    To configure XMPP justo do:   1º- Login to Blesta Live Chat Click on Menu->Settings->XMPP Settings here you can configure settings.   2º-Login to Blesta Live Chat Click on Menu->Settings->Departments Edit a department->Notifications about new chats here you can configure department push settings.     How to install (is very simple):     1º- Download the Blesta Live Chat Plugin here: Download Here (updated updated 14-04-2015) 2º- Uncompress, and upload the folder "live_chat" to blesta /plugins/ directory. 3º- Go to Blesta Admin, and click on Setings->Company->Plugins->Available and it will list the "Blesta Live Chat" plugin, just Click on "INSTALL" 4º- Now you will see on new menu item called "Live Chat", wen you click for the first time, a window will popup to login with the default details:   Username: admin Password: pass##   5º- On the popup windows, in top right click on "Menu", and then click on "Blesta Admin", now change the username, email, and password to your own, and click on "Update".   And thats it   By default on install the Blesta Live Chat plugin, it will also add an "Admin Chat Box" to Blesta Admin, to all Blesta Admins/Staff start chatting, on the bottom right you will see a new button.   And also by default, Blesta Live Chat plugin will add a Live Chat Widget to Blesta Client Area for clients request chatting.   Now you can click on "Menu" then "Settings" and see all the options, like create departments, add new operators and admins, add "Live Help" embebed code widget to your website pages.   This is the first beta plugin release, any bugs found or any susgestions are welcome to post here to fix it.   Later on we will add more functionality and more integrations betwin Blesta and Blesta Live Chat.       How to uninstall:   Go to Blesta Admin, and click on Setings->Company->Plugins and it will list the "Blesta Live Chat" plugin, just Click on "UNINSTALL"   Thats it   We hope you enjoy it.     Special thanks to Remigijus Kiminas from livehelperchat.com that we have based on making the Blesta Live Chat    
    More Info below:
     
    Because I have a lot of requests to show a little of the upcoming "Blesta Live Chat" here it is a teaser before the beta release
     
     
    Teaser 1

    in Blesta menu admin on Top, you can see how many clients are online requesting chat.
    and the best thing is on the bottom right, as you can see the "Blesta Live Chat" can be use for staff members and admins to chat with each other online inside Blesta admin.
     
    Teaser 2

    you can see here admins chat window to chat only with staff members and admins
     
     
    Teaser 3

    on bottom right you can see the chat button, you can put the button code inside any website pages, and not only on Blesta.
     
    Teaser 4

    here you can see an active chat betwin client and staff member
     
    Teaser 5

    here you can see the window where staff members can acept and chat with all clients, and see all details like geo location, ip, traced page links, send files or canned responses, and much more 
     
    This plugin will be offered for free, and you can host in your hown server/hosting plan 
     
     
    FAQ's:
     
    1º- How To see online visitores do this:
    Login to Blesta Live Chat -Click on Menu->Online Visitores   2º-  How To clean online visitores (if it has an abnormal number on cache like on Blesta Menu) Login to Blesta Live Chat - Click on Menu->Online Visitores->Clear List   3º-  How To go in "Offline Mode": Login to Blesta Live Chat - Click on Menu->Green Man  (click on the litle green man to go Red (Red=offline))   4º-  How To go in "Online Mode": Login to Blesta Live Chat - Click on Menu->Red Man  (click on the litle red man to go Green (Green=online))  
     
    We hope you enjoy
     
    Regards,
    PV
  15. Like
    Serendesk reacted to Michael in Email Priority   
    yeah I use the priority tags for staff emails:
    Licensecart {ticket.department_name} - Update to Ticket {ticket.code} - Priority: {ticket.priority}
  16. Like
    Serendesk got a reaction from activa in Simple Service Alternative To Cron   
    Oops, I forgot to mention; to have cron tasks running sooner than 5 minutes you also need to do what PauloV suggested here http://www.blesta.com/forums/index.php?/topic/4942-1-one-minute-cron-jobs/#entry39451
  17. Like
    Serendesk got a reaction from activa in Simple Service Alternative To Cron   
    Here's a very simple script to run the Blesta cron tasks as a constantly running background service and to do away with cron altogether. This is useful if you need to run the tasks more frequently than 5 minutes, or, get locking and overlap with cron. I have been running this now for about 24 hours and no problems so far.
    This script can be improved on greatly, but it does have a simple feature to ensure that you don't have more than one service running at the same time. With a bit more work you could have a very useful script that behaves like a system service with cli args, better error checking and signal handling for graceful shutdowns etc. (I have added basic signal handling but I haven't tested it. It requires the posix extension which I do not have).
    You can either start/stop the service from the command line or within a script, or use a process monitor like supervisord or daemontools to handle it (they have better logging and protect you from starting more than one).
    Two files are used; service.php and config.json.
    Start the service: redirect output to a log file and place the process in the background (append & to the end of the command). Choose your own php path and log file path.
    #run as current user /usr/local/bin/php service.php > BlestaService.log & Check the service is running: you should see the service name (set in config) and the pid of the process. ps -aux | grep BlestaService Stop the service:If usePIDFile in the config is set to true, the service will stop if the pid file is deleted. This provides a very simple way of gracefully stopping the service (the while loop will stop if the file cannot be found). Otherwise, you can use kill to stop it immediately, but ideally try to avoid this. DB transactions may be in use, but there could be issues when exiting during imap connections etc. Alternatively and more cleanly, send it signals if you have the posix extension.
    #kill kill 47854 #send quit signal, better kill -s QUIT 47854 service.php
    <?php require('/usr/local/www/blesta/blesta/lib/init.php'); set_time_limit(0); class BlestaService { private $config; private $pidFile; private $running = true; public function run() { //these are required steps so dont catch errors thrown from this function $this->prep(); while($this->keepRunning()) { try { $start = time(); //do the cron work Dispatcher::dispatch('/cron/', true); //clean up. might not be absolutely required gc_collect_cycles(); sleep(max(0, $this->config->runInterval - (time() - $start))); } catch(Exception $e) { $this->logWrite($e); sleep(60); } } $this->cleanup(); } private function prep() { gc_enable(); $this->config = json_decode(file_get_contents('config.json')); if(function_exists('cli_set_process_title') && function_exists('cli_get_process_title')) { $currentTitle = cli_get_process_title(); cli_set_process_title($this->config->serviceName); } if($this->config->usePIDFile) { $this->pidFile = $this->config->pidFileDir. DIRECTORY_SEPARATOR .$this->config->serviceName.'.pid'; $this->exitIfPIDFileExists(); $this->setPIDFile(); } if(function_exists('pcntl_signal')) { //signal handling declare(ticks = 1); pcntl_signal(SIGQUIT, 'sigHandler'); pcntl_signal(SIGTERM, 'sigHandler'); pcntl_signal(SIGKILL, 'sigHandler'); pcntl_signal(SIGABRT, 'sigHandler'); pcntl_signal(SIGHUP, 'sigHandler'); pcntl_signal(SIGINT, 'sigHandler'); } } private function exitIfPIDFileExists() { if(file_exists($this->pidFile) === true) { $pid = file_get_contents($this->pidFile); $this->logWrite("Unable to start. Is there a service already running with pid $pid? Otherwise remove the pid file located at $this->pidFile before starting"); exit(1); } } private function setPIDFile() { file_put_contents($this->pidFile, getmypid()); chown($this->pidFile, $this->config->pidFileOwner); chmod($this->pidFile, 0600); } private function removePIDFile() { if($this->config->usePIDFile && file_exists($this->pidFile) === true) { unlink($this->pidFile); } } private function keepRunning() { if($this->config->usePIDFile) { //removing pid file will shutdown the service $this->running = file_exists($this->pidFile); } //alternatively use pcntl_signal to stop the service cleanly by setting $this->running = false in the SIGTERM, SIGKILL, SIGINT handler return $this->running; } private function logWrite($string) { //echo to console as output will be redirected to a log file echo "$string\n"; } public function sigHandler($signo) { switch($signo) { case SIGQUIT: case SIGTERM: case SIGHUP: case SIGABRT: $this->keepRunning = false; break; case SIGKILL: //probably cant catch this one but try anyway $this->cleanup(); break; case SIGINT: break; default: } } private function cleanup() { $this->logWrite('Exiting gracefully'); $this->removePIDFile(); exit; } /*public function __destruct() { //removed this as it will be called when exiting via exitIfPIDFileExists() when a service exists already, causing that services pid file to be deleted (and eventually stop running) $this->cleanup(); }*/ } //run $service = new BlestaService(); $service->run(); ?> config.json { "serviceName":"BlestaService", "runInterval":60, "usePIDFile":true, "pidFileDir":"/tmp", "pidFileOwner":"www" }
  18. Like
    Serendesk reacted to PauloV in Simple Service Alternative To Cron   
    Thanks for sharing
  19. Like
    Serendesk got a reaction from PauloV in Simple Service Alternative To Cron   
    Oops, I forgot to mention; to have cron tasks running sooner than 5 minutes you also need to do what PauloV suggested here http://www.blesta.com/forums/index.php?/topic/4942-1-one-minute-cron-jobs/#entry39451
  20. Like
    Serendesk got a reaction from PauloV in Simple Service Alternative To Cron   
    Here's a very simple script to run the Blesta cron tasks as a constantly running background service and to do away with cron altogether. This is useful if you need to run the tasks more frequently than 5 minutes, or, get locking and overlap with cron. I have been running this now for about 24 hours and no problems so far.
    This script can be improved on greatly, but it does have a simple feature to ensure that you don't have more than one service running at the same time. With a bit more work you could have a very useful script that behaves like a system service with cli args, better error checking and signal handling for graceful shutdowns etc. (I have added basic signal handling but I haven't tested it. It requires the posix extension which I do not have).
    You can either start/stop the service from the command line or within a script, or use a process monitor like supervisord or daemontools to handle it (they have better logging and protect you from starting more than one).
    Two files are used; service.php and config.json.
    Start the service: redirect output to a log file and place the process in the background (append & to the end of the command). Choose your own php path and log file path.
    #run as current user /usr/local/bin/php service.php > BlestaService.log & Check the service is running: you should see the service name (set in config) and the pid of the process. ps -aux | grep BlestaService Stop the service:If usePIDFile in the config is set to true, the service will stop if the pid file is deleted. This provides a very simple way of gracefully stopping the service (the while loop will stop if the file cannot be found). Otherwise, you can use kill to stop it immediately, but ideally try to avoid this. DB transactions may be in use, but there could be issues when exiting during imap connections etc. Alternatively and more cleanly, send it signals if you have the posix extension.
    #kill kill 47854 #send quit signal, better kill -s QUIT 47854 service.php
    <?php require('/usr/local/www/blesta/blesta/lib/init.php'); set_time_limit(0); class BlestaService { private $config; private $pidFile; private $running = true; public function run() { //these are required steps so dont catch errors thrown from this function $this->prep(); while($this->keepRunning()) { try { $start = time(); //do the cron work Dispatcher::dispatch('/cron/', true); //clean up. might not be absolutely required gc_collect_cycles(); sleep(max(0, $this->config->runInterval - (time() - $start))); } catch(Exception $e) { $this->logWrite($e); sleep(60); } } $this->cleanup(); } private function prep() { gc_enable(); $this->config = json_decode(file_get_contents('config.json')); if(function_exists('cli_set_process_title') && function_exists('cli_get_process_title')) { $currentTitle = cli_get_process_title(); cli_set_process_title($this->config->serviceName); } if($this->config->usePIDFile) { $this->pidFile = $this->config->pidFileDir. DIRECTORY_SEPARATOR .$this->config->serviceName.'.pid'; $this->exitIfPIDFileExists(); $this->setPIDFile(); } if(function_exists('pcntl_signal')) { //signal handling declare(ticks = 1); pcntl_signal(SIGQUIT, 'sigHandler'); pcntl_signal(SIGTERM, 'sigHandler'); pcntl_signal(SIGKILL, 'sigHandler'); pcntl_signal(SIGABRT, 'sigHandler'); pcntl_signal(SIGHUP, 'sigHandler'); pcntl_signal(SIGINT, 'sigHandler'); } } private function exitIfPIDFileExists() { if(file_exists($this->pidFile) === true) { $pid = file_get_contents($this->pidFile); $this->logWrite("Unable to start. Is there a service already running with pid $pid? Otherwise remove the pid file located at $this->pidFile before starting"); exit(1); } } private function setPIDFile() { file_put_contents($this->pidFile, getmypid()); chown($this->pidFile, $this->config->pidFileOwner); chmod($this->pidFile, 0600); } private function removePIDFile() { if($this->config->usePIDFile && file_exists($this->pidFile) === true) { unlink($this->pidFile); } } private function keepRunning() { if($this->config->usePIDFile) { //removing pid file will shutdown the service $this->running = file_exists($this->pidFile); } //alternatively use pcntl_signal to stop the service cleanly by setting $this->running = false in the SIGTERM, SIGKILL, SIGINT handler return $this->running; } private function logWrite($string) { //echo to console as output will be redirected to a log file echo "$string\n"; } public function sigHandler($signo) { switch($signo) { case SIGQUIT: case SIGTERM: case SIGHUP: case SIGABRT: $this->keepRunning = false; break; case SIGKILL: //probably cant catch this one but try anyway $this->cleanup(); break; case SIGINT: break; default: } } private function cleanup() { $this->logWrite('Exiting gracefully'); $this->removePIDFile(); exit; } /*public function __destruct() { //removed this as it will be called when exiting via exitIfPIDFileExists() when a service exists already, causing that services pid file to be deleted (and eventually stop running) $this->cleanup(); }*/ } //run $service = new BlestaService(); $service->run(); ?> config.json { "serviceName":"BlestaService", "runInterval":60, "usePIDFile":true, "pidFileDir":"/tmp", "pidFileOwner":"www" }
  21. Like
    Serendesk got a reaction from Michael in Simple Service Alternative To Cron   
    Oops, I forgot to mention; to have cron tasks running sooner than 5 minutes you also need to do what PauloV suggested here http://www.blesta.com/forums/index.php?/topic/4942-1-one-minute-cron-jobs/#entry39451
  22. Like
    Serendesk got a reaction from Michael in Simple Service Alternative To Cron   
    Here's a very simple script to run the Blesta cron tasks as a constantly running background service and to do away with cron altogether. This is useful if you need to run the tasks more frequently than 5 minutes, or, get locking and overlap with cron. I have been running this now for about 24 hours and no problems so far.
    This script can be improved on greatly, but it does have a simple feature to ensure that you don't have more than one service running at the same time. With a bit more work you could have a very useful script that behaves like a system service with cli args, better error checking and signal handling for graceful shutdowns etc. (I have added basic signal handling but I haven't tested it. It requires the posix extension which I do not have).
    You can either start/stop the service from the command line or within a script, or use a process monitor like supervisord or daemontools to handle it (they have better logging and protect you from starting more than one).
    Two files are used; service.php and config.json.
    Start the service: redirect output to a log file and place the process in the background (append & to the end of the command). Choose your own php path and log file path.
    #run as current user /usr/local/bin/php service.php > BlestaService.log & Check the service is running: you should see the service name (set in config) and the pid of the process. ps -aux | grep BlestaService Stop the service:If usePIDFile in the config is set to true, the service will stop if the pid file is deleted. This provides a very simple way of gracefully stopping the service (the while loop will stop if the file cannot be found). Otherwise, you can use kill to stop it immediately, but ideally try to avoid this. DB transactions may be in use, but there could be issues when exiting during imap connections etc. Alternatively and more cleanly, send it signals if you have the posix extension.
    #kill kill 47854 #send quit signal, better kill -s QUIT 47854 service.php
    <?php require('/usr/local/www/blesta/blesta/lib/init.php'); set_time_limit(0); class BlestaService { private $config; private $pidFile; private $running = true; public function run() { //these are required steps so dont catch errors thrown from this function $this->prep(); while($this->keepRunning()) { try { $start = time(); //do the cron work Dispatcher::dispatch('/cron/', true); //clean up. might not be absolutely required gc_collect_cycles(); sleep(max(0, $this->config->runInterval - (time() - $start))); } catch(Exception $e) { $this->logWrite($e); sleep(60); } } $this->cleanup(); } private function prep() { gc_enable(); $this->config = json_decode(file_get_contents('config.json')); if(function_exists('cli_set_process_title') && function_exists('cli_get_process_title')) { $currentTitle = cli_get_process_title(); cli_set_process_title($this->config->serviceName); } if($this->config->usePIDFile) { $this->pidFile = $this->config->pidFileDir. DIRECTORY_SEPARATOR .$this->config->serviceName.'.pid'; $this->exitIfPIDFileExists(); $this->setPIDFile(); } if(function_exists('pcntl_signal')) { //signal handling declare(ticks = 1); pcntl_signal(SIGQUIT, 'sigHandler'); pcntl_signal(SIGTERM, 'sigHandler'); pcntl_signal(SIGKILL, 'sigHandler'); pcntl_signal(SIGABRT, 'sigHandler'); pcntl_signal(SIGHUP, 'sigHandler'); pcntl_signal(SIGINT, 'sigHandler'); } } private function exitIfPIDFileExists() { if(file_exists($this->pidFile) === true) { $pid = file_get_contents($this->pidFile); $this->logWrite("Unable to start. Is there a service already running with pid $pid? Otherwise remove the pid file located at $this->pidFile before starting"); exit(1); } } private function setPIDFile() { file_put_contents($this->pidFile, getmypid()); chown($this->pidFile, $this->config->pidFileOwner); chmod($this->pidFile, 0600); } private function removePIDFile() { if($this->config->usePIDFile && file_exists($this->pidFile) === true) { unlink($this->pidFile); } } private function keepRunning() { if($this->config->usePIDFile) { //removing pid file will shutdown the service $this->running = file_exists($this->pidFile); } //alternatively use pcntl_signal to stop the service cleanly by setting $this->running = false in the SIGTERM, SIGKILL, SIGINT handler return $this->running; } private function logWrite($string) { //echo to console as output will be redirected to a log file echo "$string\n"; } public function sigHandler($signo) { switch($signo) { case SIGQUIT: case SIGTERM: case SIGHUP: case SIGABRT: $this->keepRunning = false; break; case SIGKILL: //probably cant catch this one but try anyway $this->cleanup(); break; case SIGINT: break; default: } } private function cleanup() { $this->logWrite('Exiting gracefully'); $this->removePIDFile(); exit; } /*public function __destruct() { //removed this as it will be called when exiting via exitIfPIDFileExists() when a service exists already, causing that services pid file to be deleted (and eventually stop running) $this->cleanup(); }*/ } //run $service = new BlestaService(); $service->run(); ?> config.json { "serviceName":"BlestaService", "runInterval":60, "usePIDFile":true, "pidFileDir":"/tmp", "pidFileOwner":"www" }
  23. Like
    Serendesk reacted to PauloV in Help Me With My Security? :)   
    Advice: dont put all the eggs in the same bagg
    The big problem is, it only needs one password to get them all
    Memorise, memorise, encrypt a usb pen or microsd and store them. Is more safe
    Dont forget of you dont remember a password you always have a chance to recover without any cloud storage.
    Just remember the recent "Fappening" from the Apple lol
  24. Like
    Serendesk reacted to Cody in 1 (One) Minute Cron Jobs :)   
    You could create race conditions. Each PHP process is spun off in a new thread, so there's no guarantee one finishes before the next is requested. This is especially problematic when a task performs operations that result in the PHP process blocking for IO, such as processing payments, or receiving email. If you were to do this, you would need to verify that the task ended before starting up the next.
  25. Like
    Serendesk reacted to serge in 1 (One) Minute Cron Jobs :)   
    In my case, it's more about get paid service activated quick, my cron is 2 mins frequency by the way.
×
×
  • Create New...