runit startup script without pause - runit

I am using a runit based linux distro (artix) and I would like to run a script once at startup with the root user. To achieve this I usually create a service with this kind of run script:
#!/bin/bash
<my command here> & pause
This allow the command to run once when the service is started, but this keep a useless process alive. Is there a cleaner way to tell runit that a service script should be run once ?

Related

running scripts on ssh remotely

I have a python script and a file (both on ssh) to be inserted to a db (mysql) using the python script. My file has 53,000,000 rows to be submitted to the db. This submission takes a very long time. Is there anyway in which I can run the script so that even if I exit ssh the script continues running?
Thanks,
You can use the screen or tmux. Both commands allow you to have detached user session. You can reconnect at any time to this session.
You only need to start screen and run your scripts there. After that you can push ctrl+a and than d and your session will be detached.
To restore your session you need to run screen -a.
Why dont you have it handled in a jenkins pipline, setup a job in jenkins to run the script.

Easiest Way to Execute a Node Script

I have an AWS-hosted MySQL database with 900+ records. I've developed a Node script that queries the database for new records, generates MP3 files for each one, uploads those files to S3 storage, and inserts the links into my database.
Right now, I'm having to execute that script manually via command prompt (npm). The script only needs to be run occasionally, so running it manually isn't a problem. But I'm sure there's an easier way than command prompt.
Is there a way to automatically run the script every so often? Or perhaps run it via a desktop shortcut? I'm open to ideas on this...just looking to simplify.
I am very new to Node and all things programming, so please forgive my ignorance here.
In Linux, you could run as a pure Linux shell script. Use a cron job to schedule the script.
Ex :
#!/usr/bin/env node
console.log('Hello world!');
In Windows, if you want to run manually, you could create a bat file and run the bat file to run the script.
Ex :
name : my_node_script.bat
node c:\path\to\file\my_node_script_code.js
If you want to run the bat file periodically, you could use Task Scheduler to schedule the bat file. See this guide of you want more details on scheduling.

Does crontab leave mysql connections open?

When I run report jobs (get net sales data from mysql) in crontab (bashscript) , I establish a connection to mysql and get the required data.
Does this leave mysql connections open or all the connections are closed on job completion?
UPDATE - I use bash script to connect to mysql.
In basic scenarios the MySQL connections will be closed when the mysql client within the bash script finishes running.
If you are running the mysql command line Linux client within your bash script then bash would normally wait for the mysql process to exit before continuing to the end of the script.
There are ways to persist processes beyond the life of the bash script but you haven't mentioned using those in your question.
If you are using a mysql library that has a close function - most of the MySQL libraries have this in the api then you should use it. Although the default process behaviour will probably clean up open connections for you, it helps to get in the habit of closing resources that you are not going to require again within your code as this makes it more scalable and also informs other developers of your intended behaviour.

How can I automate mysqldump database backups in Windows Server 2012?

I'm trying to get mysqldump to do backups to a .sql file automatically, I have being reading that I need to use cron jobs or Windows Task Scheduler; the problem is that I can't find anything online that shows me how to do it.
To do the backups I'm using cmd with the following commands:
mysqldump --user username --password=123 databtable > backup.sql
This command works perfectly, it does create the .sql file but how do I automate it in such a way that it does the backup every certain time.
Hopefully you can help me and thank you so much!
You should use the schtasks command in Windows.
Command syntax details are available here: https://technet.microsoft.com/en-us/library/cc772785(v=ws.10).aspx
You could also use the Task Scheduler application in Windows if you like GUIs:
Create a new basic task
Set the Trigger (run daily, weekly, etc)
Set the Action. (what program to run) Be sure to
include only the executable in the Program field, and put the
command arguments in the Add Arguments field.
You probably want to set your task to 'Run whether the user is logged on or not'. This is achieved by modifying the task, and adjusting the Security Options on the General Tab of the task.
When troubleshooting your task, use the History tab for info regarding job failures.

Bash init.d script detect that mysqld has started and is running

I'm working on my dedicated server running CentOS. I found out that one of my applications which starts up via a script in /etc/init.d/ requires MySQL to be running, or else it throws an error, so essentially I currently have to start it by hand.
How can I detect, in a bash script (#!/bin/sh), whether the MySQL service has started yet? Is there some way to poll port 3306 until it is open to accept connections, and only then continue with the script? Or maybe set an order so that the script doesn't run until the mysqld script runs?
The init scripts allow you to set the order with the numbering scheme.
Example, in /etc/rc.d/rc5.d you might see:
S98first
S99second
S99second runs after S98first due to the naming.