Codeigniter log class not being called when running via CLI - codeigniter

I have enabled the inbuilt logging within Codeigniter. This works fine.
However I'm running a particular script through the command line interface, of which works fine, however none of the normal logs are being updated. If I call the script through http the logs update fine.
Is it some built in feature within CI that running through the CLI won't update the logs, or do I have a problem somewhere?

Well there is normally a difference in the user that CI uses to write the logs.
If you are using the browser it may be using an Apache Web-User like ours does.
If you do it through the command line you are normally logged in as yourself. Do you have write permissions to the log file?

Related

Run a bash script in the background using Laravel

I’m trying to run a bash script in the background using Laravel. I’m currently using Symfony process to run it. However, there is a timeout and the user won’t be able to navigate the website until the script is done. The script doesn’t output anything. It simply runs other scripts and take the output and insert it into a database.
I have tried appending & at the end of the command as well as dev/null. No matter what I do the user can’t navigate away from the page until the script is done executing. If the user navigates away from the page, the script is stoped.
Regards,
Arron
You should use laravel queues, it is exactly what you want :
https://laravel.com/docs/5.8/queues
The easiest way is with a database, but if you are using it with redis, you can also use Laravel Horizon to monitor them : https://laravel.com/docs/5.8/horizon
Configure supervisord to run your script in the background. Google how to install and setup supervisor.

Error logging in for osx

This is a continuation of
https://community.h2o.ai/questions/2165/error-logging-in.html
and
https://community.h2o.ai/questions/1665/can-not-login-to-steam-osx.html
from my original post on community.h2o:
"""
Hi there, I am currently trying to set up an an API on my local machine using steam.
The documentation is out of date on http://docs.h2o.ai/steam/latest-stable/steam-docs/Installation.html#steam-start-flags which says to start the steam service for the first time, execute ./steam serve master --admin-name=admin --admin-password=admin the first time around to set the password. The current command is ./steam serve master --superuser-name=admin --superuser-password=admin but when I try to log in to 0.0.0.0:9000 (which is what it asks me to point the browser to) I get 2017/06/14 13:03:48 User admin does not exist I tried using single, double and no quotes.
Thank you for your time!
"""
The default username/password is superuser/superuser. The flags are not honored by steam server command and looks like its a bug. See config.toml file in the folder.
This breaks the very first developer experience with h2o/steam and is not encouraging.
./steam serve master --superuser-name=superuser --superuser-password=superuser works fine

Using is_cli_request() is necessary for cron job in codeigniter

Using Codeigniter 2.2.0 for my project. Is $this->input->is_cli_request() validation is necessary for a cron job?
It is recommended to protect your cronjob not to execute when someone type the URL in their browser. However if you don't have any problem running your cronjob invoked by anyone then can avoid this check.
Refer https://ellislab.com/codeigniter/user-guide/general/cli.html for more details.
It recommented to run cron jobs with command line.
There are many reasons for running CodeIgniter from the command-line, but they are not always obvious.
Run your cron-jobs without needing to use wget or curl
Make your cron-jobs inaccessible from being loaded in the URL by checking for $this->input->is_cli_request()
Make interactive "tasks" that can do things like set permissions, prune cache folders, run backups, etc.
Integrate with other applications in other languages. For example, a random C++ script could call one command and run code in your models!
More info read here
But you also can prevent calling from URL in your server.

Topshelf, NLog and File Permissions

I have a Windows service application that uses the TopShelf library and I'm installing it in AWS during the cfn-init using the handy command line features that you get with topshelf.
C:\handy_service\> HandyService.exe install start
This basically installs the service in the registry and then calls sc start, but it's quite useful because it checks the service name matches what you expect and it allows you to configure the user that service will run as using the nice fluent API.
The installer code also writes some diagnostic logs to NLog if the service is configured to use NLog in general.
The problem is this: the installer runs as the default local administrator account that the AMI starts with and the NLog file gets created by this user. When the service starts up as the Network Service user, it doesn't have permission to write to the NLog log file.
How can I get my service to write to the log file? I've thought about setting the permissions programmatically but it looks nasty and I'd have to determine the log file name as this is generated dynamically based on the ec2 instance id. Also, it's not entirely obvious at what point the log file is first created. The easiest hack that I might go with is having two NLog.configs and switching one out at the end of the install after the logger is flushed. But because there is some overlap in time between the service starting and the installer exiting, I expect I'll lose a few lines of logging here.
Any clean suggestions would be greatly appreciated!
In the end I went with setting the permissions on the logs folder at deploy time. It's actually pretty straightforward with icacls, only a couple of lines in rake for instance, assuming you know where your logs folder is going to be:
sh %{icacls "#{logs_dir}" /grant "#{username}":(OI)(W)}
Not calling UseNLog() in the service config would also be a simple option, any install-time errors would go in the Windows event log in that case.

Invoke a CakePHP console shell on server without command line access

Is there way to invoke a CakePHP console shell on server without shell access? I have written a shell for performing some once off (and hence not a cron task) post DB upgrade tasks.
I could always just copy the logic into a temporary controller, call its actions via http and then delete it, but was wondering if there was a better way to go about it.
It seems that this is a one off script you might want to typically be running after DB updates right?
If that's the case, you can make it part of your "DB update script"
If you use anything like capistrano, you can include there too.
In all cases, if you don't want to touch the shell, I agree that having a controller to call the console code (or any php file running exec() as mentioned previously) would do the trick.
Also, if you want to run it just once and have it scheduled - don't forget that you have the "at" command (instead of cron) which will run it at that scheduled date (see http://linux.about.com/library/cmd/blcmdl1_at.htm)
Hope it helps,
Cheers,
p.s: if its a console shell and you don't want to run it from the console, then just don't make it a console shell.
I have to agree with elvy. Since this is something that you need to do once in a while after other events have happened, why not just create an 'admin' area for your application and stick code for that update in there?
you may be able to use php's exec function to call it from any old php script.
http://www.php.net/exec

Resources