pm2 restart app, how to create a new log,don't add old log - pm2

everybody.
i using pm2. when it restart an app, it doesn't create a new log.it will add the new log to the old log.
i want it create new log,and delete old log.
module.exports = {
apps : [{
name : "restart",
script : "./stat.js",
error_file: './err_logs/error-log.log',
out_file: './log/out-log.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss',
cron_restart: '10 * * * *',
}]
}
i want rewrite the old log,don't add it.so,how should i set it?

Related

TYPO3 and MySQL trigger

In ext_tables.sql file of an extension I can define new tables/fields that are going to be added to the database.
Is it possible with TYPO3 to add also Triggers (MySQL) to database?
Not via ext_tables.sql.
You can use the extension manager signal slot and execute your queries there after installation of your extension
ext_localconf.php of your extension:
call_user_func(function($extensionKey) {
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
'hasInstalledExtensions',
function($keyOfInstalledExtension) use ($extensionKey) {
if ($extensionKey !== $keyOfInstalledExtension) {
return;
}
\Vendor\MyExt\Hooks\ExtensionManager::postInstallExtension();
}
);
}
}, $_EXTKEY);

Detect if another Chrome Extension is installed

I'm developing an extension for Chrome, but I want my extension to work only if another is disabled/removed.
It means that when my users install my extension, I would like to tell them "if you install my extension, you have to accept to disable this other extension".
I don't want my extension to work if the other one is active.
Do you know how I could proceed?
To detect if another extension is installed:
1) Update the manifest.json to include the necessary management permission:
{
"name": "My extension",
...
"permissions": [
"management"
],
...
}
2) To check if the extension is installed exist 2 options:
a) If you know the extension id, use the chrome.management.get(extensionId, function callback) method:
var extensionId = '<the_extension_id>';
chrome.management.get(extensionId, function(extensionInfo) {
var isInstalled;
if (chrome.runtime.lastError) {
//When the extension does not exist, an error is generated
isInstalled = false;
} else {
//The extension is installed. Use "extensionInfo" to get more details
isInstalled = true;
}
});
b) If you know the extension name (or any other parameter), you can use chrome.management.getAll(function callback):
var extensionName = '<the_extension_name>';
chrome.management.getAll(function(extensions) {
var isInstalled = extensions.some(function(extensionInfo) {
return extensionInfo.name === extensionName;
});
});

node.js json-server data are cached

I'm using the following json-server
var server = jsonServer.create()
var router = jsonServer.router('./books/db.json')
server.use(jsonServer.defaults())
server.use(router)
server.listen(3000)
I change db.json every 5 seconds
setInterval(function() {
var o = JSON.parse(fs.readFileSync('./books/db.json', 'utf8'));
for (var i = 0; i < o.books.length; i++) {
// do some changes
}
fs.writeFile("./books/db.json", JSON.stringify(o));
}, 5000);
the file is changing but when doing a request, it stills has the old data
json-server uses lowdb internally for serving static files. lowdb won't reload your file on change as it is not watching the file for changes. The lowdb database is available at router.db, so you can use router.db.read('./books/db.json') to read your file again after changing it. See the lowdb docs for the API.
Alternatively, read the section of the json-server docs pertaining to generating random data. This solution avoids continual disk access, but your data will be lost after the server exits. If this is not an issue, this would the the way I would go.

How to configure grafana to display data in graphite

I am trying to configure grafana for graphite. I used the below link to configure graphite.
Graphite is running on my laptop on port 8080. I am able to send data using a sample project that i have created and am able to see the graphs for the same on graphite UI.I am sending data to graphite over port 2003 ie the port on which carbon runs.
Graphite installation - https://gist.github.com/albertohm/5697429
I am trying to configure grafana now to display data present on graphite.I have used the link below to configure grafana. I have only made changes in the config file.When i click the index.html file i can see the grafana UI but it is not displaying data present on graphite. Can somebody please help me on this.
Grafana installation link - http://grafana.org/docs/
All the services are running on my laptop.
Below is the config file that i am using on grafana.
define(['settings'],
function (Settings) {
return new Settings({
datasources: {
graphite: {
type: 'graphite',
url: "http://127.0.0.1:8080",
default: true,
//render_method: 'GET',
}
},
/* Global configuration options
* ========================================================
*/
// specify the limit for dashboard search results
search: {
max_results: 20
},
// default home dashboard
default_route: '/dashboard/file/default.json',
//default_route: '/opt/graphite/webapp/graphite/dashboard',
// set to false to disable unsaved changes warning
unsaved_changes_warning: true,
// set the default timespan for the playlist feature
// Example: "1m", "1h"
playlist_timespan: "1m",
// If you want to specify password before saving, please specify it bellow
// The purpose of this password is not security, but to stop some users from accidentally changing dashboards
admin: {
password: ''
},
// Change window title prefix from 'Grafana - <dashboard title>'
window_title_prefix: 'Grafana - ',
// Add your own custom panels
plugins: {
// list of plugin panels
panels: [],
// requirejs modules in plugins folder that should be loaded
// for example custom datasources
dependencies: [],
}
});
});
Thanks in advance.

Is there a way generate a shortcut file with adobe air?

Good afternoon,
I would like create a application that can can create folders and short cuts to folders in the file system. The user will click a button and it will put a folder on there desktop that has short cuts to files like //server/folder1/folder2 Can you create a desktop shortcut with code in adobe air? How would you do that? How do you create a folder? I keep thinking this should be easy but i keep missing it.
Thank you for your help sorry for the trouble,
Justin
If your deployment profile is Extended Desktop, you may be able to use NativeProcess and some simple scripts that you could package with your app. This approach would entail handling the functionality on a per OS basis, which would take some work and extensive testing. However, I wanted to at least share a scenario that I verified does work. Below is a test case that I threw together:
Test Case: Windows 7
Even though the Adobe documentation says that it prevents execution of .bat files, apparently it doesn't prevent one from executing the Windows Scripting Host: wscript.exe. This means you can execute any JScript or VBScript files. And this is what you would use to write a command to create a shortcut in Windows (since Windows doesn't have a commandline command to create shortcuts otherwise).
Here's a simple script to create a shortcut command, which I found on giannistsakiris.com, (converted to JScript):
// File: mkshortcut.js
var WshShell = new ActiveXObject("WScript.Shell");
var oShellLink = WshShell.CreateShortcut(WScript.Arguments.Named("shortcut") + ".lnk");
oShellLink.TargetPath = WScript.Arguments.Named("target");
oShellLink.WindowStyle = 1;
oShellLink.Save();
If you package this in your application in a folder named utils, you could write a function to create a shortcut like so:
public function createShortcut(target:File, shortcut:File):void {
if (NativeProcess.isSupported) { // Note: this is only true under extendedDesktop profile
var shortcutInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
// Location of the Windows Scripting Host executable
shortcutInfo.executable = new File("C:/Windows/System32/wscript.exe");
// Argument 1: script to execute
shortcutInfo.arguments.push( File.applicationDirectory.resolvePath("utils/mkshortcut.js").nativePath);
// Argument 2: target
shortcutInfo.arguments.push("/target:" + target.nativePath);
// Argument 3: shortcut
shortcutInfo.arguments.push("/shortcut:" + shortcut.nativePath);
var mkShortcutProcess = new NativeProcess();
mkShortcutProcess.start(shortcutInfo);
}
}
If one wanted to create a shortcut to the Application Storage Directory on the Desktop, the following would suffice:
var targetLocation:File = File.applicationStorageDirectory;
var shortcutLocation:File = File.desktopDirectory.resolvePath("Shortcut to My AIR App Storage");
createShortcut(targetLocation, shortcutLocation);
Obviously there's a lot of work to be done to handle different OS environments, but this is at least a step.
As far as I know, File class does not allow the creation of symbolic links. But you can create directories with createDirectory(): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#createDirectory%28%29
Check if this can be useful: http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/
Air doesnt let you create shortcuts natively. Here's a workaround that works with Windows [may work on Mac but I don't have a machine to test].
Using Air, create a file that contains the following plain text
[InternetShortcut]
URL=C:\path-to-folder-or-file
Replace path-to-folder-or-file with your folder/file name
Save the file as test.url
Windows recognizes this file as a shortcut.
It is possible to coerce Adobe Air into creating symbolic links, other useful things, on a Mac. Here's how I did it:
You will need AIRAliases.js - Revision: 2.5
In the application.xml add:
<!-- Enables NativeProcess -->
<supportedProfiles>extendedDesktop desktop</supportedProfiles>
In the Air app JavaScript:
// A familiar console logger
var console = {
'log' : function(msg){air.Introspector.Console.log(msg)}
};
if (air.NativeProcess.isSupported) {
var cmdFile = air.File.documentsDirectory.resolvePath("/bin/ln");
if (cmdFile.exists) {
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var processArgs = new air.Vector["<String>"]();
nativeProcessStartupInfo.executable = cmdFile;
processArgs.push("-s");
processArgs.push("< source file path >");
processArgs.push("< link file path >");
nativeProcessStartupInfo.arguments = processArgs;
nativeProcess = new air.NativeProcess();
nativeProcess.addEventListener(air.NativeProcessExitEvent.EXIT, onProcessExit);
nativeProcess.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onProcessOutput);
nativeProcess.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onProcessError);
nativeProcess.start(nativeProcessStartupInfo);
} else {
console.log("Can't find cmdFile");
}
} else {
console.log("Not Supported");
}
function onProcessExit(event) {
var result = event.exitCode;
console.log("Exit Code: "+result);
};
function onProcessOutput() {
console.log("Output: "+nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable));
};
function onProcessError() {
console.log("Error: "+nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable));
};
Altering the syntax of the command and parameters passed to NativeProcess you should be able to get real shortcuts on Windows too.