set condition on pause before in packer - packer

I have a script which reboots the instance. However the reboot happens only in certain cases. Is there a way I can put a condition on the pause_before n the provisioner that will run after the reboot. Since I would want it to pause only when reboot happened and not always.

No.
Most of the times machines shutsdown sshd rather quick on reboot and pause_before can have a short duration and still work correctly.

Related

start mysql service if it is down programatically

I have a ubuntu server and i want to monitor it and start mysql service if it goes down, what can i do programatically to implement this.
I see this solution and set it via cron to execute every minute.
#!/bin/bash
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
/usr/sbin/service mysql start
fi
but would setting a cron to execute every minute load my server.
Any help in this direction will be appreciated. Thanks.
For the most part, running a short script like that every minute won't stress your server. So programmatically, assuming you tested it and all, I don't see much wrong with your approach.
I'd be more concerned as to why your service randomly shuts down though, have you looked for clues in logs? Depending on the severity of the cause, perhaps implementing a monitoring tool like nagios or icinga might be useful.

How to detect what is running on MySQL every hour?

Munin showing huge spike on MySQL queries every hour but I am unable to detect what is causing this. I am running version 5.6.30.
Tried to enable slow running queries but can't find it there.
Also logged all queries and tried to see what is running on that particular time. I cannot find it.
Checked cronjobs but there wasn't anything related
Disabled almost everything on LFD & CSF
The event scheduler status is set to OFF
Is there any other way to find what is running every hour?
Munin graph showing sql queries:
You can use a shell script and put the instruccion "processlist" and send the output to a log file.
Put the delay in seconds that you want for run again the instucction.
while [true];
mysql -h localhost -u root -ppasswd < process
delay xtime
done
And the file processlist you put the instrucction "show full processlist"
I hope this help you
Regards
Some crawlers were mining data from my website. I wasn't able to detect because requests sent from a million different IPs.
Added captcha to website as human control and spikes gone.

Auto delete a GCE Instance even after I turn off my laptop

I would like to start a job on Compute engine instance, turn off my laptop and have the instance automatically deleted once the remote job is complete (without my laptop running)
Currently I have a script which runs on my laptop which has a delete instance command in the end. But I wish to turn off my laptop, since the remote job can even run for >24hours.
Is it possible to do this? Maybe I can poweroff or delete the instance at the end of the remote job FROM the remote instance itself?
Your assumption is correct you just need to trigger the shutdown command from within your GCE instance when the script has finished and not calling it from your laptop

Is expect code going to through error if i reboot remote machine?

i am not sure what will happen so i am asking this question and also because i didn't tested this.i have a function send command which sends commands to remote machine and it works fine for normal commands but what if it sends command for reboot like below.
sendcommand reload
expect -re "$prompt"
send -- "exit"
expect eof
i mean after reload how would the rest of the script going to excecute or it will thorugh some error or it will work fine? please guide.
It depends on exactly how you ask for the reboot to be done. Rebooting may be done by asking the system to restart, and the time to process that might allow you to exit. Or it might not; there's a race condition. You certainly need to drop the network connection though; when the OS comes back, it won't recognize it and you'll get a forced connection reset (if not before).
Or you could ask it to reboot a couple of seconds in the future (I forget the exact syntax for this) to give yourself time to disconnect. Some individual research and experimentation is likely to be needed; VMs are good for this as they restart much more rapidly…

PHP script timeout problem

Here's a short back story for context:
- Had a site hosted on a solaris machine, had a script that generated a report (pulled data from mysql, generally took ~60 seconds). Everything worked fine.
- Migrated that site and db to Ubuntu machines. Now, the script times out after 30 seconds.
Steps I've already taken:
Increased the max_execution_time to 3600 (I know it's high as hell, but that's what it was set to on the old solaris box)
Set max_input_time = -1
set memory_limit = 64MB
I've checked through phpinfo() that these changes are being accepted and show as the current configuration.
As hard as I pray, as crossed as I can get my fingers, or as many times as I can run the script over and over again...I still get the same result - 30 seconds, it seemingly times out, and tosses a 500 error back at me.
Thoughts? Thanks!
Double check your configuration. If this is being run as a CLI script then some distros have taken to seperating config files in separate directories to have different configuration values for CLI vs web/mod_php. You can run php -i from the command line to see what the CLI environment is configured to do.
First you need to be sure if mysql or php is restricting the time. If it's PHP set_time_limit(0) does it well.
A mysql abortion would propably lead into an unexpected result. For your 500 PHP should be responsible.