{"_id":"5b2582f13fd93f0003dd0832","category":{"_id":"5b2582f13fd93f0003dd082e","version":"5b2582f13fd93f0003dd0835","project":"54e78caefdabe62500fcdddf","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-05-21T01:28:30.273Z","from_sync":false,"order":1,"slug":"templates","title":"Templates"},"project":"54e78caefdabe62500fcdddf","user":"54e7ff93c1c5e90d0048bd92","version":{"_id":"5b2582f13fd93f0003dd0835","project":"54e78caefdabe62500fcdddf","__v":1,"forked_from":"5a787de939d488001232a05f","createdAt":"2018-02-05T15:53:13.563Z","releaseDate":"2018-02-05T15:53:13.563Z","categories":["5b2582f13fd93f0003dd082d","5b2582f13fd93f0003dd082e","5b2582f13fd93f0003dd082f","5b258376a03e480003de616e"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.2.4","version":"1.2.4"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-05-21T01:29:28.039Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:api-header]\n{\n  \"title\": \"How to add a new template\"\n}\n[/block]\nOne of the main features of pufferd is its template system, which makes it very easy to add new games by simply editing a JSON file.\n\nThese templates are located by default in ```/var/lib/pufferd/templates```\n\nTo create a new template, make a new file in ```/var/lib/pufferd/templates``` with a name not used by a default template, and make sure the file ends in .json\n[block:api-header]\n{\n  \"title\": \"Template Structure\"\n}\n[/block]\nTemplates are made up of a beginning description and 4 main sections: install, run, environment, and data\n\nVariables are created in the data section and can be used throughout the template with the syntax ```${variable}``` to replace data where needed.\n\n**type:** To start, include the beginning section which includes the \"type\" of template it is. This type field is not utilized yet, but will be in the future for grouping of templates.\n\nFor this example we are going to make a template for SpongeForge, so the type is set to \"java\" like the other Minecraft templates.\n\n**display:** This sets the name of the template displayed in PufferPanel.\n\n```\n{\n  \"pufferd\": {\n    \"type\": \"java\",\n    \"display\": \"SpongeForge - Minecraft\",\n ```\n[block:api-header]\n{\n  \"title\": \"Processors\"\n}\n[/block]\nA \"processor\" is a command or operation that can occur on installing, before starting, and after stopping a server. Processors are made up of different times, each one having a specific job.\n\nThese types are:\n  * download\n  * move\n  * command\n  * writefile\n  * mkdir\n\nEach processor has access to each data variable defined, and can use their values. They also have the environment variables which can be defined in the run section below. \n\n**download** - Downloads a file or multiple files\n```\n    \"install\": {\n      \"commands\": [\n        {\n          \"type\": \"download\",\n          \"files\": [\n            \"http://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeversion}/forge-${forgeversion}-installer.jar\",\n\"http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/${spongeversion}/spongeforge-${spongeversion}.jar\"\n          ]\n        },\n\n```\n\n**move - renaming a file** - move can be used to either move a file into a different location, or rename a file. In this case we are renaming a file that begins with \"forge-\" to \"installer.jar\" so that the commands below will work even if the version of Forge changes.\n```\n        {\n          \"source\": \"forge-*.jar\",\n          \"target\": \"installer.jar\",\n          \"type\": \"move\"\n        },\n```\n\n**mkdir** - Creates a new directory\n```\n        {\n          \"target\": \"mods\",\n          \"type\": \"mkdir\"\n        },\n```\n\n**move - moving a file** - This is moving a file that begins with \"spongeforge-\" into the newly created mods directory\n```\n        {\n          \"source\": \"spongeforge-*.jar\",\n          \"target\": \"mods\",\n          \"type\": \"move\"\n        },\n```\n\n**command** - Executes a command directly on the system\nYou should use this type only when necessary, and if possible, make the commands generic to the host operating system.\n```\n        {\n          \"commands\": [\n            \"java -jar installer.jar --installServer\"\n          ],\n          \"type\": \"command\"\n        },\n```\n\n**writefile** - Writes text into a file, ${ip} and ${port} are variables from the data section\n```\n        {\n          \"type\": \"writefile\",\n          \"text\": \"server-ip=${ip}\\nserver-port=${port}\\n\",\n          \"target\": \"server.properties\"\n        },\n```\n\n**move** - Finally, we rename a file that begins with \"forge-\" and ends in \"-universal\" to the \"server.jar\" like other pufferd Minecraft templates do.\n```\n        {\n          \"source\": \"forge-*-universal.jar\",\n          \"target\": \"server.jar\",\n          \"type\": \"move\"\n        }\n      ]\n    },\n```\n[block:api-header]\n{\n  \"title\": \"Run\"\n}\n[/block]\nThe run section defines what happens when the start and stop buttons are pressed.\n\n**stop** - Command to send to the console of the running server to stop it\n**pre** - Processors to run before the server starts\n**post** - Processors to run after the server starts\n**arguments** - These are the command line arguments placed after the initial ```program``` and accepts variables from the data section\n**program** - The actual program to execute to run the server\n**environmentVars** - Any environment variables to set for this server\n\n\n```json\n{\n    \"run\": {\n      \"stop\": \"stop\",\n      \"pre\": [],\n      \"post\": [],\n      \"arguments\": [\n        \"-Xmx${memory}M\",\n        \"-jar\",\n        \"server.jar\"\n      ],\n      \"program\": \"java\"\n    }\n}\n```\n\nPre and post support the processors defined in the above section.\n\nEnvironment variables are a simple key-value mapping. An example of this section is below:\n\n```json\n{ \n  \"environmentVars\": {\n    \"NAME\": \"VALUE\"\n  }\n}\n```\n[block:api-header]\n{\n  \"title\": \"Environment\"\n}\n[/block]\nThe environment section supports several types, which can be either ```standard```, ```tty```, or ```docker```.\n\nThe standard environment runs the server directly on the system, as if you were running it from the command line.\n\n```\n    \"environment\": {\n      \"type\": \"standard\"\n    },\n```\n\nThe tty environment is very similar to the standard environment, except it starts a pseudoterminal for the server's output to piped into. This is useful for programs that use ncurses, or otherwise do not function in the standard environment. Use it only when necessary.\n\n```\n    \"environment\": {\n      \"type\": \"tty\"\n    },\n```\n\nThe docker environment runs the server in it's own container. The docker environment lets you also specify the image name to use to generate the container. If none is specified, then ```pufferpanel/generic``` is used. \n\n```\n    \"environment\": {\n      \"type\": \"docker\",\n      \"image\": \"pufferpanel/minecraft\"\n    },\n```\n[block:api-header]\n{\n  \"title\": \"Data\"\n}\n[/block]\nThe data section contains the variables used throughout the template, which can be populated by the user on the server creation page, or exist only in the template.\n\nEach variable is made up of several options and can be used throughout the template with the syntax ```${variable}``` to replace data where needed.\n\n**memory** - This is the name of the variable, change this for each variable\n**value** - The default value for the variable\n**required** - Whether or not the variable must be populated\n**desc** - The description of the variable shown on the server creation page\n**display** - The name of the variable shown on the server creation page\n**internal** - Whether or not to show the variable on the server creation page\n```\n    \"data\": {\n      \"memory\": {\n        \"value\": \"1024\",\n        \"required\": true,\n        \"desc\": \"How much memory in MB to allocate to the Java Heap\",\n        \"display\": \"Memory (MB)\",\n        \"internal\": false\n      },\n```\n[block:api-header]\n{\n  \"title\": \"Finished Template\"\n}\n[/block]\nFor reference, here is the entire completed template\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"pufferd\\\": {\\n    \\\"type\\\": \\\"java\\\",\\n    \\\"display\\\": \\\"SpongeForge - Minecraft\\\",\\n    \\\"install\\\": {\\n      \\\"commands\\\": [\\n        {\\n          \\\"type\\\": \\\"download\\\",\\n          \\\"files\\\": [\\n            \\\"http://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeversion}/forge-${forgeversion}-installer.jar\\\",\\n            \\\"http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/${spongeversion}/spongeforge-${spongeversion}.jar\\\"\\n          ]\\n        },\\n        {\\n          \\\"source\\\": \\\"forge-*.jar\\\",\\n          \\\"target\\\": \\\"installer.jar\\\",\\n          \\\"type\\\": \\\"move\\\"\\n        },\\n        {\\n          \\\"target\\\": \\\"mods\\\",\\n          \\\"type\\\": \\\"mkdir\\\"\\n        },\\n        {\\n          \\\"source\\\": \\\"spongeforge-*.jar\\\",\\n          \\\"target\\\": \\\"mods\\\",\\n          \\\"type\\\": \\\"move\\\"\\n        },\\n        {\\n          \\\"commands\\\": [\\n            \\\"java -jar installer.jar --installServer\\\"\\n          ],\\n          \\\"type\\\": \\\"command\\\"\\n        },\\n        {\\n          \\\"type\\\": \\\"writefile\\\",\\n          \\\"text\\\": \\\"eula=${eula}\\\",\\n          \\\"target\\\": \\\"eula.txt\\\"\\n        },\\n        {\\n          \\\"type\\\": \\\"writefile\\\",\\n          \\\"text\\\": \\\"server-ip=${ip}\\\\nserver-port=${port}\\\\n\\\",\\n          \\\"target\\\": \\\"server.properties\\\"\\n        },\\n        {\\n          \\\"source\\\": \\\"forge-*-universal.jar\\\",\\n          \\\"target\\\": \\\"server.jar\\\",\\n          \\\"type\\\": \\\"move\\\"\\n        }\\n      ]\\n    },\\n    \\\"run\\\": {\\n      \\\"stop\\\": \\\"stop\\\",\\n      \\\"pre\\\": [],\\n      \\\"post\\\": [],\\n      \\\"arguments\\\": [\\n        \\\"-Xmx${memory}M\\\",\\n        \\\"-jar\\\",\\n        \\\"server.jar\\\"\\n      ],\\n      \\\"program\\\": \\\"java\\\"\\n    },\\n    \\\"environment\\\": {\\n      \\\"type\\\": \\\"standard\\\"\\n    },\\n    \\\"data\\\": {\\n      \\\"memory\\\": {\\n        \\\"value\\\": \\\"1024\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"How much memory in MB to allocate to the Java Heap\\\",\\n        \\\"display\\\": \\\"Memory (MB)\\\",\\n        \\\"internal\\\": false\\n      },\\n      \\\"ip\\\": {\\n        \\\"value\\\": \\\"0.0.0.0\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"What IP to bind the server to\\\",\\n        \\\"display\\\": \\\"IP\\\",\\n        \\\"internal\\\": false\\n      },\\n      \\\"port\\\": {\\n        \\\"value\\\": \\\"25565\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"What port to bind the server to\\\",\\n        \\\"display\\\": \\\"Port\\\",\\n        \\\"internal\\\": false\\n      },\\n      \\\"eula\\\": {\\n        \\\"value\\\": \\\"false\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"Do you (or the server owner) agree to the <a href='https://account.mojang.com/documents/minecraft_eula'>Minecraft EULA?</a>\\\",\\n        \\\"display\\\": \\\"EULA Agreement (true/false)\\\",\\n        \\\"internal\\\": false\\n      },\\n      \\\"spongeversion\\\": {\\n        \\\"value\\\": \\\"1.11.2-2282-6.1.0-BETA-2343\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"Version of Sponge to install (may be located <a href='https://www.spongepowered.org/downloads/spongeforge/stable/'>here</a>\\\",\\n        \\\"display\\\": \\\"Sponge Version\\\",\\n        \\\"internal\\\": false\\n      },\\n      \\\"forgeversion\\\": {\\n        \\\"value\\\": \\\"1.11.2-13.20.0.2298\\\",\\n        \\\"required\\\": true,\\n        \\\"desc\\\": \\\"Version of Forge to install (use version specified by Sponge)\\\",\\n        \\\"display\\\": \\\"Forge Version\\\",\\n        \\\"internal\\\": false\\n      }\\n    }\\n  }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"spongeforge.json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"creating-pufferd-templates","type":"basic","title":"Creating pufferd templates"}

Creating pufferd templates


[block:api-header] { "title": "How to add a new template" } [/block] One of the main features of pufferd is its template system, which makes it very easy to add new games by simply editing a JSON file. These templates are located by default in ```/var/lib/pufferd/templates``` To create a new template, make a new file in ```/var/lib/pufferd/templates``` with a name not used by a default template, and make sure the file ends in .json [block:api-header] { "title": "Template Structure" } [/block] Templates are made up of a beginning description and 4 main sections: install, run, environment, and data Variables are created in the data section and can be used throughout the template with the syntax ```${variable}``` to replace data where needed. **type:** To start, include the beginning section which includes the "type" of template it is. This type field is not utilized yet, but will be in the future for grouping of templates. For this example we are going to make a template for SpongeForge, so the type is set to "java" like the other Minecraft templates. **display:** This sets the name of the template displayed in PufferPanel. ``` { "pufferd": { "type": "java", "display": "SpongeForge - Minecraft", ``` [block:api-header] { "title": "Processors" } [/block] A "processor" is a command or operation that can occur on installing, before starting, and after stopping a server. Processors are made up of different times, each one having a specific job. These types are: * download * move * command * writefile * mkdir Each processor has access to each data variable defined, and can use their values. They also have the environment variables which can be defined in the run section below. **download** - Downloads a file or multiple files ``` "install": { "commands": [ { "type": "download", "files": [ "http://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeversion}/forge-${forgeversion}-installer.jar", "http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/${spongeversion}/spongeforge-${spongeversion}.jar" ] }, ``` **move - renaming a file** - move can be used to either move a file into a different location, or rename a file. In this case we are renaming a file that begins with "forge-" to "installer.jar" so that the commands below will work even if the version of Forge changes. ``` { "source": "forge-*.jar", "target": "installer.jar", "type": "move" }, ``` **mkdir** - Creates a new directory ``` { "target": "mods", "type": "mkdir" }, ``` **move - moving a file** - This is moving a file that begins with "spongeforge-" into the newly created mods directory ``` { "source": "spongeforge-*.jar", "target": "mods", "type": "move" }, ``` **command** - Executes a command directly on the system You should use this type only when necessary, and if possible, make the commands generic to the host operating system. ``` { "commands": [ "java -jar installer.jar --installServer" ], "type": "command" }, ``` **writefile** - Writes text into a file, ${ip} and ${port} are variables from the data section ``` { "type": "writefile", "text": "server-ip=${ip}\nserver-port=${port}\n", "target": "server.properties" }, ``` **move** - Finally, we rename a file that begins with "forge-" and ends in "-universal" to the "server.jar" like other pufferd Minecraft templates do. ``` { "source": "forge-*-universal.jar", "target": "server.jar", "type": "move" } ] }, ``` [block:api-header] { "title": "Run" } [/block] The run section defines what happens when the start and stop buttons are pressed. **stop** - Command to send to the console of the running server to stop it **pre** - Processors to run before the server starts **post** - Processors to run after the server starts **arguments** - These are the command line arguments placed after the initial ```program``` and accepts variables from the data section **program** - The actual program to execute to run the server **environmentVars** - Any environment variables to set for this server ```json { "run": { "stop": "stop", "pre": [], "post": [], "arguments": [ "-Xmx${memory}M", "-jar", "server.jar" ], "program": "java" } } ``` Pre and post support the processors defined in the above section. Environment variables are a simple key-value mapping. An example of this section is below: ```json { "environmentVars": { "NAME": "VALUE" } } ``` [block:api-header] { "title": "Environment" } [/block] The environment section supports several types, which can be either ```standard```, ```tty```, or ```docker```. The standard environment runs the server directly on the system, as if you were running it from the command line. ``` "environment": { "type": "standard" }, ``` The tty environment is very similar to the standard environment, except it starts a pseudoterminal for the server's output to piped into. This is useful for programs that use ncurses, or otherwise do not function in the standard environment. Use it only when necessary. ``` "environment": { "type": "tty" }, ``` The docker environment runs the server in it's own container. The docker environment lets you also specify the image name to use to generate the container. If none is specified, then ```pufferpanel/generic``` is used. ``` "environment": { "type": "docker", "image": "pufferpanel/minecraft" }, ``` [block:api-header] { "title": "Data" } [/block] The data section contains the variables used throughout the template, which can be populated by the user on the server creation page, or exist only in the template. Each variable is made up of several options and can be used throughout the template with the syntax ```${variable}``` to replace data where needed. **memory** - This is the name of the variable, change this for each variable **value** - The default value for the variable **required** - Whether or not the variable must be populated **desc** - The description of the variable shown on the server creation page **display** - The name of the variable shown on the server creation page **internal** - Whether or not to show the variable on the server creation page ``` "data": { "memory": { "value": "1024", "required": true, "desc": "How much memory in MB to allocate to the Java Heap", "display": "Memory (MB)", "internal": false }, ``` [block:api-header] { "title": "Finished Template" } [/block] For reference, here is the entire completed template [block:code] { "codes": [ { "code": "{\n \"pufferd\": {\n \"type\": \"java\",\n \"display\": \"SpongeForge - Minecraft\",\n \"install\": {\n \"commands\": [\n {\n \"type\": \"download\",\n \"files\": [\n \"http://files.minecraftforge.net/maven/net/minecraftforge/forge/${forgeversion}/forge-${forgeversion}-installer.jar\",\n \"http://files.minecraftforge.net/maven/org/spongepowered/spongeforge/${spongeversion}/spongeforge-${spongeversion}.jar\"\n ]\n },\n {\n \"source\": \"forge-*.jar\",\n \"target\": \"installer.jar\",\n \"type\": \"move\"\n },\n {\n \"target\": \"mods\",\n \"type\": \"mkdir\"\n },\n {\n \"source\": \"spongeforge-*.jar\",\n \"target\": \"mods\",\n \"type\": \"move\"\n },\n {\n \"commands\": [\n \"java -jar installer.jar --installServer\"\n ],\n \"type\": \"command\"\n },\n {\n \"type\": \"writefile\",\n \"text\": \"eula=${eula}\",\n \"target\": \"eula.txt\"\n },\n {\n \"type\": \"writefile\",\n \"text\": \"server-ip=${ip}\\nserver-port=${port}\\n\",\n \"target\": \"server.properties\"\n },\n {\n \"source\": \"forge-*-universal.jar\",\n \"target\": \"server.jar\",\n \"type\": \"move\"\n }\n ]\n },\n \"run\": {\n \"stop\": \"stop\",\n \"pre\": [],\n \"post\": [],\n \"arguments\": [\n \"-Xmx${memory}M\",\n \"-jar\",\n \"server.jar\"\n ],\n \"program\": \"java\"\n },\n \"environment\": {\n \"type\": \"standard\"\n },\n \"data\": {\n \"memory\": {\n \"value\": \"1024\",\n \"required\": true,\n \"desc\": \"How much memory in MB to allocate to the Java Heap\",\n \"display\": \"Memory (MB)\",\n \"internal\": false\n },\n \"ip\": {\n \"value\": \"0.0.0.0\",\n \"required\": true,\n \"desc\": \"What IP to bind the server to\",\n \"display\": \"IP\",\n \"internal\": false\n },\n \"port\": {\n \"value\": \"25565\",\n \"required\": true,\n \"desc\": \"What port to bind the server to\",\n \"display\": \"Port\",\n \"internal\": false\n },\n \"eula\": {\n \"value\": \"false\",\n \"required\": true,\n \"desc\": \"Do you (or the server owner) agree to the <a href='https://account.mojang.com/documents/minecraft_eula'>Minecraft EULA?</a>\",\n \"display\": \"EULA Agreement (true/false)\",\n \"internal\": false\n },\n \"spongeversion\": {\n \"value\": \"1.11.2-2282-6.1.0-BETA-2343\",\n \"required\": true,\n \"desc\": \"Version of Sponge to install (may be located <a href='https://www.spongepowered.org/downloads/spongeforge/stable/'>here</a>\",\n \"display\": \"Sponge Version\",\n \"internal\": false\n },\n \"forgeversion\": {\n \"value\": \"1.11.2-13.20.0.2298\",\n \"required\": true,\n \"desc\": \"Version of Forge to install (use version specified by Sponge)\",\n \"display\": \"Forge Version\",\n \"internal\": false\n }\n }\n }\n}", "language": "json", "name": "spongeforge.json" } ] } [/block]